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(monitoring): preserve canonical agent identity
rcourtmanc03ec1e74d5a
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.mdindex f69ba1af84..b04617aa37 100644--- a/docs/release-control/v6/internal/subsystems/monitoring.md+++ b/docs/release-control/v6/internal/subsystems/monitoring.md@@ -196,6 +196,12 @@ legacy aliases such as `rrd-available`, `rrd-data`, `node-status-available`,`calculated`, and `listing` must normalize onto the governed canonical labelsbefore snapshots are returned to diagnostics consumers, not only when newsnapshots are first recorded.+The same canonical identity rule now applies when removed host agents are+blocked from re-reporting. `ApplyHostReport` must resolve the final canonical+host identifier for the `(token, machine-id, hostname)` tuple before it checks+`removedHostAgents` or emits the reconnect-blocking error, so removing one+token-bound host cannot poison a different host that shared the same raw+machine identifier.Node disk-source selection now also routes through one canonical resolverunder `internal/monitoring/`. When a Proxmox node has a linked Pulse hostagent, the node summary must prefer the linked host's canonical disk view overdiff --git a/internal/monitoring/canonical_guardrails_test.go b/internal/monitoring/canonical_guardrails_test.goindex d23a4afcd2..f9fb654bb5 100644--- a/internal/monitoring/canonical_guardrails_test.go+++ b/internal/monitoring/canonical_guardrails_test.go@@ -146,6 +146,27 @@ func TestProxmoxGuestPollersCarryPoolIntoCanonicalModels(t *testing.T) {}}+func TestHostAgentRemovalGuardUsesResolvedIdentifier(t *testing.T) {+ data, err := os.ReadFile("monitor_agents.go")+ if err != nil {+ t.Fatalf("failed to read monitor_agents.go: %v", err)+ }+ source := string(data)+ requiredSnippets := []string{+ "removedAt, wasRemoved := m.lookupRemovedHostAgent(identifier, hostname)",+ `Str("hostID", identifier)`,+ `fmt.Errorf("host agent %q had monitoring stopped at %v and cannot report again.`,+ }+ for _, snippet := range requiredSnippets {+ if !strings.Contains(source, snippet) {+ t.Fatalf("monitor_agents.go must contain %q", snippet)+ }+ }+ if strings.Contains(source, "m.lookupRemovedHostAgent(baseIdentifier, hostname)") {+ t.Fatal("monitor_agents.go must not check removed host-agent state against pre-resolution baseIdentifier")+ }+}+func TestAlertLifecycleCanonicalChangesRemainWritable(t *testing.T) {store := unifiedresources.NewMemoryStore()incidentStore := memory.NewIncidentStore(memory.IncidentStoreConfig{})diff --git a/internal/monitoring/monitor_agents.go b/internal/monitoring/monitor_agents.goindex cd4ce05149..f55c129568 100644--- a/internal/monitoring/monitor_agents.go+++ b/internal/monitoring/monitor_agents.go@@ -267,6 +267,28 @@ func (m *Monitor) AllowHostAgentReenroll(hostID string) error {return nil}+func (m *Monitor) lookupRemovedHostAgent(identifier, hostname string) (time.Time, bool) {+ identifier = strings.TrimSpace(identifier)++ m.mu.RLock()+ removedAt, wasRemoved := m.removedHostAgents[identifier]+ m.mu.RUnlock()+ if wasRemoved {+ return removedAt, true+ }++ for _, entry := range m.state.GetRemovedHostAgents() {+ if strings.TrimSpace(entry.ID) == identifier {+ return entry.RemovedAt, true+ }+ if strings.TrimSpace(entry.Hostname) == hostname {+ return entry.RemovedAt, true+ }+ }++ return time.Time{}, false+}+// LinkHostAgent manually links a host agent to a specific PVE node.// This is used when auto-linking can't disambiguate (e.g., multiple nodes with hostname "pve").// After linking, the host agent's temperature/sensor data will appear on the correct node.@@ -1388,28 +1410,6 @@ func (m *Monitor) ApplyHostReport(report agentshost.Report, tokenRecord *config.baseIdentifier = fmt.Sprintf("agent-%s", hex.EncodeToString(sum[:6]))}- m.mu.RLock()- removedAt, wasRemoved := m.removedHostAgents[baseIdentifier]- m.mu.RUnlock()- if !wasRemoved {- for _, entry := range m.state.GetRemovedHostAgents() {- if strings.TrimSpace(entry.Hostname) != hostname {- continue- }- removedAt = entry.RemovedAt- wasRemoved = true- baseIdentifier = strings.TrimSpace(entry.ID)- break- }- }- if wasRemoved {- log.Info().- Str("hostID", baseIdentifier).- Time("removedAt", removedAt).- Msg("Rejecting report from deliberately removed host agent")- return models.Host{}, fmt.Errorf("host agent %q had monitoring stopped at %v and cannot report again. Use Allow reconnect in Settings -> Infrastructure before reconnecting this host", baseIdentifier, removedAt.Format(time.RFC3339))- }-readState := m.snapshotBackedUnifiedReadState()var existingHosts []*unifiedresources.HostViewif readState != nil {@@ -1476,6 +1476,15 @@ func (m *Monitor) ApplyHostReport(report agentshost.Report, tokenRecord *config.}}+ removedAt, wasRemoved := m.lookupRemovedHostAgent(identifier, hostname)+ if wasRemoved {+ log.Info().+ Str("hostID", identifier).+ Time("removedAt", removedAt).+ Msg("Rejecting report from deliberately removed host agent")+ return models.Host{}, fmt.Errorf("host agent %q had monitoring stopped at %v and cannot report again. Use Allow reconnect in Settings -> Infrastructure before reconnecting this host", identifier, removedAt.Format(time.RFC3339))+ }+var previous *unifiedresources.HostViewvar hasPrevious boolfor _, candidate := range existingHosts {diff --git a/internal/monitoring/monitor_extra_coverage_test.go b/internal/monitoring/monitor_extra_coverage_test.goindex 1299e6bad1..5d8423db9a 100644--- a/internal/monitoring/monitor_extra_coverage_test.go+++ b/internal/monitoring/monitor_extra_coverage_test.go@@ -842,8 +842,8 @@ func (m *mockResourceStoreExtra) UnifiedResourceFreshness() time.Time {func TestMonitor_ResourcesForBroadcast_Extra(t *testing.T) {m := &Monitor{}- if m.getResourcesForBroadcast() != nil {- t.Error("Expected nil when store is nil")+ if res := m.getResourcesForBroadcast(); res == nil || len(res) != 0 {+ t.Fatalf("expected empty resources when store is nil, got %#v", res)}now := time.Now().UTC()diff --git a/internal/servicediscovery/service_test.go b/internal/servicediscovery/service_test.goindex 2dd5245c3b..07c70c285e 100644--- a/internal/servicediscovery/service_test.go+++ b/internal/servicediscovery/service_test.go@@ -3,6 +3,7 @@ package servicediscoveryimport ("context""encoding/json"+ "fmt""os""path/filepath""strings"@@ -217,6 +218,7 @@ func readStateFromSnapshot(snap StateSnapshot) unifiedresources.ReadState {ms := models.StateSnapshot{}for _, vm := range snap.VMs {ms.VMs = append(ms.VMs, models.VM{+ ID: fmt.Sprintf("vm-%d", vm.VMID),VMID: vm.VMID,Name: vm.Name,Node: vm.Node,@@ -227,6 +229,7 @@ func readStateFromSnapshot(snap StateSnapshot) unifiedresources.ReadState {}for _, ct := range snap.Containers {ms.Containers = append(ms.Containers, models.Container{+ ID: fmt.Sprintf("ct-%d", ct.VMID),VMID: ct.VMID,Name: ct.Name,Node: ct.Node,@@ -242,8 +245,15 @@ func readStateFromSnapshot(snap StateSnapshot) unifiedresources.ReadState {Hostname: dh.Hostname,}for _, dc := range dh.Containers {+ containerID := strings.TrimSpace(dc.ID)+ if containerID == "" {+ containerID = fmt.Sprintf("%s:%s", strings.TrimSpace(dh.AgentID), strings.TrimSpace(dc.Name))+ if strings.TrimSpace(dh.AgentID) == "" {+ containerID = fmt.Sprintf("docker:%s", strings.TrimSpace(dc.Name))+ }+ }mc := models.DockerContainer{- ID: dc.ID,+ ID: containerID,Name: dc.Name,Image: dc.Image,State: dc.Status, // servicediscovery.DockerContainer.Status maps to Docker engine state