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
Stop same-short-name hosts collapsing across estates
rcourtman53ba9786c552
diff --git a/internal/unifiedresources/presentation_coalesce.go b/internal/unifiedresources/presentation_coalesce.goindex 322b6ca5e9..ce7b77581a 100644--- a/internal/unifiedresources/presentation_coalesce.go+++ b/internal/unifiedresources/presentation_coalesce.go@@ -61,6 +61,9 @@ func coalescePresentationHostResourcesOnce(if excluded != nil && excluded(existing, resource) {continue}+ if presentationHostIdentitiesDistinct(existing, resource) {+ continue+ }if !presentationHostnamesCompatible(existing, resource) {continue}@@ -166,6 +169,61 @@ func presentationHostnameCandidates(resource Resource) []string {return candidates}+// presentationMachineIDs returns the hardware machine identifiers a host row+// carries.+func presentationMachineIDs(resource Resource) []string {+ candidates := []string{resource.Identity.MachineID}+ if resource.Agent != nil {+ candidates = append(candidates, resource.Agent.MachineID)+ }+ ids := candidates[:0]+ for _, id := range candidates {+ if id = strings.TrimSpace(id); id != "" {+ ids = append(ids, id)+ }+ }+ return ids+}++func presentationMachineIDsOverlap(left, right []string) bool {+ for _, leftID := range left {+ for _, rightID := range right {+ if strings.EqualFold(leftID, rightID) {+ return true+ }+ }+ }+ return false+}++// presentationHostIdentitiesDistinct reports whether two host views carry+// identity proving they are different machines. Distinct machines share a+// merge bucket whenever both report only a short hostname (#1753: a pve01 in+// staging and a pve01 in production), so a differing machine ID, DMI UUID, or+// Proxmox cluster membership must veto the merge no matter what the hostname+// comparison concludes. Equal cluster names deliberately do not veto: the same+// cluster added under two connections still describes the same machines.+func presentationHostIdentitiesDistinct(left, right Resource) bool {+ leftIDs, rightIDs := presentationMachineIDs(left), presentationMachineIDs(right)+ if len(leftIDs) > 0 && len(rightIDs) > 0 && !presentationMachineIDsOverlap(leftIDs, rightIDs) {+ return true+ }+ if presentationIdentityValuesConflict(left.Identity.DMIUUID, right.Identity.DMIUUID) {+ return true+ }+ if left.Proxmox != nil && right.Proxmox != nil &&+ presentationIdentityValuesConflict(left.Proxmox.ClusterName, right.Proxmox.ClusterName) {+ return true+ }+ return false+}++func presentationIdentityValuesConflict(left, right string) bool {+ left = strings.TrimSpace(left)+ right = strings.TrimSpace(right)+ return left != "" && right != "" && !strings.EqualFold(left, right)+}+// presentationHostnamesCompatible reports whether two host views may describe// the same machine. Sharing a short hostname is not enough: distinct dotted// hostnames (cloud.rnd-lax1 vs cloud.gce-or1) belong to distinct machines,diff --git a/internal/unifiedresources/presentation_coalesce_test.go b/internal/unifiedresources/presentation_coalesce_test.goindex d4ee5e30d8..d151b04f43 100644--- a/internal/unifiedresources/presentation_coalesce_test.go+++ b/internal/unifiedresources/presentation_coalesce_test.go@@ -456,3 +456,83 @@ func TestCoalescePresentationHostResourcesKeepsLiveAgentCPU(t *testing.T) {t.Fatalf("expected live agent CPU 12 to be kept, got %+v", cpu)}}++// Two estates each running a node named pve01 must not collapse into one host+// row just because PVE node names are short. Refs #1753.+func TestCoalescePresentationHostResourcesKeepsSameShortNameEstatesApart(t *testing.T) {+ estateRow := func(id, machineID, cluster string) Resource {+ identity := ResourceIdentity{Hostnames: []string{"pve01"}, MachineID: machineID}+ agent := &AgentData{Hostname: "pve01", MachineID: machineID, OSName: "Proxmox VE"}+ return Resource{+ ID: id,+ Type: ResourceTypeAgent,+ Name: "pve01",+ Status: StatusOnline,+ Sources: []DataSource{SourceAgent, SourceProxmox},+ Identity: identity,+ Agent: agent,+ Proxmox: &ProxmoxData{NodeName: "pve01", ClusterName: cluster},+ }+ }++ t.Run("distinct machine ids veto the merge", func(t *testing.T) {+ resources := []Resource{+ estateRow("agent-staging-pve01", "machine-staging", ""),+ estateRow("agent-production-pve01", "machine-production", ""),+ }+ if got := CoalescePresentationHostResources(resources); len(got) != 2 {+ t.Fatalf("expected distinct machines to stay apart, got %d rows: %#v", len(got), got)+ }+ })++ t.Run("distinct proxmox clusters veto the merge without machine ids", func(t *testing.T) {+ platformOnly := estateRow("node-production-pve01", "", "production")+ platformOnly.Sources = []DataSource{SourceProxmox}+ platformOnly.Agent = nil+ resources := []Resource{+ estateRow("agent-staging-pve01", "machine-staging", "staging"),+ platformOnly,+ }+ if got := CoalescePresentationHostResources(resources); len(got) != 2 {+ t.Fatalf("expected distinct clusters to stay apart, got %d rows: %#v", len(got), got)+ }+ })++ t.Run("distinct dmi uuids veto the merge", func(t *testing.T) {+ left := estateRow("agent-staging-pve01", "", "")+ left.Identity.DMIUUID = "uuid-staging"+ right := estateRow("agent-production-pve01", "", "")+ right.Identity.DMIUUID = "uuid-production"+ right.Sources = []DataSource{SourceProxmox}+ right.Agent = nil+ if got := CoalescePresentationHostResources([]Resource{left, right}); len(got) != 2 {+ t.Fatalf("expected distinct DMI UUIDs to stay apart, got %d rows: %#v", len(got), got)+ }+ })++ t.Run("control: without distinguishing identity the rows merge", func(t *testing.T) {+ platformOnly := estateRow("node-pve01", "", "")+ platformOnly.Sources = []DataSource{SourceProxmox}+ platformOnly.Agent = nil+ resources := []Resource{+ estateRow("agent-pve01", "machine-shared", ""),+ platformOnly,+ }+ if got := CoalescePresentationHostResources(resources); len(got) != 1 {+ t.Fatalf("expected identity-free split views to still merge, got %d rows: %#v", len(got), got)+ }+ })++ t.Run("control: equal cluster names still merge", func(t *testing.T) {+ platformOnly := estateRow("node-pve01", "", "homelab")+ platformOnly.Sources = []DataSource{SourceProxmox}+ platformOnly.Agent = nil+ resources := []Resource{+ estateRow("agent-pve01", "machine-shared", "homelab"),+ platformOnly,+ }+ if got := CoalescePresentationHostResources(resources); len(got) != 1 {+ t.Fatalf("expected same-cluster views to merge, got %d rows: %#v", len(got), got)+ }+ })+}diff --git a/internal/unifiedresources/proxmox_node_links.go b/internal/unifiedresources/proxmox_node_links.goindex 0710fbcdae..156520a970 100644--- a/internal/unifiedresources/proxmox_node_links.go+++ b/internal/unifiedresources/proxmox_node_links.go@@ -25,6 +25,36 @@ func inferLinkedHostsForProxmoxNodes(nodes []models.Node, hostByID map[string]*mnodeIDToHostID := make(map[string]string)ambiguousNodeIDs := make(map[string]struct{})trustedHostIDs := make(map[string]struct{})+ hostClusterByID := make(map[string]string)+ hostClusterAmbiguous := make(map[string]struct{})+ recordHostCluster := func(hostID string, node models.Node) {+ hostID = strings.TrimSpace(hostID)+ cluster := strings.TrimSpace(strings.ToLower(node.ClusterName))+ if hostID == "" || cluster == "" {+ return+ }+ if _, ambiguous := hostClusterAmbiguous[hostID]; ambiguous {+ return+ }+ if existing, ok := hostClusterByID[hostID]; ok && existing != cluster {+ delete(hostClusterByID, hostID)+ hostClusterAmbiguous[hostID] = struct{}{}+ return+ }+ hostClusterByID[hostID] = cluster+ }+ // Short hostnames and short endpoint aliases collide across estates+ // (#1753: pve01 in staging vs pve01 in production), so a host whose+ // trusted link pins it to one cluster must never be inferred for a node+ // from a different cluster, whichever inference path proposed it.+ hostClusterConflicts := func(hostID string, node models.Node) bool {+ hostCluster := hostClusterByID[strings.TrimSpace(hostID)]+ if hostCluster == "" {+ return false+ }+ nodeCluster := strings.TrimSpace(strings.ToLower(node.ClusterName))+ return nodeCluster != "" && nodeCluster != hostCluster+ }register := func(key, hostID string) {key = strings.TrimSpace(key)hostID = strings.TrimSpace(hostID)@@ -68,6 +98,7 @@ func inferLinkedHostsForProxmoxNodes(nodes []models.Node, hostByID map[string]*mcontinue}trustedHostIDs[hostID] = struct{}{}+ recordHostCluster(hostID, node)for _, key := range proxmoxNodeLinkKeys(node) {register(key, hostID)}@@ -86,6 +117,7 @@ func inferLinkedHostsForProxmoxNodes(nodes []models.Node, hostByID map[string]*mcontinue}trustedHostIDs[hostID] = struct{}{}+ recordHostCluster(hostID, *node)registerNode(nodeID, hostID)for _, key := range proxmoxNodeLinkKeys(*node) {register(key, hostID)@@ -121,7 +153,7 @@ func inferLinkedHostsForProxmoxNodes(nodes []models.Node, hostByID map[string]*mcontinue}hostID := strings.TrimSpace(keyToHostID[key])- if hostID == "" {+ if hostID == "" || hostClusterConflicts(hostID, node) {continue}if inferredHostID != "" && inferredHostID != hostID {@@ -138,6 +170,9 @@ func inferLinkedHostsForProxmoxNodes(nodes []models.Node, hostByID map[string]*m!proxmoxNodeCorroboratesHost(node, *host) {continue}+ if hostClusterConflicts(hostID, node) {+ continue+ }if inferredHostID != "" && inferredHostID != hostID {inferredHostID = ""breakdiff --git a/internal/unifiedresources/proxmox_node_links_test.go b/internal/unifiedresources/proxmox_node_links_test.gonew file mode 100644index 0000000000..81ad335afb--- /dev/null+++ b/internal/unifiedresources/proxmox_node_links_test.go@@ -0,0 +1,58 @@+package unifiedresources++import (+ "testing"++ "github.com/rcourtman/pulse-go-rewrite/internal/models"+)++// A host trusted-linked into one cluster must not be inferred as the agent+// view of a same-named node in a different cluster. Refs #1753.+func TestInferLinkedHostsForProxmoxNodesKeepsClustersApart(t *testing.T) {+ stagingNode := models.Node{+ ID: "staging-pve01",+ Name: "pve01",+ ClusterName: "staging",+ Host: "https://pve01.staging.tld:8006",+ LinkedAgentID: "host-a",+ }+ hostA := &models.Host{+ ID: "host-a",+ Hostname: "pve01",+ LinkedNodeID: "staging-pve01",+ }++ t.Run("different cluster blocks the short-name fallback", func(t *testing.T) {+ productionNode := models.Node{+ ID: "production-pve01",+ Name: "pve01",+ ClusterName: "production",+ Host: "https://pve01.production.tld:8006",+ }+ out := inferLinkedHostsForProxmoxNodes(+ []models.Node{stagingNode, productionNode},+ map[string]*models.Host{"host-a": hostA},+ )+ if out["staging-pve01"] != hostA {+ t.Fatalf("expected staging node to keep its trusted host link, got %+v", out["staging-pve01"])+ }+ if linked, ok := out["production-pve01"]; ok {+ t.Fatalf("expected production node to stay unlinked, got %+v", linked)+ }+ })++ t.Run("control: unknown cluster still falls back on the short name", func(t *testing.T) {+ orphanNode := models.Node{+ ID: "standalone-pve01",+ Name: "pve01",+ Host: "https://192.0.2.10:8006",+ }+ out := inferLinkedHostsForProxmoxNodes(+ []models.Node{stagingNode, orphanNode},+ map[string]*models.Host{"host-a": hostA},+ )+ if out["standalone-pve01"] != hostA {+ t.Fatalf("expected cluster-less node to keep the legacy fallback link, got %+v", out["standalone-pve01"])+ }+ })+}