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(alerts): resolve threshold overrides through the registry identity
rcourtman316657b5e859
diff --git a/internal/alerts/host.go b/internal/alerts/host.goindex d09fc4868c..6c46bc27d5 100644--- a/internal/alerts/host.go+++ b/internal/alerts/host.go@@ -83,13 +83,13 @@ func (m *Manager) resolveHostThresholdsNoLock(hostID, linkedNodeID, linkedVMID,// resolveHostThresholdsNoLock's precedence. Callers must hold m.mu.func (m *Manager) hostThresholdOverrideNoLock(hostID, linkedNodeID, linkedVMID, linkedContainerID string) (ThresholdConfig, bool) {if hostID = strings.TrimSpace(hostID); hostID != "" {- if override, exists := m.config.Overrides[hostID]; exists {+ if override, exists := m.thresholdOverrideForResourceNoLock(hostID); exists {return override, true}}if linkedNodeID = strings.TrimSpace(linkedNodeID); linkedNodeID != "" {- if override, exists := m.config.Overrides[linkedNodeID]; exists {+ if override, exists := m.thresholdOverrideForResourceNoLock(linkedNodeID); exists {return override, true}}diff --git a/internal/alerts/unified_eval.go b/internal/alerts/unified_eval.goindex e7777703b5..3df73a5b76 100644--- a/internal/alerts/unified_eval.go+++ b/internal/alerts/unified_eval.go@@ -205,13 +205,38 @@ func (m *Manager) defaultThresholdsForResourceType(typeKey string) ThresholdConf// resolveThresholdOverride applies an exact resource-ID override onto an existing base config.// Callers must hold m.mu when reading config through this helper.func (m *Manager) resolveThresholdOverride(base ThresholdConfig, resourceID string) ThresholdConfig {- if override, exists := m.config.Overrides[resourceID]; exists {+ if override, exists := m.thresholdOverrideForResourceNoLock(resourceID); exists {return m.applyThresholdOverride(base, override)}return base}+// thresholdOverrideForResourceNoLock looks up a stored threshold override by+// exact resource ID first, then under the canonical unified registry identity+// for that ID. The thresholds UI stores overrides keyed by registry resource+// IDs while the engine check paths look up legacy monitor IDs, so without the+// translation a per-resource override on an API-only PVE node saves, displays+// as Custom, and silently never applies (#1738). Callers must hold m.mu.+func (m *Manager) thresholdOverrideForResourceNoLock(resourceID string) (ThresholdConfig, bool) {+ if override, exists := m.config.Overrides[resourceID]; exists {+ return override, true+ }+ if m.resourceIntentResolver == nil {+ return ThresholdConfig{}, false+ }+ canonicalID, ok := m.resourceIntentResolver(resourceID)+ if !ok {+ return ThresholdConfig{}, false+ }+ canonicalID = strings.TrimSpace(canonicalID)+ if canonicalID == "" || canonicalID == resourceID {+ return ThresholdConfig{}, false+ }+ override, exists := m.config.Overrides[canonicalID]+ return override, exists+}+// resolveGuestThresholdOverride applies the shared guest override lookup onto an existing base config.// Callers must hold m.mu when reading config through this helper.func (m *Manager) resolveGuestThresholdOverride(base ThresholdConfig, guest any, guestID string) ThresholdConfig {diff --git a/internal/monitoring/monitor_additional_test.go b/internal/monitoring/monitor_additional_test.goindex fcbeeec112..6e7367ae15 100644--- a/internal/monitoring/monitor_additional_test.go+++ b/internal/monitoring/monitor_additional_test.go@@ -772,3 +772,89 @@ func TestMergedProxmoxHostAgentGraceOverrideHoldsCPUAlert(t *testing.T) {t.Fatalf("CPU alert fired immediately despite 600s per-resource grace override on %q: %+v", merged.ID, alert)}}++func TestNodeThresholdOverrideStoredUnderRegistryIDApplies(t *testing.T) {+ node := models.Node{+ ID: "mock-cluster-pve1",+ Name: "pve1",+ Instance: "mock-cluster",+ Status: "online",+ Type: "node",+ CPU: 0.10,+ Memory: models.Memory{Total: 16 << 30, Used: 10 << 30, Free: 6 << 30, Usage: 60},+ LoadAverage: []float64{},+ }++ newAdapter := func() (*unifiedresources.MonitorAdapter, string) {+ adapter := unifiedresources.NewMonitorAdapter(unifiedresources.NewRegistry(nil))+ adapter.PopulateFromSnapshot(models.StateSnapshot{Nodes: []models.Node{node}})+ for _, resource := range adapter.GetAll() {+ if resource.Proxmox != nil {+ return adapter, resource.ID+ }+ }+ t.Fatal("expected node snapshot to produce a registry resource with a Proxmox facet")+ return nil, ""+ }++ overrideFor := func(registryID string) map[string]alerts.ThresholdConfig {+ return map[string]alerts.ThresholdConfig{+ registryID: {Memory: &alerts.HysteresisThreshold{Trigger: 50, Clear: 45}},+ }+ }++ newManager := func(overrides map[string]alerts.ThresholdConfig) *alerts.Manager {+ manager := alerts.NewManagerWithDataDir(t.TempDir())+ t.Cleanup(manager.Stop)+ cfg := manager.GetConfig()+ cfg.TimeThresholds = map[string]int{"node": 0}+ cfg.MetricTimeThresholds = nil+ cfg.Overrides = overrides+ manager.UpdateConfig(cfg)+ return manager+ }++ memoryAlert := func(manager *alerts.Manager) *alerts.Alert {+ for _, alert := range manager.GetActiveAlerts() {+ if alert.ResourceID == node.ID && alert.Type == "memory" {+ found := alert+ return &found+ }+ }+ return nil+ }++ // Control 1: without the override, the 60% sample stays below the node+ // default, so the fixture cannot fire on defaults alone.+ controlAdapter, _ := newAdapter()+ control := newManager(nil)+ monitorControl := &Monitor{alertManager: control}+ monitorControl.installOperatorIntentResolver(controlAdapter)+ control.CheckNode(node)+ if alert := memoryAlert(control); alert != nil {+ t.Fatalf("control without override fired a memory alert: %+v", alert)+ }++ // Control 2: the override stored under the registry ID with no registry+ // resolver installed never resolves, which is the reported divergence+ // (#1738): the UI shows Custom while the engine evaluates defaults.+ _, registryID := newAdapter()+ unresolved := newManager(overrideFor(registryID))+ unresolved.CheckNode(node)+ if alert := memoryAlert(unresolved); alert != nil {+ t.Fatalf("manager without registry resolver applied a registry-keyed override: %+v", alert)+ }++ adapter, registryID2 := newAdapter()+ manager := newManager(overrideFor(registryID2))+ monitor := &Monitor{alertManager: manager}+ monitor.installOperatorIntentResolver(adapter)+ manager.CheckNode(node)+ alert := memoryAlert(manager)+ if alert == nil {+ t.Fatalf("memory alert did not fire despite 50%% override stored under registry ID %q", registryID2)+ }+ if alert.Threshold != 50 {+ t.Fatalf("alert threshold = %v, want 50", alert.Threshold)+ }+}