Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Normalize typed SMART device labels for temperature merge

rcourtman97c6cad01cd8
diff --git a/internal/monitoring/merge_temps_test.go b/internal/monitoring/merge_temps_test.go
index 2b5d9a6895..4b6f5f5bae 100644
--- a/internal/monitoring/merge_temps_test.go
+++ b/internal/monitoring/merge_temps_test.go
@@ -331,3 +331,22 @@ func TestMergeNVMeTempsIntoDisks_OriginalSliceUnchanged(t *testing.T) {
t.Errorf("original disk temperature was modified: got %d, want 0", original[0].Temperature)
}
}
+
+func TestNormalizeSMARTDeviceIdentifier(t *testing.T) {
+ cases := []struct {
+ in string
+ want string
+ }{
+ {"sdd [scsi]", "sdd"},
+ {"/dev/sdd [scsi]", "sdd"},
+ {"/dev/nvme0n1", "nvme0n1"},
+ {"sda", "sda"},
+ {" sdb [ata] ", "sdb"},
+ {"", ""},
+ }
+ for _, tc := range cases {
+ if got := normalizeSMARTDeviceIdentifier(tc.in); got != tc.want {
+ t.Errorf("normalizeSMARTDeviceIdentifier(%q) = %q, want %q", tc.in, got, tc.want)
+ }
+ }
+}
diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go
index 00d1929c8a..2cf6c0f105 100644
--- a/internal/monitoring/monitor.go
+++ b/internal/monitoring/monitor.go
@@ -274,6 +274,23 @@ func (m *Monitor) getPMGClient(name string) (*pmg.Client, bool) {
return client, ok
}
+// normalizeSMARTDeviceIdentifier strips a trailing type annotation (e.g.
+// "sdd [scsi]" -> "sdd") and the /dev/ prefix so SMART temperatures match disks
+// by device path even when smartctl reports a typed label.
+func normalizeSMARTDeviceIdentifier(device string) string {
+ normalized := strings.TrimSpace(device)
+ if normalized == "" {
+ return ""
+ }
+
+ if base, suffix, found := strings.Cut(normalized, " ["); found && strings.HasSuffix(suffix, "]") {
+ normalized = base
+ }
+
+ normalized = strings.TrimSpace(normalized)
+ return strings.TrimPrefix(normalized, "/dev/")
+}
+
func mergeNVMeTempsIntoDisks(disks []models.PhysicalDisk, nodes []models.Node) []models.PhysicalDisk {
if len(disks) == 0 || len(nodes) == 0 {
return disks
@@ -387,10 +404,10 @@ func mergeNVMeTempsIntoDisks(disks []models.PhysicalDisk, nodes []models.Node) [
// Last resort: match by device path (normalized)
if updated[i].Temperature == 0 {
- normalizedDevPath := strings.TrimPrefix(updated[i].DevPath, "/dev/")
+ normalizedDevPath := normalizeSMARTDeviceIdentifier(updated[i].DevPath)
for _, temp := range smartTemps {
- normalizedTempDev := strings.TrimPrefix(temp.Device, "/dev/")
- if normalizedTempDev == normalizedDevPath {
+ normalizedTempDev := normalizeSMARTDeviceIdentifier(temp.Device)
+ if normalizedTempDev != "" && normalizedTempDev == normalizedDevPath {
if temp.Temperature > 0 && !temp.StandbySkipped {
updated[i].Temperature = temp.Temperature
log.Debug().
@@ -513,10 +530,10 @@ func mergeHostAgentSMARTIntoDisks(disks []models.PhysicalDisk, nodes []models.No
// Last resort: match by device path
if matched == nil {
- normalizedDevPath := strings.TrimPrefix(updated[i].DevPath, "/dev/")
+ normalizedDevPath := normalizeSMARTDeviceIdentifier(updated[i].DevPath)
for j := range smartData {
- normalizedDiskDev := strings.TrimPrefix(smartData[j].Device, "/dev/")
- if normalizedDiskDev == normalizedDevPath {
+ normalizedDiskDev := normalizeSMARTDeviceIdentifier(smartData[j].Device)
+ if normalizedDiskDev != "" && normalizedDiskDev == normalizedDevPath {
matched = &smartData[j]
break
}