From 9fe769ecdb6f05960d6d776efe85a9be9cbeff6a Mon Sep 17 00:00:00 2001 From: rcourtman Date: Thu, 4 Jun 2026 09:50:37 +0100 Subject: [PATCH] Parse OPNsense 'Current Drive Temperature' SMART output Back-port the smartctl regex half of v5 fix 0c2de2938 to v6 (the prerelease-aware CompareVersions half is already present). smartctl text fallback now matches 'Current Drive Temperature:' in addition to 'Current Temperature:', so OPNsense/pfSense disk temperatures are read instead of reported as missing. Adds a regression test. --- internal/hostagent/smartctl.go | 2 +- internal/hostagent/smartctl_test.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/internal/hostagent/smartctl.go b/internal/hostagent/smartctl.go index e030674aa..1be2336cf 100644 --- a/internal/hostagent/smartctl.go +++ b/internal/hostagent/smartctl.go @@ -201,7 +201,7 @@ type smartTextFallback struct { var ( smartTextTempAttributeRE = regexp.MustCompile(`^\s*(190|194)\s+\S+.*-\s+(\d{1,3})\b`) - smartTextCurrentTempRE = regexp.MustCompile(`(?i)^current temperature:\s*(\d{1,3})\b`) + smartTextCurrentTempRE = regexp.MustCompile(`(?i)^current(?: drive)? temperature:\s*(\d{1,3})\b`) smartTextTemperatureRE = regexp.MustCompile(`(?i)^temperature:\s*(\d{1,3})\b`) ) diff --git a/internal/hostagent/smartctl_test.go b/internal/hostagent/smartctl_test.go index fd22c1f34..a1b19cd11 100644 --- a/internal/hostagent/smartctl_test.go +++ b/internal/hostagent/smartctl_test.go @@ -505,6 +505,29 @@ Current Temperature: 39 C } } +func TestParseSMARTOutputParsesCurrentDriveTemperature(t *testing.T) { + // OPNsense/pfSense smartctl emits "Current Drive Temperature" rather than + // "Current Temperature"; both must parse. + output := []byte(` +=== START OF INFORMATION SECTION === +Device Model: WDC WD40EFRX +Serial Number: WD-456 +SMART overall-health self-assessment test result: PASSED +Current Drive Temperature: 41 C +`) + + result, err := parseSMARTOutput(output, smartctlTarget{Path: "/dev/ada0"}) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if result == nil { + t.Fatal("expected result") + } + if result.Temperature != 41 { + t.Fatalf("expected 'Current Drive Temperature' to parse as 41, got %#v", result) + } +} + func TestMatchesDeviceExclude(t *testing.T) { tests := []struct { name string