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
Preserve snapshots for guests missed by poll
rcourtman7a1352f1223c
diff --git a/internal/monitoring/monitor_backups.go b/internal/monitoring/monitor_backups.goindex 615e603209..657dbb93d3 100644--- a/internal/monitoring/monitor_backups.go+++ b/internal/monitoring/monitor_backups.go@@ -598,6 +598,16 @@ func (m *Monitor) pollGuestSnapshots(ctx context.Context, instanceName string, ccontainers = append(containers, containerFromReadStateView(ct))}+ previousSnapshots := make([]models.GuestSnapshot, 0)+ if m.state != nil {+ snapshot := m.state.GetSnapshot()+ for _, snap := range snapshot.PVEBackups.GuestSnapshots {+ if snap.Instance == instanceName {+ previousSnapshots = append(previousSnapshots, snap)+ }+ }+ }+guestKey := func(instance, node string, vmid int) string {if instance == node {return fmt.Sprintf("%s-%d", node, vmid)@@ -666,6 +676,7 @@ func (m *Monitor) pollGuestSnapshots(ctx context.Context, instanceName string, cvar allSnapshots []models.GuestSnapshotdeadlineExceeded := false+ polledGuestKeys := make(map[string]struct{})// Poll VM snapshotsfor _, vm := range vms {@@ -696,6 +707,7 @@ func (m *Monitor) pollGuestSnapshots(ctx context.Context, instanceName string, ccontinue}+ polledGuestKeys[guestKey(instanceName, vm.Node, vm.VMID)] = struct{}{}for _, snap := range snapshots {snapshot := models.GuestSnapshot{ID: fmt.Sprintf("%s-%s-%d-%s", instanceName, vm.Node, vm.VMID, snap.Name),@@ -714,19 +726,16 @@ func (m *Monitor) pollGuestSnapshots(ctx context.Context, instanceName string, c}}- if deadlineExceeded {- log.Warn().- Str("instance", instanceName).- Msg("Guest snapshot polling timed out before completing VM collection; retaining previous snapshots")- return- }-// Poll container snapshotsfor _, ct := range containers {// Skip templatesif ct.Template {continue}+ if snapshotCtx.Err() != nil {+ deadlineExceeded = true+ break+ }snapshots, err := client.GetContainerSnapshots(snapshotCtx, ct.Node, ct.VMID)if err != nil {@@ -743,7 +752,9 @@ func (m *Monitor) pollGuestSnapshots(ctx context.Context, instanceName string, c// API error 596 means snapshots not supported/available - this is expected for many containerserrStr := err.Error()if strings.Contains(errStr, "596") || strings.Contains(errStr, "not available") {- // Silently skip containers without snapshot support+ // Silently skip containers without snapshot support; treat+ // them as polled so stale unsupported snapshots are not kept.+ polledGuestKeys[guestKey(instanceName, ct.Node, ct.VMID)] = struct{}{}continue}// Log other errors at debug level@@ -756,6 +767,7 @@ func (m *Monitor) pollGuestSnapshots(ctx context.Context, instanceName string, ccontinue}+ polledGuestKeys[guestKey(instanceName, ct.Node, ct.VMID)] = struct{}{}for _, snap := range snapshots {snapshot := models.GuestSnapshot{ID: fmt.Sprintf("%s-%s-%d-%s", instanceName, ct.Node, ct.VMID, snap.Name),@@ -774,14 +786,29 @@ func (m *Monitor) pollGuestSnapshots(ctx context.Context, instanceName string, c}}- if deadlineExceeded || snapshotCtx.Err() != nil {+ carriedForward := 0+ for _, prev := range previousSnapshots {+ if _, polled := polledGuestKeys[guestKey(instanceName, prev.Node, prev.VMID)]; polled {+ continue+ }+ allSnapshots = append(allSnapshots, prev)+ carriedForward+++ }++ if deadlineExceeded {log.Warn().Str("instance", instanceName).- Msg("Guest snapshot polling timed out before completion; retaining previous snapshots")- return+ Int("freshlyPolled", len(polledGuestKeys)).+ Int("carriedForward", carriedForward).+ Msg("Guest snapshot polling timed out before completion; merged fresh results with previously-known snapshots for unpolled guests")+ } else if carriedForward > 0 {+ log.Debug().+ Str("instance", instanceName).+ Int("carriedForward", carriedForward).+ Msg("Guest snapshot polling completed; carried forward previous snapshots for guests with per-call errors")}- if len(allSnapshots) > 0 {+ if len(allSnapshots) > 0 && !deadlineExceeded {sizeMap := m.collectSnapshotSizes(snapshotCtx, instanceName, client, allSnapshots)if len(sizeMap) > 0 {for i := range allSnapshots {diff --git a/internal/monitoring/monitor_snapshot_test.go b/internal/monitoring/monitor_snapshot_test.goindex 1bd3c839d0..fcdadefdad 100644--- a/internal/monitoring/monitor_snapshot_test.go+++ b/internal/monitoring/monitor_snapshot_test.go@@ -85,3 +85,55 @@ func TestMonitor_PollGuestSnapshots_Coverage(t *testing.T) {// Should log warn and return (no change to state, but coverage of check)}++// TestMonitor_PollGuestSnapshots_PreservesPreviousOnPerVMError guards against+// #1437: when a per-VM snapshot fetch fails, the previously-known snapshots+// for that VM must be carried forward so they do not silently disappear.+// Successfully-polled VMs in the same cycle still get their fresh snapshots.+func TestMonitor_PollGuestSnapshots_PreservesPreviousOnPerVMError(t *testing.T) {+ m := &Monitor{state: models.NewState()}++ vms := []models.VM{+ {ID: "qemu/100", VMID: 100, Node: "node1", Instance: "pve1", Name: "vm100", Template: false},+ {ID: "qemu/999", VMID: 999, Node: "node1", Instance: "pve1", Name: "vm999-fail", Template: false},+ }+ m.state.UpdateVMsForInstance("pve1", vms)++ previous := []models.GuestSnapshot{+ {ID: "pve1-node1-100-snap_old", Name: "snap_old", Node: "node1", Instance: "pve1", Type: "qemu", VMID: 100, Time: time.Unix(1000, 0)},+ {ID: "pve1-node1-999-snap_persisted", Name: "snap_persisted", Node: "node1", Instance: "pve1", Type: "qemu", VMID: 999, Time: time.Unix(2000, 0)},+ }+ m.state.UpdateGuestSnapshotsForInstance("pve1", previous)++ client := &mockPVEClientSnapshots{+ snapshots: []proxmox.Snapshot{+ {Name: "snap_new", SnapTime: 3000, Description: "fresh"},+ },+ }++ m.pollGuestSnapshots(context.Background(), "pve1", client)++ got := m.state.GetSnapshot().PVEBackups.GuestSnapshots+ byName := make(map[string]models.GuestSnapshot, len(got))+ for _, snap := range got {+ byName[snap.Name] = snap+ }++ if _, oldStillThere := byName["snap_old"]; oldStillThere {+ t.Errorf("expected snap_old to be replaced by fresh poll, but it persisted")+ }+ if _, freshHere := byName["snap_new"]; !freshHere {+ t.Errorf("expected snap_new from fresh poll, got names=%v", keys(byName))+ }+ if _, persisted := byName["snap_persisted"]; !persisted {+ t.Errorf("expected snap_persisted to be carried forward after fetch failure, got names=%v", keys(byName))+ }+}++func keys[K comparable, V any](m map[K]V) []K {+ out := make([]K, 0, len(m))+ for k := range m {+ out = append(out, k)+ }+ return out+}