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