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
Merge PBS and PMG host agents into their API connection rows
rcourtman121b227bc6e6
diff --git a/internal/api/connections_grouping.go b/internal/api/connections_grouping.goindex b076477fd1..e9365b5fbc 100644--- a/internal/api/connections_grouping.go+++ b/internal/api/connections_grouping.go@@ -591,6 +591,13 @@ func resolveAgentAttachments(}}+ for _, attachment := range identityGroupedAgentAttachments(connectionByID, hostIndex, resources) {+ if _, exists := attachments[attachment.agentID]; exists {+ continue+ }+ register(attachment.agentID, attachment.primaryID, false, true)+ }+for _, agent := range sortedConnectionsByID(connectionByID) {if agent.Type != ConnectionTypeAgent {continue@@ -612,6 +619,108 @@ func resolveAgentAttachments(return attachments}+type identityGroupedAgentAttachment struct {+ agentID string+ primaryID string+}++// identityGroupedAgentAttachments pairs agent connections with the single+// PBS, PMG, or TrueNAS connection whose host resolves into the same+// top-level system group. The shared resolver holds the canonical+// same-machine contract (machine identity, short-form hostname equivalence,+// unique IPs), so a PBS host running a Pulse agent pairs here even when the+// configured API address shares no literal host string with anything the+// agent reports — the case the direct host fallback below cannot see.+// Proxmox stays with the LinkedAgentID passes, which carry the+// cluster-membership semantics this group view does not.+func identityGroupedAgentAttachments(+ connectionByID map[string]Connection,+ hostIndex connectionHostIndex,+ resources []unified.Resource,+) []identityGroupedAgentAttachment {+ // Mirror the monitored-system root set (infrastructure parents plus+ // PBS, PMG, and Kubernetes cluster roots) so grouping resolves with the+ // same ambiguity evidence the Infrastructure surfaces use.+ roots := make([]unified.Resource, 0, len(resources))+ for _, resource := range resources {+ switch unified.CanonicalResourceType(resource.Type) {+ case unified.ResourceTypeAgent, unified.ResourceTypePBS, unified.ResourceTypePMG,+ unified.ResourceTypeK8sCluster:+ roots = append(roots, resource)+ }+ }+ if len(roots) == 0 {+ return nil+ }++ resolver := unified.ResolveTopLevelSystems(roots)+ type groupBucket struct {+ agentIDs []string+ primaries map[string]struct{}+ }+ buckets := make(map[string]*groupBucket)+ bucketFor := func(groupID string) *groupBucket {+ bucket := buckets[groupID]+ if bucket == nil {+ bucket = &groupBucket{primaries: make(map[string]struct{})}+ buckets[groupID] = bucket+ }+ return bucket+ }+ for _, resource := range roots {+ groupID := resolver.GroupIDForResource(resource)+ if groupID == "" {+ continue+ }+ if resource.Agent != nil {+ agentID := "agent:" + strings.TrimSpace(resource.Agent.AgentID)+ if agent, ok := connectionByID[agentID]; ok && agent.Type == ConnectionTypeAgent {+ bucketFor(groupID).agentIDs = append(bucketFor(groupID).agentIDs, agentID)+ }+ }+ if resource.Proxmox != nil || resource.VMware != nil {+ continue+ }+ primaryID := primaryConnectionIDForResource(resource, hostIndex)+ if primaryID == "" {+ continue+ }+ primary, ok := connectionByID[primaryID]+ if !ok || primary.Type == ConnectionTypePVE || !isSingleHostPlatformConnectionType(primary.Type) {+ continue+ }+ bucketFor(groupID).primaries[primaryID] = struct{}{}+ }++ groupIDs := make([]string, 0, len(buckets))+ for groupID := range buckets {+ groupIDs = append(groupIDs, groupID)+ }+ sort.Strings(groupIDs)++ attachments := make([]identityGroupedAgentAttachment, 0)+ for _, groupID := range groupIDs {+ bucket := buckets[groupID]+ // A group naming more than one platform connection is ambiguous+ // evidence; fail closed the same way the direct host fallback does.+ if len(bucket.primaries) != 1 || len(bucket.agentIDs) == 0 {+ continue+ }+ var primaryID string+ for id := range bucket.primaries {+ primaryID = id+ }+ sort.Strings(bucket.agentIDs)+ for _, agentID := range bucket.agentIDs {+ attachments = append(attachments, identityGroupedAgentAttachment{+ agentID: agentID,+ primaryID: primaryID,+ })+ }+ }+ return attachments+}+func sortedConnectionsByID(connectionByID map[string]Connection) []Connection {connections := make([]Connection, 0, len(connectionByID))for _, connection := range connectionByID {@@ -745,11 +854,13 @@ func primaryConnectionIDForResource(}case resource.PBS != nil:if instanceID := strings.TrimSpace(resource.PBS.InstanceID); instanceID != "" {- return "pbs:" + instanceID+ // The PBS poller writes "pbs-<name>" instance IDs while+ // connection IDs carry the bare configured instance name.+ return "pbs:" + strings.TrimPrefix(instanceID, "pbs-")}case resource.PMG != nil:if instanceID := strings.TrimSpace(resource.PMG.InstanceID); instanceID != "" {- return "pmg:" + instanceID+ return "pmg:" + strings.TrimPrefix(instanceID, "pmg-")}}diff --git a/internal/api/connections_grouping_test.go b/internal/api/connections_grouping_test.goindex 5b55a419da..2fccef3c14 100644--- a/internal/api/connections_grouping_test.go+++ b/internal/api/connections_grouping_test.go@@ -538,6 +538,307 @@ func TestBuildConnectionSystems_AttachesHostAgentToMatchingProxmoxSourceWithoutN}}+// A PBS host running a Pulse agent must collapse into one "API + Agent" row+// the way PVE hosts do, even when the configured PBS address (an FQDN or+// DNS alias) shares no literal host string with anything the agent reports.+// The pairing comes from the shared top-level-system resolver, which holds+// short-form hostname equivalence — the same contract the Infrastructure+// surfaces already use to count these as one system.+func TestBuildConnectionSystems_AttachesHostAgentToPBSSourceByIdentityGrouping(t *testing.T) {+ cfg := &config.Config{DataPath: t.TempDir()}+ monitor, err := monitoring.New(cfg)+ if err != nil {+ t.Fatalf("monitoring.New: %v", err)+ }+ t.Cleanup(func() { monitor.Stop() })++ now := time.Date(2026, 8, 1, 9, 0, 0, 0, time.UTC)+ adapter := unified.NewMonitorAdapter(nil)+ adapter.PopulateSupplementalRecords(unified.SourcePBS, []unified.IngestRecord{+ {+ SourceID: "pbs-backup-01",+ Resource: unified.Resource{+ ID: "resource-pbs-backup-01",+ Type: unified.ResourceTypePBS,+ Name: "backup-01",+ Status: unified.StatusOnline,+ LastSeen: now,+ Sources: []unified.DataSource{unified.SourcePBS},+ Identity: unified.ResourceIdentity{+ Hostnames: []string{"pbs01.internal.example"},+ },+ PBS: &unified.PBSData{+ InstanceID: "pbs-backup-01",+ Hostname: "pbs01.internal.example",+ HostURL: "https://pbs01.internal.example:8007",+ },+ },+ },+ {+ SourceID: "pbs-backup-02",+ Resource: unified.Resource{+ ID: "resource-pbs-backup-02",+ Type: unified.ResourceTypePBS,+ Name: "backup-02",+ Status: unified.StatusOnline,+ LastSeen: now,+ Sources: []unified.DataSource{unified.SourcePBS},+ Identity: unified.ResourceIdentity{+ Hostnames: []string{"pbs02.internal.example"},+ },+ PBS: &unified.PBSData{+ InstanceID: "pbs-backup-02",+ Hostname: "pbs02.internal.example",+ HostURL: "https://pbs02.internal.example:8007",+ },+ },+ },+ })+ adapter.PopulateSupplementalRecords(unified.SourceAgent, []unified.IngestRecord{+ {+ SourceID: "agent-pbs01",+ Resource: unified.Resource{+ ID: "resource-agent-pbs01",+ Type: unified.ResourceTypeAgent,+ Name: "pbs01",+ Status: unified.StatusOnline,+ LastSeen: now,+ Sources: []unified.DataSource{unified.SourceAgent},+ Identity: unified.ResourceIdentity{+ MachineID: "machine-pbs01",+ Hostnames: []string{"pbs01"},+ },+ Agent: &unified.AgentData{+ AgentID: "agent-pbs01",+ Hostname: "pbs01",+ MachineID: "machine-pbs01",+ },+ },+ },+ {+ SourceID: "agent-pbs02",+ Resource: unified.Resource{+ ID: "resource-agent-pbs02",+ Type: unified.ResourceTypeAgent,+ Name: "pbs02",+ Status: unified.StatusOnline,+ LastSeen: now,+ Sources: []unified.DataSource{unified.SourceAgent},+ Identity: unified.ResourceIdentity{+ MachineID: "machine-pbs02",+ Hostnames: []string{"pbs02"},+ },+ Agent: &unified.AgentData{+ AgentID: "agent-pbs02",+ Hostname: "pbs02",+ MachineID: "machine-pbs02",+ },+ },+ },+ })+ setTestUnexportedField(t, monitor, "resourceStore", monitoring.ResourceStoreInterface(adapter))++ connections := []Connection{+ {+ ID: "pbs:backup-01",+ Type: ConnectionTypePBS,+ Name: "backup-01",+ Address: "https://pbs01.internal.example:8007",+ HostAliases: []string{"backup-01", "pbs01.internal.example"},+ State: ConnectionStateActive,+ Enabled: true,+ Surfaces: []string{"backups", "datastores"},+ Scope: map[string]bool{"backups": true, "datastores": true},+ Source: ConnectionSourceManual,+ Capabilities: ConnectionCapabilities{SupportsPause: true, SupportsScope: true, SupportsTest: true},+ },+ {+ ID: "pbs:backup-02",+ Type: ConnectionTypePBS,+ Name: "backup-02",+ Address: "https://pbs02.internal.example:8007",+ HostAliases: []string{"backup-02", "pbs02.internal.example"},+ State: ConnectionStateActive,+ Enabled: true,+ Surfaces: []string{"backups", "datastores"},+ Scope: map[string]bool{"backups": true, "datastores": true},+ Source: ConnectionSourceManual,+ Capabilities: ConnectionCapabilities{SupportsPause: true, SupportsScope: true, SupportsTest: true},+ },+ {+ ID: "agent:agent-pbs01",+ Type: ConnectionTypeAgent,+ Name: "pbs01",+ Address: "pbs01",+ HostAliases: []string{"pbs01", "192.168.40.11"},+ State: ConnectionStateActive,+ Enabled: true,+ Surfaces: []string{"host"},+ Scope: map[string]bool{"host": true},+ LastSeen: &now,+ Source: ConnectionSourceAgent,+ Capabilities: ConnectionCapabilities{SupportsPause: false, SupportsScope: false, SupportsTest: false},+ },+ {+ ID: "agent:agent-pbs02",+ Type: ConnectionTypeAgent,+ Name: "pbs02",+ Address: "pbs02",+ HostAliases: []string{"pbs02", "192.168.40.12"},+ State: ConnectionStateActive,+ Enabled: true,+ Surfaces: []string{"host"},+ Scope: map[string]bool{"host": true},+ LastSeen: &now,+ Source: ConnectionSourceAgent,+ Capabilities: ConnectionCapabilities{SupportsPause: false, SupportsScope: false, SupportsTest: false},+ },+ }++ systems := buildConnectionSystems(connections, monitor)+ if len(systems) != 2 {+ t.Fatalf("expected 2 grouped systems, got %d (%+v)", len(systems), systems)+ }++ systemsByID := make(map[string]ConnectionSystem, len(systems))+ for _, system := range systems {+ systemsByID[system.ID] = system+ }++ for pbsID, agentID := range map[string]string{+ "pbs:backup-01": "agent:agent-pbs01",+ "pbs:backup-02": "agent:agent-pbs02",+ } {+ system, ok := systemsByID[pbsID]+ if !ok {+ t.Fatalf("expected system %q, got %+v", pbsID, systems)+ }+ if len(system.Components) != 2 {+ t.Fatalf("%s: expected API and agent components, got %+v", pbsID, system.Components)+ }+ componentRoles := make(map[string]ConnectionSystemComponentRole, len(system.Components))+ for _, component := range system.Components {+ componentRoles[component.ConnectionID] = component.Role+ }+ if componentRoles[pbsID] != ConnectionSystemComponentRolePrimary {+ t.Fatalf("%s role = %q, want %q", pbsID, componentRoles[pbsID], ConnectionSystemComponentRolePrimary)+ }+ if componentRoles[agentID] != ConnectionSystemComponentRoleAttachment {+ t.Fatalf("%s role = %q, want %q", agentID, componentRoles[agentID], ConnectionSystemComponentRoleAttachment)+ }+ }+}++// The PMG poller writes "pmg-<name>" instance IDs the same way PBS does, so+// a PMG host running a Pulse agent gets the same identity-grouped pairing.+func TestBuildConnectionSystems_AttachesHostAgentToPMGSourceByIdentityGrouping(t *testing.T) {+ cfg := &config.Config{DataPath: t.TempDir()}+ monitor, err := monitoring.New(cfg)+ if err != nil {+ t.Fatalf("monitoring.New: %v", err)+ }+ t.Cleanup(func() { monitor.Stop() })++ now := time.Date(2026, 8, 1, 9, 30, 0, 0, time.UTC)+ adapter := unified.NewMonitorAdapter(nil)+ adapter.PopulateSupplementalRecords(unified.SourcePMG, []unified.IngestRecord{+ {+ SourceID: "pmg-mail-01",+ Resource: unified.Resource{+ ID: "resource-pmg-mail-01",+ Type: unified.ResourceTypePMG,+ Name: "mail-01",+ Status: unified.StatusOnline,+ LastSeen: now,+ Sources: []unified.DataSource{unified.SourcePMG},+ Identity: unified.ResourceIdentity{+ Hostnames: []string{"pmg01.internal.example"},+ },+ PMG: &unified.PMGData{+ InstanceID: "pmg-mail-01",+ Hostname: "pmg01.internal.example",+ HostURL: "https://pmg01.internal.example:8006",+ },+ },+ },+ })+ adapter.PopulateSupplementalRecords(unified.SourceAgent, []unified.IngestRecord{+ {+ SourceID: "agent-pmg01",+ Resource: unified.Resource{+ ID: "resource-agent-pmg01",+ Type: unified.ResourceTypeAgent,+ Name: "pmg01",+ Status: unified.StatusOnline,+ LastSeen: now,+ Sources: []unified.DataSource{unified.SourceAgent},+ Identity: unified.ResourceIdentity{+ MachineID: "machine-pmg01",+ Hostnames: []string{"pmg01"},+ },+ Agent: &unified.AgentData{+ AgentID: "agent-pmg01",+ Hostname: "pmg01",+ MachineID: "machine-pmg01",+ },+ },+ },+ })+ setTestUnexportedField(t, monitor, "resourceStore", monitoring.ResourceStoreInterface(adapter))++ connections := []Connection{+ {+ ID: "pmg:mail-01",+ Type: ConnectionTypePMG,+ Name: "mail-01",+ Address: "https://pmg01.internal.example:8006",+ HostAliases: []string{"mail-01", "pmg01.internal.example"},+ State: ConnectionStateActive,+ Enabled: true,+ Surfaces: []string{"mailStats", "queues"},+ Scope: map[string]bool{"mailStats": true, "queues": true},+ Source: ConnectionSourceManual,+ Capabilities: ConnectionCapabilities{SupportsPause: true, SupportsScope: true, SupportsTest: true},+ },+ {+ ID: "agent:agent-pmg01",+ Type: ConnectionTypeAgent,+ Name: "pmg01",+ Address: "pmg01",+ HostAliases: []string{"pmg01", "192.168.40.21"},+ State: ConnectionStateActive,+ Enabled: true,+ Surfaces: []string{"host"},+ Scope: map[string]bool{"host": true},+ LastSeen: &now,+ Source: ConnectionSourceAgent,+ Capabilities: ConnectionCapabilities{SupportsPause: false, SupportsScope: false, SupportsTest: false},+ },+ }++ systems := buildConnectionSystems(connections, monitor)+ if len(systems) != 1 {+ t.Fatalf("expected 1 grouped system, got %d (%+v)", len(systems), systems)+ }+ system := systems[0]+ if system.ID != "pmg:mail-01" {+ t.Fatalf("system id = %q, want %q", system.ID, "pmg:mail-01")+ }+ if len(system.Components) != 2 {+ t.Fatalf("expected API and agent components, got %+v", system.Components)+ }+ componentRoles := make(map[string]ConnectionSystemComponentRole, len(system.Components))+ for _, component := range system.Components {+ componentRoles[component.ConnectionID] = component.Role+ }+ if componentRoles["pmg:mail-01"] != ConnectionSystemComponentRolePrimary {+ t.Fatalf("pmg:mail-01 role = %q, want %q", componentRoles["pmg:mail-01"], ConnectionSystemComponentRolePrimary)+ }+ if componentRoles["agent:agent-pmg01"] != ConnectionSystemComponentRoleAttachment {+ t.Fatalf("agent:agent-pmg01 role = %q, want %q", componentRoles["agent:agent-pmg01"], ConnectionSystemComponentRoleAttachment)+ }+}+func TestDirectPlatformHostAttachmentSupportsSingleHostAPISources(t *testing.T) {tests := []struct {name string