Skip to content

Commit

Permalink
fix: see if an error is occuring during parsing
Browse files Browse the repository at this point in the history
plus lots of debug messages

fixes: influxdata#9993
  • Loading branch information
powersj committed Jul 29, 2022
1 parent 5b9aee1 commit f370690
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions plugins/inputs/smart/smart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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"
}
Expand Down Expand Up @@ -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]
Expand All @@ -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)
}
}

Expand All @@ -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 != "" {
Expand All @@ -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 {
Expand Down

0 comments on commit f370690

Please sign in to comment.