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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Fix alert threshold and disk temperature regressions
rcourtmanc9ee0b339211
diff --git a/docs/release-control/v6/internal/subsystems/alerts.md b/docs/release-control/v6/internal/subsystems/alerts.mdindex 3c4031ed4e..0a9a21f96e 100644--- a/docs/release-control/v6/internal/subsystems/alerts.md+++ b/docs/release-control/v6/internal/subsystems/alerts.md@@ -255,6 +255,11 @@ alerts must evaluate the normalized pool storage id while accepting legacy`agent:<host>-ceph-pool-<name>` override keys as aliases, so operators do notlose saved thresholds when the same physical Ceph pool moves betweenhost-agent-only fallback and Proxmox API canonical discovery.+Active alert reevaluation after threshold or config changes must use canonical+resource type metadata before the legacy node fallback. Host-agent Ceph pool+alerts may carry no-colon resource ids with `Instance == Node`, but when+metadata or resource type says storage they must keep using storage threshold+resolution and source-alias overrides instead of node defaults.Browser metric severity colors are also alert-backed. Workloads,Infrastructure, and Storage may pass resolved display thresholds into theirdiff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.mdindex 88db61f5f1..3c2d1e2f15 100644--- a/docs/release-control/v6/internal/subsystems/monitoring.md+++ b/docs/release-control/v6/internal/subsystems/monitoring.md@@ -950,19 +950,23 @@ and SMART merges, so skipped or background disk refresh no longer treats thesnapshot as internal truth for that path.That same monitoring-owned disk merge path must also treat host-agent SMARTattributes as canonical fill data for the Proxmox disk view. When a linked-host agent reports SMART health or NVMe `percentage_used` for a physical disk-that Proxmox itself exposes without trustworthy health or wearout, the merge-path in `internal/monitoring/monitor.go` must promote that data into the-canonical physical-disk model and the Proxmox polling runtime in-`internal/monitoring/monitor_pve.go` must evaluate disk alerts only after that-merged disk view exists, so controller-backed disks do not lose health and-endurance coverage between collection and alerting.+host agent reports SMART health, SMART identity, ZFS pool membership, or NVMe+`percentage_used` for a physical disk that Proxmox itself exposes without+trustworthy health, wearout, model, serial, WWN, type, size, or pool data, the+merge path in `internal/monitoring/monitor.go` must promote that missing data+into the canonical physical-disk model without overwriting provider truth. The+Proxmox polling runtime in `internal/monitoring/monitor_pve.go` must evaluate+disk alerts only after that merged disk view exists, so controller-backed disks+do not lose health and endurance coverage between collection and alerting.That same host-agent temperature boundary must not suppress SSH SMART diskcollection just because the agent already reported CPU package or NVMetemperatures. `internal/monitoring/monitor_polling_node_helpers.go` may skip-SSH only once the host-agent temperature payload already has SMART disk data,-so nodes keep their disk-temperature and SMART augmentation when the host agent-is present but lacks SMART support.+SSH only once the host-agent temperature payload already has usable SMART disk+temperatures rather than identity-only or zero-temperature SMART rows. Those+identity-only host-agent rows must still allow wrapper or proxy SMART+augmentation, and proxy SMART temperatures may replace them so nodes keep their+disk-temperature and SMART augmentation when the host agent is present but lacks+usable SMART temperature support.Legacy SSH temperature collection must also use the Pulse sensor-wrappercontract before falling back to raw lm-sensors output. `internal/monitoring/temperature.go`must request `/usr/local/sbin/pulse-sensors` when it exists, parse the wrapperdiff --git a/internal/alerts/config_runtime.go b/internal/alerts/config_runtime.goindex f9dbacec79..53ce1ad190 100644--- a/internal/alerts/config_runtime.go+++ b/internal/alerts/config_runtime.go@@ -271,6 +271,15 @@ func alertPrimaryResourceType(alert *Alert) string {return keys[0]}+func alertResourceTypeKeysContain(keys []string, target string) bool {+ for _, key := range keys {+ if key == target {+ return true+ }+ }+ return false+}+// reevaluateActiveAlertsLocked re-evaluates all active alerts against the current configuration.// This should only be called with m.mu already locked.func (m *Manager) reevaluateActiveAlertsLocked() {@@ -337,13 +346,7 @@ func (m *Manager) reevaluateActiveAlertsLocked() {threshold = getThresholdForMetric(thresholds, metricType)}- isAgentResource := false- for _, key := range resourceTypeKeys {- if key == "agent" {- isAgentResource = true- break- }- }+ isAgentResource := alertResourceTypeKeysContain(resourceTypeKeys, "agent")if !handledModernPlatformType && isAgentResource {if m.config.DisableAllAgents {alertsToResolve = append(alertsToResolve, alertID)@@ -407,7 +410,9 @@ func (m *Manager) reevaluateActiveAlertsLocked() {threshold = getThresholdForMetric(thresholds, metricType)}- if threshold == nil && !handledModernPlatformType && !strings.Contains(resourceID, ":") && (alert.Instance == "Node" || alert.Instance == alert.Node) {+ isNodeResource := primaryResourceType == "" || primaryResourceType == "node"+ isStorageResource := alertResourceTypeKeysContain(resourceTypeKeys, "storage")+ if threshold == nil && !handledModernPlatformType && isNodeResource && !strings.Contains(resourceID, ":") && (alert.Instance == "Node" || alert.Instance == alert.Node) {if m.config.DisableAllNodes {alertsToResolve = append(alertsToResolve, alertID)continue@@ -418,7 +423,7 @@ func (m *Manager) reevaluateActiveAlertsLocked() {continue}threshold = getThresholdForMetric(thresholds, metricType)- } else if threshold == nil && !handledModernPlatformType && (alert.Instance == "Storage" || strings.Contains(alert.ResourceID, ":storage/")) {+ } else if threshold == nil && !handledModernPlatformType && (isStorageResource || alert.Instance == "Storage" || strings.Contains(alert.ResourceID, ":storage/")) {if m.config.DisableAllStorage {alertsToResolve = append(alertsToResolve, alertID)continuediff --git a/internal/alerts/pbs_offline_notification_test.go b/internal/alerts/pbs_offline_notification_test.gonew file mode 100644index 0000000000..f133d845e1--- /dev/null+++ b/internal/alerts/pbs_offline_notification_test.go@@ -0,0 +1,55 @@+package alerts++import (+ "testing"+ "time"++ alertspecs "github.com/rcourtman/pulse-go-rewrite/internal/alerts/specs"+ "github.com/rcourtman/pulse-go-rewrite/internal/models"+)++func TestCheckPBSOfflineDoesNotRenotifyExistingAlert(t *testing.T) {+ m := newTestManager(t)+ m.config.ActivationState = ActivationActive+ dispatched := make(chan *Alert, 1)+ m.SetAlertCallback(func(alert *Alert) {+ dispatched <- alert+ })++ oldSeen := time.Now().Add(-time.Hour)+ notifiedAt := time.Now().Add(-10 * time.Minute)+ state, existing := testNewCanonicalAlert("pbs1", canonicalConnectivitySpecID("pbs1"), string(alertspecs.AlertSpecKindConnectivity), "offline")+ existing.Level = AlertLevelCritical+ existing.LastSeen = oldSeen+ existing.LastNotified = ¬ifiedAt+ existing.Metadata = map[string]interface{}{+ "resourceType": "pbs",+ }++ m.mu.Lock()+ m.offlineConfirmations["pbs1"] = 3+ m.setActiveAlertNoLock(state, existing)+ m.mu.Unlock()++ m.checkPBSOffline(models.PBSInstance{ID: "pbs1", Name: "PBS 1", Host: "pbs.local"})++ select {+ case alert := <-dispatched:+ t.Fatalf("expected repeated PBS offline poll to stay quiet, got callback for %s", alert.ID)+ case <-time.After(50 * time.Millisecond):+ }++ m.mu.RLock()+ active := m.activeAlerts[state]+ m.mu.RUnlock()++ if active == nil {+ t.Fatal("expected existing PBS offline alert to remain active")+ }+ if !active.LastSeen.After(oldSeen) {+ t.Fatalf("expected repeated PBS offline poll to refresh LastSeen after %s, got %s", oldSeen, active.LastSeen)+ }+ if active.LastNotified == nil || !active.LastNotified.Equal(notifiedAt) {+ t.Fatalf("expected LastNotified to remain %s, got %v", notifiedAt, active.LastNotified)+ }+}diff --git a/internal/alerts/quiet_hours_test.go b/internal/alerts/quiet_hours_test.goindex 0d36326323..0d957d7c64 100644--- a/internal/alerts/quiet_hours_test.go+++ b/internal/alerts/quiet_hours_test.go@@ -3,6 +3,8 @@ package alertsimport ("testing""time"++ alertspecs "github.com/rcourtman/pulse-go-rewrite/internal/alerts/specs")func fixedQuietHoursTestManager(now time.Time, quietHours QuietHours) *Manager {@@ -170,6 +172,51 @@ func TestShouldSuppressNotificationQuietHours(t *testing.T) {t.Fatal("expected recovery notification to enter quiet-hours replay queue")}})++ t.Run("manual re-dispatch of offline alert keeps quiet-hours replay metadata", func(t *testing.T) {+ m := newManagerWithQuietHoursSuppress(QuietHoursSuppression{Offline: true})+ m.config.ActivationState = ActivationActive++ received := make(chan *Alert, 1)+ m.SetAlertCallback(func(alert *Alert) {+ received <- alert+ })++ state, alert := testNewCanonicalAlert("pbs1", canonicalConnectivitySpecID("pbs1"), string(alertspecs.AlertSpecKindConnectivity), "offline")+ alert.Level = AlertLevelCritical+ alert.Metadata = map[string]interface{}{+ "resourceType": "pbs",+ }++ m.mu.Lock()+ m.setActiveAlertNoLock(state, alert)+ m.mu.Unlock()++ m.NotifyExistingAlert(state)++ select {+ case dispatched := <-received:+ if dispatched.Metadata[MetadataQuietHoursSuppressed] != true {+ t.Fatalf("expected quiet-hours replay metadata, got %#v", dispatched.Metadata)+ }+ if dispatched.Metadata[MetadataQuietHoursSuppressionReason] != "offline" {+ t.Fatalf("expected offline suppression reason, got %#v", dispatched.Metadata[MetadataQuietHoursSuppressionReason])+ }+ rawReplayAt, ok := dispatched.Metadata[MetadataQuietHoursReplayAt].(string)+ if !ok || rawReplayAt == "" {+ t.Fatalf("expected quiet-hours replay timestamp, got %#v", dispatched.Metadata[MetadataQuietHoursReplayAt])+ }+ replayAt, err := time.Parse(time.RFC3339, rawReplayAt)+ if err != nil {+ t.Fatalf("expected RFC3339 replay timestamp, got %q: %v", rawReplayAt, err)+ }+ if !replayAt.After(m.now()) {+ t.Fatalf("expected replay timestamp after quiet-hours dispatch time, got %s", replayAt)+ }+ case <-time.After(time.Second):+ t.Fatal("expected quiet-hours annotated re-dispatch callback")+ }+ })}func TestIsInQuietHours(t *testing.T) {diff --git a/internal/alerts/threshold_resolution_shared_test.go b/internal/alerts/threshold_resolution_shared_test.goindex a8998a4cab..ba1c3dd475 100644--- a/internal/alerts/threshold_resolution_shared_test.go+++ b/internal/alerts/threshold_resolution_shared_test.go@@ -288,6 +288,40 @@ func TestReevaluateActiveAlertsUsesSharedStorageOverrideResolution(t *testing.T)}}+func TestReevaluateActiveAlertsUsesStorageMetadataForCephPoolAlias(t *testing.T) {+ m := newTestManager(t)+ resourceID := "pve5-ceph-pool-data_replication"++ m.mu.Lock()+ m.config.Enabled = true+ m.config.StorageDefault = HysteresisThreshold{Trigger: 95, Clear: 90}+ m.config.Overrides = map[string]ThresholdConfig{+ "agent:pve5-ceph-pool-data_replication": {+ Usage: &HysteresisThreshold{Trigger: 50, Clear: 45},+ },+ }+ state, alert := testNewCanonicalAlert(resourceID, canonicalMetricSpecID(resourceID, "usage"), string(alertspecs.AlertSpecKindMetricThreshold), "usage")+ alert.Value = 60+ alert.Threshold = 50+ alert.ResourceName = "data_replication"+ alert.Node = "pve5"+ alert.Instance = "pve5"+ alert.Metadata = map[string]interface{}{+ "resourceType": "Storage",+ }+ m.setActiveAlertNoLock(state, alert)+ m.reevaluateActiveAlertsLocked()+ m.mu.Unlock()++ m.mu.RLock()+ _, exists := m.activeAlerts[state]+ m.mu.RUnlock()++ if !exists {+ t.Fatalf("expected Ceph pool storage alert to remain active under agent-prefixed alias override")+ }+}+func TestStorageThresholdResolutionUsesAliasIDs(t *testing.T) {m := newTestManager(t)diff --git a/internal/monitoring/canonical_guardrails_test.go b/internal/monitoring/canonical_guardrails_test.goindex 5ffa6c5340..dd75f7cf76 100644--- a/internal/monitoring/canonical_guardrails_test.go+++ b/internal/monitoring/canonical_guardrails_test.go@@ -1040,7 +1040,9 @@ func TestMonitoringTemperatureFallbackUsesSMARTAwareSSHSkipRule(t *testing.T) {requiredSnippets := map[string][]string{"host_agent_temps.go": {"func shouldSkipTemperatureSSHCollection(hostAgentTemp *models.Temperature) bool {",- "return hostAgentTemp.HasSMART",+ "return hasUsableSMARTTemperature(hostAgentTemp)",+ "func hasUsableSMARTTemperature(temp *models.Temperature) bool {",+ "disk.Temperature > 0 && !disk.StandbySkipped",},"monitor_polling_node_helpers.go": {"skipSSHCollection := shouldSkipTemperatureSSHCollection(hostAgentTemp)",diff --git a/internal/monitoring/host_agent_temps.go b/internal/monitoring/host_agent_temps.goindex 7b9ef26bf8..d0b0db3b4c 100644--- a/internal/monitoring/host_agent_temps.go+++ b/internal/monitoring/host_agent_temps.go@@ -31,11 +31,20 @@ func shouldSkipTemperatureSSHCollection(hostAgentTemp *models.Temperature) boolreturn false}- if hostAgentTemp.HasSMART {- return hostAgentTemp.HasSMART+ return hasUsableSMARTTemperature(hostAgentTemp)+}++func hasUsableSMARTTemperature(temp *models.Temperature) bool {+ if temp == nil || !temp.HasSMART {+ return false}- return hostAgentTemp.HasCPU || hostAgentTemp.HasGPU || hostAgentTemp.HasNVMe+ for _, disk := range temp.SMART {+ if disk.Temperature > 0 && !disk.StandbySkipped {+ return true+ }+ }+ return false}// getHostAgentTemperatureByID looks for a matching host agent by node ID first,@@ -178,7 +187,7 @@ func (m *Monitor) getClusterSensorTemperature(nodeName string) *models.Temperatu// - "nvme0", "nvme1", etc. -> NVMe temperatures// - "gpu_edge", "gpu_junction", etc. -> GPU temperaturesfunc convertHostSensorsToTemperature(sensors models.HostSensorSummary, lastSeen time.Time) *models.Temperature {- if len(sensors.TemperatureCelsius) == 0 {+ if len(sensors.TemperatureCelsius) == 0 && len(sensors.SMART) == 0 {return nil}@@ -309,7 +318,7 @@ func convertHostSensorsToTemperature(sensors models.HostSensorSummary, lastSeencontinue}temp.SMART = append(temp.SMART, models.DiskTemp{- Device: "/dev/" + disk.Device,+ Device: canonicalSMARTDevicePath(disk.Device),Serial: disk.Serial,WWN: disk.WWN,Model: disk.Model,@@ -339,6 +348,14 @@ func convertHostSensorsToTemperature(sensors models.HostSensorSummary, lastSeenreturn temp}+func canonicalSMARTDevicePath(device string) string {+ normalized := normalizeSMARTDeviceIdentifier(device)+ if normalized == "" {+ return ""+ }+ return "/dev/" + normalized+}+// isHostAgentTemperatureRecent checks if the host agent temperature data is recent enough to use.// We consider data stale if the host hasn't reported in more than 2 minutes.func isHostAgentTemperatureRecent(lastSeen time.Time) bool {@@ -372,7 +389,6 @@ func mergeTemperatureData(hostAgentTemp, proxyTemp *models.Temperature) *models.HasCPU: hostAgentTemp.HasCPU,HasGPU: hostAgentTemp.HasGPU,HasNVMe: hostAgentTemp.HasNVMe,- HasSMART: hostAgentTemp.HasSMART || proxyTemp.HasSMART,// The legacy-format marker describes the node's SSH sensor setup; a// linked host agent doesn't fix that setup, so the flag survives the// merge (the UI gate hides the notice once disk temps actually arrive).@@ -388,12 +404,20 @@ func mergeTemperatureData(hostAgentTemp, proxyTemp *models.Temperature) *models.result.HasCPU = true}- // Merge SMART data - prefer host agent if available, fall back to proxy- if hostAgentTemp.HasSMART {+ // Merge SMART data. Prefer host-agent SMART only when it carries usable+ // temperatures; otherwise let the SSH/proxy wrapper fill disk temps and keep+ // host-agent SMART inventory only when neither side has temperatures.+ switch {+ case hasUsableSMARTTemperature(hostAgentTemp):+ result.SMART = hostAgentTemp.SMART+ case hasUsableSMARTTemperature(proxyTemp):+ result.SMART = proxyTemp.SMART+ case hostAgentTemp.HasSMART:result.SMART = hostAgentTemp.SMART- } else if proxyTemp.HasSMART {+ case proxyTemp.HasSMART:result.SMART = proxyTemp.SMART}+ result.HasSMART = len(result.SMART) > 0// Merge GPU data - prefer host agent if availableif !hostAgentTemp.HasGPU && proxyTemp.HasGPU {diff --git a/internal/monitoring/host_agent_temps_test.go b/internal/monitoring/host_agent_temps_test.goindex c0569c1df8..e8fc59e28d 100644--- a/internal/monitoring/host_agent_temps_test.go+++ b/internal/monitoring/host_agent_temps_test.go@@ -170,15 +170,15 @@ func TestShouldSkipTemperatureSSHCollection(t *testing.T) {}})- t.Run("recent cpu only host agent temp skips", func(t *testing.T) {+ t.Run("recent cpu only host agent temp does not skip", func(t *testing.T) {host := &models.Temperature{Available: true,HasCPU: true,CPUPackage: 55,LastUpdate: time.Now(),}- if !shouldSkipTemperatureSSHCollection(host) {- t.Fatal("expected recent CPU-only host agent temp to skip SSH collection")+ if shouldSkipTemperatureSSHCollection(host) {+ t.Fatal("expected recent CPU-only host agent temp to allow SSH SMART augmentation")}})@@ -218,6 +218,19 @@ func TestShouldSkipTemperatureSSHCollection(t *testing.T) {t.Fatal("expected SMART-capable host agent temp to skip SSH collection")}})++ t.Run("host agent smart inventory without temperatures does not skip", func(t *testing.T) {+ host := &models.Temperature{+ Available: true,+ HasCPU: true,+ HasSMART: true,+ SMART: []models.DiskTemp{{Device: "/dev/sda", Temperature: 0}},+ LastUpdate: time.Now(),+ }+ if shouldSkipTemperatureSSHCollection(host) {+ t.Fatal("expected identity-only SMART rows to allow SSH SMART augmentation")+ }+ })}func TestIsHostAgentTemperatureRecent(t *testing.T) {@@ -455,7 +468,7 @@ func TestConvertHostSensorsToTemperature_ExtraBranches(t *testing.T) {sensors := models.HostSensorSummary{TemperatureCelsius: map[string]float64{"cpu_package": 45.0},SMART: []models.HostDiskSMART{- {Device: "sda", Temperature: 35, Standby: false},+ {Device: "/dev/sda [sat]", Temperature: 35, Standby: false},{Device: "sdb", Temperature: 0, Standby: true},},}@@ -465,6 +478,22 @@ func TestConvertHostSensorsToTemperature_ExtraBranches(t *testing.T) {assert.Equal(t, "/dev/sda", result.SMART[0].Device)})+ t.Run("SMART-only sensors stay available", func(t *testing.T) {+ sensors := models.HostSensorSummary{+ SMART: []models.HostDiskSMART{+ {Device: "/dev/sdc", Temperature: 37},+ },+ }+ result := convertHostSensorsToTemperature(sensors, time.Now())+ assert.NotNil(t, result)+ assert.True(t, result.Available)+ assert.True(t, result.HasSMART)+ if assert.Len(t, result.SMART, 1) {+ assert.Equal(t, "/dev/sdc", result.SMART[0].Device)+ assert.Equal(t, 37, result.SMART[0].Temperature)+ }+ })+t.Run("GPU merge into same device", func(t *testing.T) {sensors := models.HostSensorSummary{TemperatureCelsius: map[string]float64{@@ -651,4 +680,23 @@ func TestMergeTemperatureData_HistoricalOverrides(t *testing.T) {assert.Len(t, result.GPU, 1)assert.Len(t, result.NVMe, 1)})++ t.Run("proxy SMART temperatures replace host inventory rows", func(t *testing.T) {+ host := &models.Temperature{+ CPUPackage: 50.0,+ HasCPU: true,+ HasSMART: true,+ SMART: []models.DiskTemp{{Device: "/dev/sda", Temperature: 0}},+ }+ proxy := &models.Temperature{+ HasSMART: true,+ SMART: []models.DiskTemp{{Device: "/dev/sda", Temperature: 39}},+ }++ result := mergeTemperatureData(host, proxy)+ assert.True(t, result.HasSMART)+ if assert.Len(t, result.SMART, 1) {+ assert.Equal(t, 39, result.SMART[0].Temperature)+ }+ })}diff --git a/internal/monitoring/merge_temps_test.go b/internal/monitoring/merge_temps_test.goindex 4b6f5f5bae..d3c6d50cf0 100644--- a/internal/monitoring/merge_temps_test.go+++ b/internal/monitoring/merge_temps_test.go@@ -3,6 +3,7 @@ package monitoringimport ("math""testing"+ "time""github.com/rcourtman/pulse-go-rewrite/internal/models")@@ -350,3 +351,134 @@ func TestNormalizeSMARTDeviceIdentifier(t *testing.T) {}}}++func TestMergeHostAgentSMARTIntoDisks_EnrichesMissingIdentityAndZFSPool(t *testing.T) {+ powerOnHours := int64(12345)+ percentageUsed := 12+ disks := []models.PhysicalDisk{+ {+ ID: "pve1-node1--dev-sda",+ Instance: "pve1",+ Node: "node1",+ DevPath: "/dev/sda",+ Health: "UNKNOWN",+ Wearout: -1,+ LastChecked: mustParseTime(t, "2026-06-01T12:00:00Z"),+ },+ }+ nodes := []models.Node{+ {Name: "node1", LinkedAgentID: "host-node1"},+ }+ hosts := []models.Host{+ {+ ID: "host-node1",+ Sensors: models.HostSensorSummary{+ SMART: []models.HostDiskSMART{+ {+ Device: "sda [sat]",+ Model: "WDC Red",+ Serial: "WD-SATA-1",+ WWN: "5000c5001234abcd",+ Type: "sata",+ SizeBytes: 4_000_000_000_000,+ Temperature: 38,+ Health: "PASSED",+ Pool: "tank",+ Attributes: &models.SMARTAttributes{+ PowerOnHours: &powerOnHours,+ PercentageUsed: &percentageUsed,+ },+ },+ },+ },+ },+ }++ result := mergeHostAgentSMARTIntoDisks(disks, nodes, hosts)+ if len(result) != 1 {+ t.Fatalf("got %d disks, want 1", len(result))+ }+ got := result[0]+ if got.Temperature != 38 {+ t.Fatalf("temperature = %d, want 38", got.Temperature)+ }+ if got.Model != "WDC Red" || got.Serial != "WD-SATA-1" || got.WWN != "5000c5001234abcd" || got.Type != "sata" {+ t.Fatalf("identity not enriched from SMART row: %+v", got)+ }+ if got.Size != 4_000_000_000_000 {+ t.Fatalf("size = %d, want host-agent SMART size", got.Size)+ }+ if got.StorageGroup != "tank" {+ t.Fatalf("storageGroup = %q, want tank", got.StorageGroup)+ }+ if got.Health != "PASSED" {+ t.Fatalf("health = %q, want PASSED", got.Health)+ }+ if got.Wearout != 88 {+ t.Fatalf("wearout = %d, want 88 derived from SMART percentage-used", got.Wearout)+ }+ if got.SmartAttributes == nil || got.SmartAttributes.PowerOnHours == nil || *got.SmartAttributes.PowerOnHours != powerOnHours {+ t.Fatalf("SMART attributes were not copied: %+v", got.SmartAttributes)+ }++ if disks[0].Serial != "" || disks[0].Temperature != 0 || disks[0].StorageGroup != "" {+ t.Fatalf("original disk slice was modified: %+v", disks[0])+ }+}++func TestMergeHostAgentSMARTIntoDisks_PreservesExistingProxmoxIdentity(t *testing.T) {+ disks := []models.PhysicalDisk{+ {+ ID: "pve1-node1--dev-sdb",+ Instance: "pve1",+ Node: "node1",+ DevPath: "/dev/sdb",+ Model: "Proxmox Model",+ Serial: "PVE-SERIAL",+ WWN: "pve-wwn",+ Type: "sas",+ Size: 100,+ Health: "PASSED",+ Temperature: 41,+ StorageGroup: "api-pool",+ },+ }+ nodes := []models.Node{{Name: "node1", LinkedAgentID: "host-node1"}}+ hosts := []models.Host{+ {+ ID: "host-node1",+ Sensors: models.HostSensorSummary{+ SMART: []models.HostDiskSMART{+ {+ Device: "/dev/sdb",+ Model: "Agent Model",+ Serial: "AGENT-SERIAL",+ WWN: "agent-wwn",+ Type: "sata",+ SizeBytes: 200,+ Temperature: 35,+ Health: "FAILED",+ Pool: "agent-pool",+ },+ },+ },+ },+ }++ got := mergeHostAgentSMARTIntoDisks(disks, nodes, hosts)[0]+ if got.Model != "Proxmox Model" || got.Serial != "PVE-SERIAL" || got.WWN != "pve-wwn" || got.Type != "sas" {+ t.Fatalf("existing Proxmox identity was overwritten: %+v", got)+ }+ if got.Size != 100 || got.Temperature != 41 || got.Health != "PASSED" || got.StorageGroup != "api-pool" {+ t.Fatalf("existing Proxmox disk fields were overwritten: %+v", got)+ }+}++func mustParseTime(t *testing.T, raw string) time.Time {+ t.Helper()+ value, err := time.Parse(time.RFC3339, raw)+ if err != nil {+ t.Fatalf("parse time %q: %v", raw, err)+ }+ return value+}diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.goindex 79240baca4..f5dff83ebc 100644--- a/internal/monitoring/monitor.go+++ b/internal/monitoring/monitor.go@@ -544,6 +544,25 @@ func mergeHostAgentSMARTIntoDisks(disks []models.PhysicalDisk, nodes []models.Nocontinue}+ if strings.TrimSpace(updated[i].Model) == "" && strings.TrimSpace(matched.Model) != "" {+ updated[i].Model = strings.TrimSpace(matched.Model)+ }+ if strings.TrimSpace(updated[i].Serial) == "" && strings.TrimSpace(matched.Serial) != "" {+ updated[i].Serial = strings.TrimSpace(matched.Serial)+ }+ if strings.TrimSpace(updated[i].WWN) == "" && strings.TrimSpace(matched.WWN) != "" {+ updated[i].WWN = strings.TrimSpace(matched.WWN)+ }+ if strings.TrimSpace(updated[i].Type) == "" && strings.TrimSpace(matched.Type) != "" {+ updated[i].Type = strings.TrimSpace(matched.Type)+ }+ if updated[i].Size <= 0 && matched.SizeBytes > 0 {+ updated[i].Size = matched.SizeBytes+ }+ if strings.TrimSpace(updated[i].StorageGroup) == "" && strings.TrimSpace(matched.Pool) != "" {+ updated[i].StorageGroup = strings.TrimSpace(matched.Pool)+ }+// Merge temperature if not already setif updated[i].Temperature == 0 && matched.Temperature > 0 {updated[i].Temperature = matched.Temperature