From e877540841ac31853e96e75724706887848d4591 Mon Sep 17 00:00:00 2001 From: Frank Wettstein Date: Wed, 3 Dec 2025 22:13:06 +0100 Subject: [PATCH] Fix 298 by reusing the label instead of taking it from the json of smartctl Signed-off-by: Frank Wettstein --- main.go | 2 +- smartctl.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index c5b138a..4257be0 100644 --- a/main.go +++ b/main.go @@ -69,7 +69,7 @@ func (i *SMARTctlManagerCollector) Collect(ch chan<- prometheus.Metric) { json := readData(i.logger, device) if json.Exists() { info.SetJSON(json) - smart := NewSMARTctl(i.logger, json, ch) + smart := NewSMARTctl(i.logger, json, ch, device) smart.Collect() } } diff --git a/smartctl.go b/smartctl.go index b136b8b..8db1793 100644 --- a/smartctl.go +++ b/smartctl.go @@ -55,7 +55,7 @@ func buildDeviceLabel(inputName string, inputType string) string { } // NewSMARTctl is smartctl constructor -func NewSMARTctl(logger *slog.Logger, json gjson.Result, ch chan<- prometheus.Metric) SMARTctl { +func NewSMARTctl(logger *slog.Logger, json gjson.Result, ch chan<- prometheus.Metric, device Device) SMARTctl { var model_name string if obj := json.Get("model_name"); obj.Exists() { model_name = obj.String() @@ -72,7 +72,7 @@ func NewSMARTctl(logger *slog.Logger, json gjson.Result, ch chan<- prometheus.Me json: json, logger: logger, device: SMARTDevice{ - device: buildDeviceLabel(json.Get("device.name").String(), json.Get("device.type").String()), + device: device.Label, serial: strings.TrimSpace(json.Get("serial_number").String()), family: strings.TrimSpace(GetStringIfExists(json, "model_family", "unknown")), model: strings.TrimSpace(model_name),