Skip to content

Commit

Permalink
Accomodate a smartmontools pre-7.3 bug (#238)
Browse files Browse the repository at this point in the history
* Accomodate a smartmontools pre-7.3 bug

https://www.smartmontools.org/changeset/5283
---------

Signed-off-by: Nathan Carlson <[email protected]>
  • Loading branch information
nathanlcarlson authored Nov 8, 2024
1 parent 87e9928 commit 3fa5ea5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions collect-smartctl-json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ for device in "${devices[@]}"
echo -n "Collecting data for '${device}'..."
# shellcheck disable=SC2086
data="$($SUDO smartctl ${smartctl_args} ${device})"
# Accommodate a smartmontools pre-7.3 bug
data=${data#" Pending defect count:"}
type="$(echo "${data}" | "${json_tool}" "${json_args}" '.device.type')"
family="$(echo "${data}" | "${json_tool}" "${json_args}" \
'select(.model_family != null) | .model_family | sub(" |/" ; "_" ; "g")
Expand Down
4 changes: 3 additions & 1 deletion readjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ func readSMARTctl(logger *slog.Logger, device Device) (gjson.Result, bool) {
if err != nil {
logger.Warn("S.M.A.R.T. output reading", "err", err, "device", device.Info_Name)
}
json := parseJSON(string(out))
// Accommodate a smartmontools pre-7.3 bug
cleaned_out := strings.TrimPrefix(string(out), " Pending defect count:")
json := parseJSON(cleaned_out)
rcOk := resultCodeIsOk(logger, device, json.Get("smartctl.exit_status").Int())
jsonOk := jsonIsOk(logger, json)
logger.Debug("Collected S.M.A.R.T. json data", "device", device.Info_Name, "duration", time.Since(start))
Expand Down

0 comments on commit 3fa5ea5

Please sign in to comment.