smartctl will return a non-zero exit code under a number of conditions, defined in their source here.
If the collector gets a non-zero exit code for a smartctl --xall, it will still send the data to the backend:
|
result, err := mc.shell.Command(mc.logger, mc.config.GetString("commands.metrics_smartctl_bin"), args, "", os.Environ()) |
|
resultBytes := []byte(result) |
|
if err != nil { |
|
if exitError, ok := err.(*exec.ExitError); ok { |
|
// smartctl command exited with an error, we should still push the data to the API server |
|
mc.logger.Errorf("smartctl returned an error code (%d) while processing %s\n", exitError.ExitCode(), deviceName) |
|
mc.LogSmartctlExitCode(exitError.ExitCode()) |
|
mc.Publish(deviceWWN, resultBytes) |
which will happily unmarshall it into our model and push it (with a bunch of uninitialized struct fields) into the database:
|
// insert smart info |
|
smartData, err := deviceRepo.SaveSmartAttributes(c, c.Param("wwn"), collectorSmartData) |
|
if err != nil { |
|
logger.Errorln("An error occurred while saving smartctl metrics", err) |
|
c.JSON(http.StatusInternalServerError, gin.H{"success": false}) |
|
return |
|
} |
We should update the exit_status field in our model to match the bitmask from the smartctl source:
|
package collector |
|
|
|
type SmartInfo struct { |
|
JSONFormatVersion []int `json:"json_format_version"` |
|
Smartctl struct { |
|
Version []int `json:"version"` |
|
SvnRevision string `json:"svn_revision"` |
|
PlatformInfo string `json:"platform_info"` |
|
BuildInfo string `json:"build_info"` |
|
Argv []string `json:"argv"` |
|
ExitStatus int `json:"exit_status"` |
and in the backend handler shown above, skip pushing data if any of bits 2-0 are set.
Note that some error codes are shared! Smartctl exits 2 for a variety of reasons including a drive being in standby.
smartctl will return a non-zero exit code under a number of conditions, defined in their source here.
If the collector gets a non-zero exit code for a
smartctl --xall, it will still send the data to the backend:scrutiny/collector/pkg/collector/metrics.go
Lines 136 to 143 in 9d1ce79
which will happily unmarshall it into our model and push it (with a bunch of uninitialized struct fields) into the database:
scrutiny/webapp/backend/pkg/web/handler/upload_device_metrics.go
Lines 45 to 51 in 9d1ce79
We should update the
exit_statusfield in our model to match the bitmask from the smartctl source:scrutiny/webapp/backend/pkg/models/collector/smart.go
Lines 1 to 11 in 9d1ce79
and in the backend handler shown above, skip pushing data if any of bits 2-0 are set.
Note that some error codes are shared! Smartctl exits 2 for a variety of reasons including a drive being in standby.