Skip to content

Commit

Permalink
Change logic to allow recording of device fields when attributes is f…
Browse files Browse the repository at this point in the history
…alse (influxdata#6638)
  • Loading branch information
ryan-peck authored and idohalevi committed Sep 23, 2020
1 parent 15bc0a4 commit 9fe6848
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions plugins/inputs/smart/smart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
}

parse := parseCommaSeperatedInt
if attr.Parse != nil {
parse = attr.Parse
}

if err := parse(fields, deviceFields, matches[2]); err != nil {
continue
}
// 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
}
// if the field is classified as an attribute, only add it
// if collectAttributes is true
if collectAttributes {
acc.AddFields("smart_attribute", fields, tags)
}
}
Expand Down

0 comments on commit 9fe6848

Please sign in to comment.