Fix dash to underscore replacement when handling embedded tags in Cisco MDT (#7035)

Currently configuring embedded_tags for cisco_telemetry_mdt input
requires an unusual mix of - and _, i.e. one needs to specify e.g.
Cisco-IOS-XR-wdsysmon-fd-oper:system-monitoring/cpu-utilization/process_cpu/process-id
for it to work correctly. Additionally, tags created might still contain
dashes against convention.

This fix creates correctly formatted tags with underscores instead of
dashes and unifies the configuration parameter to expect either dashes
or underscores, so old configurations are still valid.
This commit is contained in:
Steven Barth 2020-02-19 02:31:39 +01:00 committed by GitHub
parent 8b3bd2585d
commit 0a1373765e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -76,7 +76,7 @@ func (c *CiscoTelemetryMDT) Start(acc telegraf.Accumulator) error {
// Fill extra tags // Fill extra tags
c.extraTags = make(map[string]map[string]struct{}) c.extraTags = make(map[string]map[string]struct{})
for _, tag := range c.EmbeddedTags { for _, tag := range c.EmbeddedTags {
dir := path.Dir(tag) dir := strings.Replace(path.Dir(tag), "-", "_", -1)
if _, hasKey := c.extraTags[dir]; !hasKey { if _, hasKey := c.extraTags[dir]; !hasKey {
c.extraTags[dir] = make(map[string]struct{}) c.extraTags[dir] = make(map[string]struct{})
} }
@ -400,7 +400,7 @@ func (c *CiscoTelemetryMDT) parseContentField(grouper *metric.SeriesGrouper, fie
name = prefix + "/" + name name = prefix + "/" + name
} }
extraTags := c.extraTags[path+"/"+name] extraTags := c.extraTags[strings.Replace(path, "-", "_", -1)+"/"+name]
if value := decodeValue(field); value != nil { if value := decodeValue(field); value != nil {
// Do alias lookup, to shorten measurement names // Do alias lookup, to shorten measurement names
@ -423,7 +423,7 @@ func (c *CiscoTelemetryMDT) parseContentField(grouper *metric.SeriesGrouper, fie
if len(extraTags) > 0 { if len(extraTags) > 0 {
for _, subfield := range field.Fields { for _, subfield := range field.Fields {
if _, isExtraTag := extraTags[subfield.Name]; isExtraTag { if _, isExtraTag := extraTags[subfield.Name]; isExtraTag {
tags[name+"/"+subfield.Name] = decodeTag(subfield) tags[name+"/"+strings.Replace(subfield.Name, "-", "_", -1)] = decodeTag(subfield)
} }
} }
} }