From bd0ecefb73cbca5c38cebf0269ad8325ef347d04 Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 26 Feb 2025 16:56:23 -0500 Subject: [PATCH 1/5] added support for multiple CCISS devices Signed-off-by: Josh --- smartctl.go | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/smartctl.go b/smartctl.go index eb94130..60ee802 100644 --- a/smartctl.go +++ b/smartctl.go @@ -67,16 +67,38 @@ func NewSMARTctl(logger *slog.Logger, json gjson.Result, ch chan<- prometheus.Me model_name = "unknown" } + // Handle CCISS devices. + // CCISS does not alway get stored in devices.type, it is more frequent in devices.info_name + var device_name string + var device_interface string + if strings.Contains(strings.ToLower(json.Get("device.info_name").String()), "cciss") { + // Correct the "device name" to be what is exected in buildDeviceLabel + // For a CCISS device typically device.name is just /dev/sda + // The info_name is reported as "/dev/sda [cciss_disk_NN] [SCSI]" + tmp := json.Get("device.info_name").String() + tmp = strings.Trim(strings.Split(tmp, "")[1], "[]") + tmp = strings.Replace(tmp, "_disk_", ",", 1) + device_name = buildDeviceLabel(json.Get("device.name").String(), tmp) + + // Correct the device "interface" + // On some machines it reports the interface as CCISS and others it reports it as SAT/SCSI + // Here it will show the device as SAT or SCSI + device_interface = strings.ToLower(strings.Trim(strings.Split(json.Get("device.info_name").String(), " ")[2], "[]")) + } else { + device_name = buildDeviceLabel(json.Get("device.name").String(), json.Get("device.type").String()) + device_interface = strings.TrimSpace(json.Get("device.type").String()) + } + return SMARTctl{ ch: ch, json: json, logger: logger, device: SMARTDevice{ - device: buildDeviceLabel(json.Get("device.name").String(), json.Get("device.type").String()), + device: device_name, serial: strings.TrimSpace(json.Get("serial_number").String()), family: strings.TrimSpace(GetStringIfExists(json, "model_family", "unknown")), model: strings.TrimSpace(model_name), - interface_: strings.TrimSpace(json.Get("device.type").String()), + interface_: device_interface, protocol: strings.TrimSpace(json.Get("device.protocol").String()), }, } From 4dd8f8f7e08dbb62fc7113c23ee192ab08d456d7 Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 26 Feb 2025 17:10:43 -0500 Subject: [PATCH 2/5] corrected spelling Signed-off-by: Josh --- smartctl_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/smartctl_test.go b/smartctl_test.go index 8c9836c..b86480c 100644 --- a/smartctl_test.go +++ b/smartctl_test.go @@ -29,6 +29,7 @@ func TestBuildDeviceLabel(t *testing.T) { // Some cases extracted from smartctl docs. Are these the prettiest? // Probably not. Are they unique enough. Definitely. {"/dev/sg1", "cciss,1", "sg1_cciss_1"}, + {"/dev/sda", "cciss,0", "sda_cciss_0"}, {"/dev/bsg/sssraid0", "sssraid,0,1", "bsg_sssraid0_sssraid_0_1"}, {"/dev/cciss/c0d0", "cciss,0", "cciss_c0d0_cciss_0"}, {"/dev/sdb", "aacraid,1,0,4", "sdb_aacraid_1_0_4"}, From 85d65bde3925749450841008abbc21cc88a1e86b Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 26 Feb 2025 17:12:20 -0500 Subject: [PATCH 3/5] revert Signed-off-by: Josh --- smartctl_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/smartctl_test.go b/smartctl_test.go index b86480c..8c9836c 100644 --- a/smartctl_test.go +++ b/smartctl_test.go @@ -29,7 +29,6 @@ func TestBuildDeviceLabel(t *testing.T) { // Some cases extracted from smartctl docs. Are these the prettiest? // Probably not. Are they unique enough. Definitely. {"/dev/sg1", "cciss,1", "sg1_cciss_1"}, - {"/dev/sda", "cciss,0", "sda_cciss_0"}, {"/dev/bsg/sssraid0", "sssraid,0,1", "bsg_sssraid0_sssraid_0_1"}, {"/dev/cciss/c0d0", "cciss,0", "cciss_c0d0_cciss_0"}, {"/dev/sdb", "aacraid,1,0,4", "sdb_aacraid_1_0_4"}, From dee392b2ab4261f1b94e3283fbe823b9faf0ec8b Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 26 Feb 2025 17:13:19 -0500 Subject: [PATCH 4/5] spelling Signed-off-by: Josh --- smartctl.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smartctl.go b/smartctl.go index 60ee802..9fc5a43 100644 --- a/smartctl.go +++ b/smartctl.go @@ -72,7 +72,7 @@ func NewSMARTctl(logger *slog.Logger, json gjson.Result, ch chan<- prometheus.Me var device_name string var device_interface string if strings.Contains(strings.ToLower(json.Get("device.info_name").String()), "cciss") { - // Correct the "device name" to be what is exected in buildDeviceLabel + // Correct the "device name" to be what is expected in buildDeviceLabel // For a CCISS device typically device.name is just /dev/sda // The info_name is reported as "/dev/sda [cciss_disk_NN] [SCSI]" tmp := json.Get("device.info_name").String() From 19ab0eb850d833b00ae6edd823157261d9b6be12 Mon Sep 17 00:00:00 2001 From: Josh Date: Sat, 8 Mar 2025 15:21:31 -0500 Subject: [PATCH 5/5] corrected spelling Signed-off-by: Josh --- smartctl.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smartctl.go b/smartctl.go index 9fc5a43..abd573d 100644 --- a/smartctl.go +++ b/smartctl.go @@ -68,7 +68,7 @@ func NewSMARTctl(logger *slog.Logger, json gjson.Result, ch chan<- prometheus.Me } // Handle CCISS devices. - // CCISS does not alway get stored in devices.type, it is more frequent in devices.info_name + // CCISS does not always get stored in devices.type, it is more frequent in devices.info_name var device_name string var device_interface string if strings.Contains(strings.ToLower(json.Get("device.info_name").String()), "cciss") {