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
Match structured PBS comments to guest backup badges
pulse-triage[bot]5b249fb30782
diff --git a/internal/models/issue2292_backup_age_test.go b/internal/models/issue2292_backup_age_test.goindex ad4993e674..df3409c794 100644--- a/internal/models/issue2292_backup_age_test.go+++ b/internal/models/issue2292_backup_age_test.go@@ -216,3 +216,94 @@ func TestSyncGuestBackupTimesNewestPBSBackupSameNodeCollision(t *testing.T) {})}}++// The reported notes template changed from "pulse" to "pdm21.21008.pulse".+// Root has no namespace placement, so a colliding CT ID needs the complete+// node/VMID/name comment to identify which PVE connection owns the newer row.+func TestSyncGuestBackupTimesNodeVMIDNameCommentForUniqueCT(t *testing.T) {+ now := time.Now()+ recent := now.Add(-10 * time.Hour)+ state := NewState()+ state.UpdateContainers([]Container{+ {VMID: 21008, Name: "pulse", Instance: "cluster-a", Node: "pdm21"},+ })+ state.mu.Lock()+ state.PBSBackups = []PBSBackup{+ {ID: "old", VMID: "21008", BackupType: "ct", BackupTime: now.Add(-29 * 24 * time.Hour),+ Instance: "pbs-main", Comment: "pulse"},+ {ID: "recent", VMID: "21008", BackupType: "ct", BackupTime: recent,+ Instance: "pbs-main", Comment: "pdm21.21008.pulse"},+ }+ state.mu.Unlock()++ state.SyncGuestBackupTimes()+ if got := state.GetSnapshot().Containers[0].LastBackup; !got.Equal(recent) {+ t.Errorf("unique CT LastBackup = %v, want newer Root snapshot %v", got, recent)+ }+}++func TestSyncGuestBackupTimesNodeVMIDNameCommentForCollidingCT(t *testing.T) {+ now := time.Now()+ old := now.Add(-29 * 24 * time.Hour)+ recent := now.Add(-10 * time.Hour)+ other := now.Add(-2 * time.Hour)++ state := NewState()+ state.UpdateContainers([]Container{+ {VMID: 21008, Name: "pulse", Instance: "cluster-a", Node: "pdm21"},+ {VMID: 21008, Name: "other", Instance: "cluster-b", Node: "pdm22"},+ })+ state.mu.Lock()+ state.PBSBackups = []PBSBackup{+ {ID: "old", VMID: "21008", BackupType: "ct", BackupTime: old,+ Instance: "pbs-main", Comment: "pulse"},+ {ID: "recent", VMID: "21008", BackupType: "ct", BackupTime: recent,+ Instance: "pbs-main", Comment: "pdm21.21008.pulse"},+ // An unmarked newer root snapshot is still unsafe to assign to either CT.+ {ID: "unknown", VMID: "21008", BackupType: "ct", BackupTime: other,+ Instance: "pbs-unattributed"},+ {ID: "running", VMID: "21008", BackupType: "ct", BackupTime: now,+ Instance: "pbs-main", Comment: "pdm21.21008.pulse", InProgress: true},+ }+ state.mu.Unlock()++ state.SyncGuestBackupTimes()+ for _, guest := range state.GetSnapshot().Containers {+ switch guest.Instance {+ case "cluster-a":+ if !guest.LastBackup.Equal(recent) || !guest.BackupInProgress {+ t.Errorf("cluster-a LastBackup/running = %v/%v, want %v/true", guest.LastBackup, guest.BackupInProgress, recent)+ }+ case "cluster-b":+ if !guest.LastBackup.IsZero() || guest.BackupInProgress {+ t.Errorf("cluster-b inherited another CT's backup: %v/%v", guest.LastBackup, guest.BackupInProgress)+ }+ }+ }+}++// A matching node/VMID/name comment is still insufficient when two distinct+// connections host an indistinguishable CT. The #1639 collision guard wins.+func TestSyncGuestBackupTimesNodeVMIDNameCommentTieStaysUnattributed(t *testing.T) {+ now := time.Now()+ state := NewState()+ state.UpdateContainers([]Container{+ {VMID: 21008, Name: "pulse", Instance: "cluster-a", Node: "pdm21"},+ {VMID: 21008, Name: "pulse", Instance: "cluster-b", Node: "pdm21"},+ })+ state.mu.Lock()+ state.PBSBackups = []PBSBackup{+ {ID: "tied", VMID: "21008", BackupType: "ct", BackupTime: now.Add(-10 * time.Hour),+ Instance: "pbs-main", Comment: "pdm21.21008.pulse"},+ {ID: "running-tied", VMID: "21008", BackupType: "ct", BackupTime: now,+ Instance: "pbs-main", Comment: "pdm21.21008.pulse", InProgress: true},+ }+ state.mu.Unlock()++ state.SyncGuestBackupTimes()+ for _, guest := range state.GetSnapshot().Containers {+ if !guest.LastBackup.IsZero() || guest.BackupInProgress {+ t.Errorf("%s inherited tied CT backup: %v/%v", guest.Instance, guest.LastBackup, guest.BackupInProgress)+ }+ }+}diff --git a/internal/proxmoxidentity/backup_identity.go b/internal/proxmoxidentity/backup_identity.goindex 113a11d1cc..68b38c5ada 100644--- a/internal/proxmoxidentity/backup_identity.go+++ b/internal/proxmoxidentity/backup_identity.go@@ -81,9 +81,24 @@ func BackupCommentMatchesGuestName(comment, vmid, guestName string) bool {return subjectName != "" && guestName != "" && subjectName == guestName}+// backupCommentMatchesNodeVMIDName recognises a PVE notes template such as+// "pdm21.21008.pulse" only when all three fields match this guest. The node+// must match exactly: suffix or name-only matching could attribute a Root PBS+// snapshot to the wrong PVE connection when CT IDs collide (#2292, #1639).+func backupCommentMatchesNodeVMIDName(comment, vmid, guestName, nodeName string) bool {+ vmid = strings.TrimSpace(vmid)+ guestName = strings.TrimSpace(guestName)+ nodeName = strings.TrimSpace(nodeName)+ if vmid == "" || guestName == "" || nodeName == "" {+ return false+ }+ return strings.EqualFold(strings.TrimSpace(comment), nodeName+"."+vmid+"."+guestName)+}+func BackupGuestMatchScore(namespace, comment, vmid, guestName, instanceName, nodeName string) int {score := NamespaceLocationScore(namespace, instanceName, nodeName) * 10- if BackupCommentMatchesGuestName(comment, vmid, guestName) {+ if BackupCommentMatchesGuestName(comment, vmid, guestName) ||+ backupCommentMatchesNodeVMIDName(comment, vmid, guestName, nodeName) {score += 5}return scorediff --git a/internal/proxmoxidentity/backup_identity_test.go b/internal/proxmoxidentity/backup_identity_test.goindex 8311e0404c..d09185dc41 100644--- a/internal/proxmoxidentity/backup_identity_test.go+++ b/internal/proxmoxidentity/backup_identity_test.go@@ -70,6 +70,30 @@ func TestBackupGuestMatchScoreRanksNodeMatchAboveClusterEntrypoint(t *testing.T)}}+func TestBackupGuestMatchScoreNodeVMIDNameComment(t *testing.T) {+ const comment = "pdm21.21008.pulse"+ if got := BackupGuestMatchScore("", comment, "21008", "pulse", "cluster-a", "pdm21"); got <= 0 {+ t.Fatalf("matching node.VMID.name comment score = %d, want positive", got)+ }+ for _, tc := range []struct {+ name, vmid, guestName, node string+ }{+ {"other node", "21008", "pulse", "pdm22"},+ {"other VMID", "21009", "pulse", "pdm21"},+ {"other name", "21008", "other", "pdm21"},+ {"empty node", "21008", "pulse", ""},+ } {+ t.Run(tc.name, func(t *testing.T) {+ if got := BackupGuestMatchScore("", comment, tc.vmid, tc.guestName, "cluster-a", tc.node); got != 0 {+ t.Fatalf("mismatched node.VMID.name comment score = %d, want zero", got)+ }+ })+ }+ if got := BackupGuestMatchScore("", "other.pdm21.21008.pulse", "21008", "pulse", "cluster-a", "pdm21"); got != 0 {+ t.Fatalf("prefixed comment score = %d, want zero", got)+ }+}+func TestLocationLabelsEqualRequiresExactNormalizedMatch(t *testing.T) {if !LocationLabelsEqual("pve-nat", "PVE Nat") {t.Fatal("normalized identical labels should match")