Skip to content

Commit

Permalink
int64, correct message
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj committed Mar 29, 2024
1 parent 9ef3205 commit b4ad06c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
24 changes: 14 additions & 10 deletions plugins/inputs/smartctl/smartctl_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@ func (s *Smartctl) scanDevice(acc telegraf.Accumulator, deviceName string, devic

var device smartctlDeviceJSON
out, err := internal.CombinedOutputTimeout(cmd, time.Duration(s.Timeout))
if err != nil {
// Error running the command and unable to parse the JSON, then bail
if jsonErr := json.Unmarshal(out, &device); jsonErr != nil {
return fmt.Errorf("error running smartctl with %s: %w", args, err)
}

// Error running the command and unable to parse the JSON, then bail
if jsonErr := json.Unmarshal(out, &device); jsonErr != nil {
return fmt.Errorf("error running smartctl with %s: %w", args, err)
// If we were able to parse the result, then only exit if we get an error
// as sometimes we can get warnings, that still produce data.
if len(device.Smartctl.Messages) > 0 &&
device.Smartctl.Messages[0].Severity == "error" &&
device.Smartctl.Messages[0].String != "" {
return fmt.Errorf("error running smartctl with %s got smartctl error message: %s", args, device.Smartctl.Messages[0].String)
}
}

// If we were able to parse the result, then only exit if we get an error
// as sometimes we can get warnings, that still produce data.
if err != nil &&
len(device.Smartctl.Messages) > 0 &&
device.Smartctl.Messages[0].Severity == "error" &&
device.Smartctl.Messages[0].String != "" {
return fmt.Errorf("error running smartctl with %s got smartctl error message: %s", args, device.Smartctl.Messages[0].String)
if err := json.Unmarshal(out, &device); err != nil {
return fmt.Errorf("error unable to unmarshall response %s: %w", args, err)
}

t := time.Now()
Expand Down
46 changes: 23 additions & 23 deletions plugins/inputs/smartctl/smartctl_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,38 +37,38 @@ type smartctlDeviceJSON struct {
Passed bool `json:"passed"`
} `json:"smart_status"`
NvmeSmartHealthInformationLog struct {
CriticalWarning int `json:"critical_warning"`
Temperature int `json:"temperature"`
AvailableSpare int `json:"available_spare"`
AvailableSpareThreshold int `json:"available_spare_threshold"`
PercentageUsed int `json:"percentage_used"`
DataUnitsRead int `json:"data_units_read"`
DataUnitsWritten int `json:"data_units_written"`
HostReads int `json:"host_reads"`
HostWrites int `json:"host_writes"`
ControllerBusyTime int `json:"controller_busy_time"`
PowerCycles int `json:"power_cycles"`
PowerOnHours int `json:"power_on_hours"`
UnsafeShutdowns int `json:"unsafe_shutdowns"`
MediaErrors int `json:"media_errors"`
NumErrLogEntries int `json:"num_err_log_entries"`
WarningTempTime int `json:"warning_temp_time"`
CriticalCompTime int `json:"critical_comp_time"`
CriticalWarning int64 `json:"critical_warning"`
Temperature int64 `json:"temperature"`
AvailableSpare int64 `json:"available_spare"`
AvailableSpareThreshold int64 `json:"available_spare_threshold"`
PercentageUsed int64 `json:"percentage_used"`
DataUnitsRead int64 `json:"data_units_read"`
DataUnitsWritten int64 `json:"data_units_written"`
HostReads int64 `json:"host_reads"`
HostWrites int64 `json:"host_writes"`
ControllerBusyTime int64 `json:"controller_busy_time"`
PowerCycles int64 `json:"power_cycles"`
PowerOnHours int64 `json:"power_on_hours"`
UnsafeShutdowns int64 `json:"unsafe_shutdowns"`
MediaErrors int64 `json:"media_errors"`
NumErrLogEntries int64 `json:"num_err_log_entries"`
WarningTempTime int64 `json:"warning_temp_time"`
CriticalCompTime int64 `json:"critical_comp_time"`
} `json:"nvme_smart_health_information_log"`
Temperature struct {
Current int `json:"current"`
} `json:"temperature"`
AtaSmartAttributes struct {
Revision int `json:"revision"`
Table []struct {
ID int `json:"id"`
ID int64 `json:"id"`
Name string `json:"name"`
Value int `json:"value"`
Worst int `json:"worst"`
Thresh int `json:"thresh"`
Value int64 `json:"value"`
Worst int64 `json:"worst"`
Thresh int64 `json:"thresh"`
WhenFailed string `json:"when_failed"`
Flags struct {
Value int `json:"value"`
Value int64 `json:"value"`
String string `json:"string"`
Prefailure bool `json:"prefailure"`
UpdatedOnline bool `json:"updated_online"`
Expand All @@ -78,7 +78,7 @@ type smartctlDeviceJSON struct {
AutoKeep bool `json:"auto_keep"`
} `json:"flags"`
Raw struct {
Value int `json:"value"`
Value int64 `json:"value"`
String string `json:"string"`
} `json:"raw"`
} `json:"table"`
Expand Down

0 comments on commit b4ad06c

Please sign in to comment.