Change logic to allow recording of device fields when attributes is false (#6638)

This commit is contained in:
ryan-peck 2020-01-14 17:05:28 -08:00 committed by Daniel Nelson
parent fc57012629
commit 1b4aad2ccd
1 changed files with 18 additions and 15 deletions

View File

@ -319,6 +319,7 @@ func gatherDisk(acc telegraf.Accumulator, timeout internal.Duration, usesudo, co
attr := attribute.FindStringSubmatch(line) attr := attribute.FindStringSubmatch(line)
if len(attr) > 1 { if len(attr) > 1 {
// attribute has been found, add it only if collectAttributes is true
if collectAttributes { if collectAttributes {
tags["id"] = attr[1] tags["id"] = attr[1]
tags["name"] = attr[2] tags["name"] = attr[2]
@ -351,7 +352,7 @@ func gatherDisk(acc telegraf.Accumulator, timeout internal.Duration, usesudo, co
} }
} }
} else { } else {
if collectAttributes { // what was found is not a vendor attribute
if matches := sasNvmeAttr.FindStringSubmatch(line); len(matches) > 2 { if matches := sasNvmeAttr.FindStringSubmatch(line); len(matches) > 2 {
if attr, ok := sasNvmeAttributes[matches[1]]; ok { if attr, ok := sasNvmeAttributes[matches[1]]; ok {
tags["name"] = attr.Name tags["name"] = attr.Name
@ -367,7 +368,9 @@ func gatherDisk(acc telegraf.Accumulator, timeout internal.Duration, usesudo, co
if err := parse(fields, deviceFields, matches[2]); err != nil { if err := parse(fields, deviceFields, matches[2]); err != nil {
continue continue
} }
// if the field is classified as an attribute, only add it
// if collectAttributes is true
if collectAttributes {
acc.AddFields("smart_attribute", fields, tags) acc.AddFields("smart_attribute", fields, tags)
} }
} }