diff --git a/plugins/inputs/smart/smart.go b/plugins/inputs/smart/smart.go index b0c755a2059f8..38d7737b5a12a 100644 --- a/plugins/inputs/smart/smart.go +++ b/plugins/inputs/smart/smart.go @@ -719,6 +719,7 @@ func (m *Smart) gatherDisk(acc telegraf.Accumulator, device string, wg *sync.Wai // smartctl 5.41 & 5.42 have are broken regarding handling of --nocheck/-n args := []string{"--info", "--health", "--attributes", "--tolerance=verypermissive", "-n", m.Nocheck, "--format=brief"} args = append(args, strings.Split(device, " ")...) + fmt.Printf("running '%s %v'\n", m.PathSmartctl, args) out, e := runCmd(m.Timeout, m.UseSudo, m.PathSmartctl, args...) outStr := string(out) @@ -766,6 +767,12 @@ func (m *Smart) gatherDisk(acc telegraf.Accumulator, device string, wg *sync.Wai } health := smartOverallHealth.FindStringSubmatch(line) + if len(health) > 0 { + fmt.Printf("found health match in: '%s'\n", line) + for index, item := range health { + fmt.Printf("%d: '%s'\n", index, item) + } + } if len(health) > 2 { deviceFields["health_ok"] = health[2] == "PASSED" || health[2] == "OK" } @@ -795,8 +802,10 @@ func (m *Smart) gatherDisk(acc telegraf.Accumulator, device string, wg *sync.Wai } } + fmt.Println(line) attr := attribute.FindStringSubmatch(line) if len(attr) > 1 { + fmt.Println("valid attribute line") // attribute has been found, add it only if m.Attributes is true if m.Attributes { tags["id"] = attr[1] @@ -819,14 +828,21 @@ func (m *Smart) gatherDisk(acc telegraf.Accumulator, device string, wg *sync.Wai fields["raw_value"] = val } + fmt.Println(tags) + fmt.Println(fields) + acc.AddFields("smart_attribute", fields, tags) } // If the attribute matches on the one in deviceFieldIds // save the raw value to a field. + fmt.Printf("looking at field id: %s\n", attr[1]) if field, ok := deviceFieldIds[attr[1]]; ok { + fmt.Printf("found %s parsing '%s'", field, attr[8]) if val, err := parseRawValue(attr[8]); err == nil { deviceFields[field] = val + } else { + fmt.Println("error parsing value: %w", err) } } @@ -841,7 +857,9 @@ func (m *Smart) gatherDisk(acc telegraf.Accumulator, device string, wg *sync.Wai } } else { // what was found is not a vendor attribute + fmt.Println("not vendor attribute, checking if sas NVME attribute") if matches := sasNVMeAttr.FindStringSubmatch(line); len(matches) > 2 { + fmt.Println("found sas nvme attribuate") if attr, ok := sasNVMeAttributes[matches[1]]; ok { tags["name"] = attr.Name if attr.ID != "" { @@ -857,6 +875,9 @@ func (m *Smart) gatherDisk(acc telegraf.Accumulator, device string, wg *sync.Wai acc.AddError(fmt.Errorf("error parsing %s: '%s': %s", attr.Name, matches[2], err.Error())) continue } + + fmt.Println(tags) + fmt.Println(fields) // if the field is classified as an attribute, only add it // if m.Attributes is true if m.Attributes {