Change logic to allow recording of device fields when attributes is false (#6638)
This commit is contained in:
parent
fc57012629
commit
1b4aad2ccd
|
@ -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,23 +352,25 @@ 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
|
||||||
if attr.ID != "" {
|
if attr.ID != "" {
|
||||||
tags["id"] = attr.ID
|
tags["id"] = attr.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
parse := parseCommaSeperatedInt
|
parse := parseCommaSeperatedInt
|
||||||
if attr.Parse != nil {
|
if attr.Parse != nil {
|
||||||
parse = attr.Parse
|
parse = attr.Parse
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := parse(fields, deviceFields, matches[2]); err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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)
|
acc.AddFields("smart_attribute", fields, tags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue