From 6e2143ca62c15f986e21eff4d5f8380bf1eac331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Fri, 4 Nov 2022 19:42:36 +0100 Subject: [PATCH] Remove useless error message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All errors are already logged from the called functions: readSMARTctl, resultCodeIsOk, jsonIsOk. Logging twice due to the same error is useless and the "smartctl returned bad data for device" message is confusing since that condition may happen when a device is in a low-power mode. Signed-off-by: Jakub Klinkovský --- main.go | 5 ++--- readjson.go | 10 +++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 90d5c91..d1fde84 100644 --- a/main.go +++ b/main.go @@ -49,12 +49,11 @@ func (i SMARTctlManagerCollector) Describe(ch chan<- *prometheus.Desc) { func (i SMARTctlManagerCollector) Collect(ch chan<- prometheus.Metric) { info := NewSMARTctlInfo(ch) for _, device := range i.Devices { - if json, err := readData(i.logger, device); err == nil { + json := readData(i.logger, device) + if json.Exists() { info.SetJSON(json) smart := NewSMARTctl(i.logger, json, ch) smart.Collect() - } else { - level.Error(i.logger).Log("msg", "Error collecting SMART data", "err", err.Error()) } } info.Collect() diff --git a/readjson.go b/readjson.go index 6a96bfe..6c3bf26 100644 --- a/readjson.go +++ b/readjson.go @@ -89,9 +89,9 @@ func readSMARTctlDevices(logger log.Logger) gjson.Result { } // Select json source and parse -func readData(logger log.Logger, device string) (gjson.Result, error) { +func readData(logger log.Logger, device string) gjson.Result { if *smartctlFakeData { - return readFakeSMARTctl(logger, device), nil + return readFakeSMARTctl(logger, device) } cacheValue, cacheOk := jsonCache.Load(device) @@ -103,11 +103,11 @@ func readData(logger log.Logger, device string) (gjson.Result, error) { if !found { level.Warn(logger).Log("msg", "device not found", "device", device) } - return j.(JSONCache).JSON, nil + return j.(JSONCache).JSON } - return gjson.Parse("{}"), fmt.Errorf("smartctl returned bad data for device %s", device) + return gjson.Result{} } - return cacheValue.(JSONCache).JSON, nil + return cacheValue.(JSONCache).JSON } // Parse smartctl return code