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
Keep clusters that reuse node names apart in node state aggregation
rcourtmanf8cdd76b79f8
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.mdindex 0c2185e5c5..c9cad4963d 100644--- a/docs/release-control/v6/internal/subsystems/monitoring.md+++ b/docs/release-control/v6/internal/subsystems/monitoring.md@@ -56,6 +56,14 @@ configured cluster labels must project into node display names as`cluster label (node name)` so duplicate node hostnames across clusters remaindistinguishable, while `models.Node.Name` and `ProxmoxData.NodeName` keep theraw Proxmox node identity for linking, metrics, URLs, and actions.+Node state aggregation is cluster-identity-scoped beyond presentation: a+hostname match alone must never bind a node to a host agent, and neither a+shared linked-agent identity nor an endpoint merge alias may fold two node+slots into one, when the two sides carry contradicting non-empty cluster+names. A hostname-based agent match is also rejected when the node's endpoint+IP is absent from the candidate agent's reported IPs. Nodes with empty+cluster names keep merging into their cluster view so standalone and+not-yet-classified endpoint views of the same machine still fold together.Docker and Podman container CPU collection preserves the runtime-native rawper-core CPU percent, but monitoring-owned history and alert thresholdevaluation use host-capacity-normalized CPU percent when host CPU capacity isdiff --git a/internal/models/models.go b/internal/models/models.goindex 7815d954d5..950e8b84fc 100644--- a/internal/models/models.go+++ b/internal/models/models.go@@ -3336,6 +3336,15 @@ func registerNodeAliases(}}+// nodeClusterIdentityConflicts reports whether two nodes belong to two+// different named clusters. Empty cluster names never conflict: a standalone+// or not-yet-classified view of a node may still merge into its cluster view.+func nodeClusterIdentityConflicts(a, b string) bool {+ clusterA := normalizeNodeIdentityPart(a)+ clusterB := normalizeNodeIdentityPart(b)+ return clusterA != "" && clusterB != "" && clusterA != clusterB+}+func resolveNodeMergeKey(primaryKey string,node Node,@@ -3359,6 +3368,12 @@ func resolveNodeMergeKey(if !ok || key == "" {continue}+ // Two clusters can reuse node names (pve01 in cluster A and cluster B),+ // so an endpoint alias is only trustworthy when the cluster identities+ // don't contradict each other.+ if existing, exists := nodeMap[key]; exists && nodeClusterIdentityConflicts(existing.ClusterName, node.ClusterName) {+ continue+ }if resolved != "" && resolved != key {return primaryKey}@@ -3473,8 +3488,9 @@ func (s *State) UpdateNodesForInstance(instanceName string, nodes []Node) {defer s.mu.Unlock()// Preserve LinkedAgentID for nodes that are being updated, including when IDs churn.- existingNodeLinks := make(map[string]string) // nodeID -> linkedAgentID- existingNodeLinksByLogicalKey := make(map[string]string) // logical node key -> linkedAgentID+ existingNodeLinks := make(map[string]string) // nodeID -> linkedAgentID+ existingNodeLinksByLogicalKey := make(map[string]string) // logical node key -> linkedAgentID+ agentClusterHints := make(map[string]map[string]struct{}) // linkedAgentID -> normalized cluster names of its linked nodesfor _, node := range s.Nodes {if node.LinkedAgentID == "" {continue@@ -3483,6 +3499,14 @@ func (s *State) UpdateNodesForInstance(instanceName string, nodes []Node) {if key := nodeLogicalKey(node); key != "" {existingNodeLinksByLogicalKey[key] = node.LinkedAgentID}+ if cluster := normalizeNodeIdentityPart(node.ClusterName); cluster != "" {+ hints := agentClusterHints[node.LinkedAgentID]+ if hints == nil {+ hints = make(map[string]struct{})+ agentClusterHints[node.LinkedAgentID] = hints+ }+ hints[cluster] = struct{}{}+ }}// Build map excluding nodes from this instance (they'll be replaced by the new set).@@ -3568,6 +3592,7 @@ func (s *State) UpdateNodesForInstance(instanceName string, nodes []Node) {}bucket[hostID] = struct{}{}}+ hostIPsByID := make(map[string]map[string]struct{}) // hostAgentID -> normalized ips it reportsaddHostIP := func(address, hostID string) {ip := normalizeIPAddress(address)if ip == "" || hostID == "" {@@ -3579,6 +3604,12 @@ func (s *State) UpdateNodesForInstance(instanceName string, nodes []Node) {hostAgentByIP[ip] = bucket}bucket[hostID] = struct{}{}+ ips := hostIPsByID[hostID]+ if ips == nil {+ ips = make(map[string]struct{})+ hostIPsByID[hostID] = ips+ }+ ips[ip] = struct{}{}}for _, host := range s.Hosts {if host.ID != "" {@@ -3597,6 +3628,29 @@ func (s *State) UpdateNodesForInstance(instanceName string, nodes []Node) {}}+ // Hostname matches are weak evidence: two clusters can reuse the same node+ // names on different subnets. Reject a candidate agent when the evidence we+ // do hold contradicts the node - the agent's linked nodes live in a different+ // named cluster, or the node's endpoint IP is absent from the IPs the agent+ // reports.+ hostContradictsNode := func(hostID string, node Node) bool {+ if hints := agentClusterHints[hostID]; len(hints) > 0 {+ if cluster := normalizeNodeIdentityPart(node.ClusterName); cluster != "" {+ if _, sameCluster := hints[cluster]; !sameCluster {+ return true+ }+ }+ }+ if nodeIP := normalizeIPAddress(extractHostEndpoint(node.Host)); nodeIP != "" {+ if ips := hostIPsByID[hostID]; len(ips) > 0 {+ if _, known := ips[nodeIP]; !known {+ return true+ }+ }+ }+ return false+ }+// Add or update nodes from this instancefor _, node := range dedupedNodes {// Preserve existing link if we had one, but only if the host agent still exists@@ -3627,13 +3681,17 @@ func (s *State) UpdateNodesForInstance(instanceName string, nodes []Node) {} else if endpoint != "" {if ids, ok := hostAgentByHostname[strings.ToLower(endpoint)]; ok {for hostID := range ids {- endpointCandidates[hostID] = struct{}{}+ if !hostContradictsNode(hostID, node) {+ endpointCandidates[hostID] = struct{}{}+ }}}if short := shortHostname(endpoint); short != "" && short != strings.ToLower(endpoint) {if ids, ok := hostAgentByHostname[short]; ok {for hostID := range ids {- endpointCandidates[hostID] = struct{}{}+ if !hostContradictsNode(hostID, node) {+ endpointCandidates[hostID] = struct{}{}+ }}}}@@ -3652,13 +3710,17 @@ func (s *State) UpdateNodesForInstance(instanceName string, nodes []Node) {if nodeName != "" {if ids, ok := hostAgentByHostname[nodeName]; ok {for hostID := range ids {- candidates[hostID] = struct{}{}+ if !hostContradictsNode(hostID, node) {+ candidates[hostID] = struct{}{}+ }}}if idx := strings.Index(nodeName, "."); idx > 0 {if ids, ok := hostAgentByHostname[nodeName[:idx]]; ok {for hostID := range ids {- candidates[hostID] = struct{}{}+ if !hostContradictsNode(hostID, node) {+ candidates[hostID] = struct{}{}+ }}}}@@ -3675,7 +3737,11 @@ func (s *State) UpdateNodesForInstance(instanceName string, nodes []Node) {if node.LinkedAgentID != "" {if _, ambiguous := ambiguousLinkedHosts[node.LinkedAgentID]; !ambiguous {if linkedKey := linkedHostToKey[node.LinkedAgentID]; linkedKey != "" {- targetKey = linkedKey+ // A shared agent identity must never collapse two different+ // named clusters into one node slot.+ if existing, ok := nodeMap[linkedKey]; !ok || !nodeClusterIdentityConflicts(existing.ClusterName, node.ClusterName) {+ targetKey = linkedKey+ }}}}diff --git a/internal/models/state_host_test.go b/internal/models/state_host_test.goindex 5502c9fdd5..9d3b249a28 100644--- a/internal/models/state_host_test.go+++ b/internal/models/state_host_test.go@@ -1425,3 +1425,172 @@ func TestHostIntegrationSourceRoundTrip(t *testing.T) {t.Fatalf("expected integrationSource omitted for agent hosts, got %s", unmarked)}}++// Two clusters reusing the same node names (pve01/pve02 on different subnets)+// must stay apart: the second cluster's node must not steal the first+// cluster's agent link by bare hostname, and the shared name must not merge+// the two nodes into one slot.+func TestUpdateNodesForInstanceKeepsClustersWithSharedNodeNamesApart(t *testing.T) {+ state := &State{+ Hosts: []Host{+ {+ ID: "host-enacon-pve01",+ Hostname: "pve01",+ ReportIP: "192.168.16.11",+ NetworkInterfaces: []HostNetworkInterface{+ {Name: "eth0", Addresses: []string{"192.168.16.11/24"}},+ },+ },+ {+ ID: "host-enacon-pve02",+ Hostname: "pve02",+ ReportIP: "192.168.16.12",+ NetworkInterfaces: []HostNetworkInterface{+ {Name: "eth0", Addresses: []string{"192.168.16.12/24"}},+ },+ },+ },+ Nodes: []Node{+ {+ ID: "enacon-pve01",+ Name: "pve01",+ Instance: "enacon",+ ClusterName: "enacon",+ IsClusterMember: true,+ Host: "https://192.168.16.11:8006",+ LinkedAgentID: "host-enacon-pve01",+ Status: "online",+ },+ {+ ID: "enacon-pve02",+ Name: "pve02",+ Instance: "enacon",+ ClusterName: "enacon",+ IsClusterMember: true,+ Host: "https://192.168.16.12:8006",+ LinkedAgentID: "host-enacon-pve02",+ Status: "online",+ },+ },+ }++ state.UpdateNodesForInstance("rewo", []Node{+ {+ ID: "rewo-pve01",+ Name: "pve01",+ Instance: "rewo",+ ClusterName: "rewo",+ IsClusterMember: true,+ Host: "https://192.168.1.11:8006",+ Status: "online",+ },+ })++ if len(state.Nodes) != 3 {+ t.Fatalf("nodes = %#v, want 3 (enacon pve01+pve02 and rewo pve01)", state.Nodes)+ }++ byID := make(map[string]Node)+ for _, node := range state.Nodes {+ byID[node.ID] = node+ }++ enacon, ok := byID["enacon-pve01"]+ if !ok {+ t.Fatalf("enacon-pve01 was clobbered, nodes = %#v", state.Nodes)+ }+ if enacon.ClusterName != "enacon" {+ t.Fatalf("enacon-pve01 ClusterName = %q, want enacon", enacon.ClusterName)+ }+ if enacon.LinkedAgentID != "host-enacon-pve01" {+ t.Fatalf("enacon-pve01 LinkedAgentID = %q, want host-enacon-pve01", enacon.LinkedAgentID)+ }++ rewo, ok := byID["rewo-pve01"]+ if !ok {+ t.Fatalf("rewo-pve01 missing, nodes = %#v", state.Nodes)+ }+ if rewo.ClusterName != "rewo" {+ t.Fatalf("rewo-pve01 ClusterName = %q, want rewo", rewo.ClusterName)+ }+ if rewo.LinkedAgentID != "" {+ t.Fatalf("rewo-pve01 LinkedAgentID = %q, want none (its host runs no agent)", rewo.LinkedAgentID)+ }+}++// When TLS settings degrade node endpoints to the bare node name, the+// endpoint-host merge alias is identical for both clusters. The alias must+// not merge nodes whose named clusters contradict each other.+func TestUpdateNodesForInstanceEndpointHostAliasDoesNotMergeAcrossClusters(t *testing.T) {+ state := &State{+ Nodes: []Node{+ {+ ID: "enacon-pve01",+ Name: "pve01",+ Instance: "enacon",+ ClusterName: "enacon",+ IsClusterMember: true,+ Host: "https://pve01:8006",+ Status: "online",+ },+ },+ }++ state.UpdateNodesForInstance("rewo", []Node{+ {+ ID: "rewo-pve01",+ Name: "pve01",+ Instance: "rewo",+ ClusterName: "rewo",+ IsClusterMember: true,+ Host: "https://pve01:8006",+ Status: "online",+ },+ })++ if len(state.Nodes) != 2 {+ t.Fatalf("nodes = %#v, want 2 (one per cluster)", state.Nodes)+ }+ clusters := map[string]bool{}+ for _, node := range state.Nodes {+ clusters[node.ClusterName] = true+ }+ if !clusters["enacon"] || !clusters["rewo"] {+ t.Fatalf("clusters = %#v, want both enacon and rewo", clusters)+ }+}++// A standalone node whose endpoint IP is absent from a same-named agent's+// reported IPs must not link to that agent: the IP evidence contradicts the+// hostname match.+func TestUpdateNodesForInstanceHostnameMatchRejectedWhenIPContradicts(t *testing.T) {+ state := &State{+ Hosts: []Host{+ {+ ID: "host-a",+ Hostname: "pve01",+ ReportIP: "192.168.16.11",+ NetworkInterfaces: []HostNetworkInterface{+ {Name: "eth0", Addresses: []string{"192.168.16.11/24"}},+ },+ },+ },+ }++ state.UpdateNodesForInstance("steinboeck", []Node{+ {+ ID: "steinboeck-pve01",+ Name: "pve01",+ Instance: "steinboeck",+ Host: "https://10.20.1.5:8006",+ Status: "online",+ },+ })++ if len(state.Nodes) != 1 {+ t.Fatalf("nodes = %#v, want 1", state.Nodes)+ }+ if state.Nodes[0].LinkedAgentID != "" {+ t.Fatalf("LinkedAgentID = %q, want none (agent IPs contradict node endpoint)", state.Nodes[0].LinkedAgentID)+ }+}