From 2c2b4aa970b635c04eb8d4b53a9f6b26d33a819e Mon Sep 17 00:00:00 2001 From: Deezzir Date: Thu, 19 Dec 2024 21:13:06 -0500 Subject: [PATCH] Do not export smart_status if object is not present Signed-off-by: Deezzir --- smartctl.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/smartctl.go b/smartctl.go index eb94130..9207bd1 100644 --- a/smartctl.go +++ b/smartctl.go @@ -468,12 +468,16 @@ func (smart *SMARTctl) mineSCSIBytesWritten() { } func (smart *SMARTctl) mineSmartStatus() { - smart.ch <- prometheus.MustNewConstMetric( - metricDeviceSmartStatus, - prometheus.GaugeValue, - smart.json.Get("smart_status.passed").Float(), - smart.device.device, - ) + passed_raw := smart.json.Get("smart_status.passed") + + if passed_raw.Exists() { + smart.ch <- prometheus.MustNewConstMetric( + metricDeviceSmartStatus, + prometheus.GaugeValue, + passed_raw.Float(), + smart.device.device, + ) + } } func (smart *SMARTctl) mineDeviceStatistics() {