Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug: see if an error is occuring during parsing #11566

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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