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(unifiedresources): derive canonical identity on stored registry resources
rcourtmanb53d96ee5456
diff --git a/internal/monitoring/monitor_additional_test.go b/internal/monitoring/monitor_additional_test.goindex c51eb77a8a..fcbeeec112 100644--- a/internal/monitoring/monitor_additional_test.go+++ b/internal/monitoring/monitor_additional_test.go@@ -6,6 +6,7 @@ import ("testing""time"+ "github.com/rcourtman/pulse-go-rewrite/internal/alerts""github.com/rcourtman/pulse-go-rewrite/internal/config""github.com/rcourtman/pulse-go-rewrite/internal/models"unifiedresources "github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"@@ -679,3 +680,95 @@ func TestMatchZFSPoolForStorageKeepsLocalMatches(t *testing.T) {})}}++// A per-resource grace override saved through the intent policy UI is keyed by+// the unified registry resource ID. For a pulse-agent merged with its Proxmox+// node the alert evaluator references the host as "agent:{hostID}", so the+// override only applies when that reference resolves back to the same merged+// resource the UI saved against (#1497).+func TestMergedProxmoxHostAgentGraceOverrideHoldsCPUAlert(t *testing.T) {+ host := models.Host{+ ID: "host-uuid-1",+ Hostname: "proxmox2",+ MachineID: "machine-abc",+ LinkedNodeID: "node/proxmox2",+ Platform: "linux",+ Status: "online",+ CPUUsage: 95,+ CPUCount: 8,+ IntervalSeconds: 30,+ LastSeen: time.Now(),+ }+ node := models.Node{+ ID: "node/proxmox2",+ Name: "proxmox2",+ Instance: "pve",+ Status: "online",+ LinkedAgentID: "host-uuid-1",+ }++ newAdapter := func() (*unifiedresources.MonitorAdapter, unifiedresources.Resource) {+ adapter := unifiedresources.NewMonitorAdapter(unifiedresources.NewRegistry(nil))+ adapter.PopulateFromSnapshot(models.StateSnapshot{+ Nodes: []models.Node{node},+ Hosts: []models.Host{host},+ })+ for _, resource := range adapter.GetAll() {+ if resource.Agent != nil && resource.Proxmox != nil {+ return adapter, resource+ }+ }+ t.Fatal("expected node+agent snapshot to merge into one resource")+ return nil, unifiedresources.Resource{}+ }++ newManager := func(adapter *unifiedresources.MonitorAdapter) *alerts.Manager {+ manager := alerts.NewManagerWithDataDir(t.TempDir())+ t.Cleanup(manager.Stop)+ cfg := manager.GetConfig()+ // Normalization restores absent keys to the 5s default, but an+ // explicit zero survives, and zero legacy delay makes the assertion+ // discriminating: no override means the alert fires on first check.+ cfg.TimeThresholds = map[string]int{"agent": 0}+ cfg.MetricTimeThresholds = nil+ manager.UpdateConfig(cfg)+ monitor := &Monitor{alertManager: manager}+ monitor.installOperatorIntentResolver(adapter)+ return manager+ }++ hostCPUAlert := func(manager *alerts.Manager) *alerts.Alert {+ for _, alert := range manager.GetActiveAlerts() {+ if alert.ResourceID == "agent:host-uuid-1" && alert.Type == "cpu" {+ found := alert+ return &found+ }+ }+ return nil+ }++ // Control: without an override the CPU alert fires on the first check,+ // proving the fixture actually triggers.+ controlAdapter, _ := newAdapter()+ control := newManager(controlAdapter)+ control.CheckHost(host)+ if hostCPUAlert(control) == nil {+ t.Fatal("control manager without override should raise the CPU alert immediately")+ }++ adapter, merged := newAdapter()+ manager := newManager(adapter)+ grace := 600+ document := alerts.NewAlertIntentPolicyDocument()+ document.Resources = map[string]map[string]alerts.AlertIntentRule{+ merged.ID: {"metric.cpu": {GraceSeconds: &grace}},+ }+ if err := manager.LoadIntentPolicies(document); err != nil {+ t.Fatalf("LoadIntentPolicies: %v", err)+ }++ manager.CheckHost(host)+ if alert := hostCPUAlert(manager); alert != nil {+ t.Fatalf("CPU alert fired immediately despite 600s per-resource grace override on %q: %+v", merged.ID, alert)+ }+}diff --git a/internal/unifiedresources/registry.go b/internal/unifiedresources/registry.goindex a091252357..f546376ac3 100644--- a/internal/unifiedresources/registry.go+++ b/internal/unifiedresources/registry.go@@ -558,6 +558,7 @@ func (rr *ResourceRegistry) ingestSnapshot(snapshot models.StateSnapshot, threshrr.refreshStoragePostureLocked()rr.refreshIncidentRollupsLocked()rr.buildChildCounts()+ rr.refreshCanonicalIdentitiesLocked()rr.markStaleLocked(time.Now().UTC(), thresholds)rr.viewsDirty = truerr.mu.Unlock()@@ -604,6 +605,7 @@ func (rr *ResourceRegistry) IngestRecords(source DataSource, records []IngestRecrr.refreshStoragePostureLocked()rr.refreshIncidentRollupsLocked()rr.buildChildCounts()+ rr.refreshCanonicalIdentitiesLocked()rr.viewsDirty = truerr.mu.Unlock()}@@ -783,6 +785,7 @@ func (rr *ResourceRegistry) ingestResources(resources []Resource, thresholds maprr.refreshStoragePostureLocked()rr.refreshIncidentRollupsLocked()rr.buildChildCounts()+ rr.refreshCanonicalIdentitiesLocked()rr.markStaleLocked(time.Now().UTC(), thresholds)rr.viewsDirty = truerr.mu.Unlock()@@ -4559,6 +4562,19 @@ func (rr *ResourceRegistry) buildChildCounts() {}}+// refreshCanonicalIdentitiesLocked recomputes the derived canonical identity+// on every stored resource. Read paths refresh identity on each clone, but+// reference resolution (GetByReference → canonical alias matching) reads the+// stored entries directly, so ingest must leave the derived block populated or+// prefixed refs like "agent:{hostID}" never resolve and per-resource alert+// policies silently fall back to factory (#1497). Runs after links and merges+// settle so alias sets reflect the fully assembled resource.+func (rr *ResourceRegistry) refreshCanonicalIdentitiesLocked() {+ for _, resource := range rr.resources {+ RefreshCanonicalIdentity(resource)+ }+}+func (rr *ResourceRegistry) refreshLinkedAgentIDFromParentLocked(resource *Resource) {if resource == nil || resource.Proxmox == nil || resource.ParentID == nil {return