Skip to content

Commit

Permalink
Restrict permissible regex for instance name in perfmon (#14666)
Browse files Browse the repository at this point in the history
* modify regex

* Added pr id

* refactor unittest
  • Loading branch information
narph authored Nov 25, 2019
1 parent 4db5135 commit 6280f83
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix checking tagsFilter using length in cloudwatch metricset. {pull}14525[14525]
- Log bulk failures from bulk API requests to monitoring cluster. {issue}14303[14303] {pull}14356[14356]
- Fixed bug with `elasticsearch/cluster_stats` metricset not recording license expiration date correctly. {issue}14541[14541] {pull}14591[14591]
- Fix regular expression to detect instance name in perfmon metricset. {issue}14273[14273] {pull}14666[14666]
- Vshpere module splits `virtualmachine.host` into `virtualmachine.host.id` and `virtualmachine.host.hostname`. {issue}7187[7187] {pull}7213[7213]
- Fixed bug with `elasticsearch/cluster_stats` metricset not recording license ID in the correct field. {pull}14592[14592]

Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/windows/perfmon/pdh_query_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

var (
instanceNameRegexp = regexp.MustCompile(`.*\((.*)\).*`)
instanceNameRegexp = regexp.MustCompile(`.*?\((.*?)\).*`)
objectNameRegexp = regexp.MustCompile(`(?:^\\\\[^\\]+\\|^\\)([^\\]+)`)
)

Expand Down
25 changes: 25 additions & 0 deletions metricbeat/module/windows/perfmon/pdh_query_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,28 @@ func TestSuccessfulQuery(t *testing.T) {
assert.Nil(t, err)
assert.NotNil(t, list)
}

// TestInstanceNameRegexp tests regular expression for instance.
func TestInstanceNameRegexp(t *testing.T) {
queryPaths := []string{`\SQLServer:Databases(*)\Log File(s) Used Size (KB)`, `\Search Indexer(*)\L0 Indexes (Wordlists)`,
`\Search Indexer(*)\L0 Merges (flushes) Now.`, `\NUMA Node Memory(*)\Free & Zero Page List MBytes`}
for _, path := range queryPaths {
matches := instanceNameRegexp.FindStringSubmatch(path)
if assert.Len(t, matches, 2, "regular expression did not return any matches") {
assert.Equal(t, matches[1], "*")
}
}
}

// TestObjectNameRegexp tests regular expression for object.
func TestObjectNameRegexp(t *testing.T) {
queryPaths := []string{`\Web Service Cache\Output Cache Current Flushed Items`,
`\Web Service Cache\Output Cache Total Flushed Items`, `\Web Service Cache\Total Flushed Metadata`,
`\Web Service Cache\Kernel: Current URIs Cached`}
for _, path := range queryPaths {
matches := objectNameRegexp.FindStringSubmatch(path)
if assert.Len(t, matches, 2, "regular expression did not return any matches") {
assert.Equal(t, matches[1], "Web Service Cache")
}
}
}

0 comments on commit 6280f83

Please sign in to comment.