From eef6f880a8c4b286f548bbe1acb17a9d6c2d8930 Mon Sep 17 00:00:00 2001 From: Nathan Carlson Date: Fri, 9 Aug 2024 16:00:43 -0500 Subject: [PATCH] Accomodate a smartmontools pre-7.3 bug https://www.smartmontools.org/changeset/5283 Signed-off-by: Nathan Carlson --- collect-smartctl-json.sh | 2 ++ readjson.go | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/collect-smartctl-json.sh b/collect-smartctl-json.sh index a658c37..0f46f16 100755 --- a/collect-smartctl-json.sh +++ b/collect-smartctl-json.sh @@ -54,6 +54,8 @@ for device in "${devices[@]}" echo -n "Collecting data for '${device}'..." # shellcheck disable=SC2086 data="$($SUDO smartctl ${smartctl_args} ${device})" + # Accomodate 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") diff --git a/readjson.go b/readjson.go index 234bc85..d305e26 100644 --- a/readjson.go +++ b/readjson.go @@ -68,7 +68,9 @@ func readSMARTctl(logger log.Logger, device Device) (gjson.Result, bool) { if err != nil { level.Warn(logger).Log("msg", "S.M.A.R.T. output reading", "err", err, "device", device.Info_Name) } - json := parseJSON(string(out)) + // Accomodate 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) level.Debug(logger).Log("msg", "Collected S.M.A.R.T. json data", "device", device.Info_Name, "duration", time.Since(start))