Skip to content

armgit / Pulse

Public Imported from GitHub
0

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.

fix(backups): prevent template backups from being flagged as orphaned

rcourtman2fe22c3308a6
diff --git a/internal/models/models.go b/internal/models/models.go
index b38db4b39e..94b8a5a8b6 100644
--- a/internal/models/models.go
+++ b/internal/models/models.go
@@ -40,6 +40,9 @@ type State struct {
LastUpdate time.Time `json:"lastUpdate"`
TemperatureMonitoringEnabled bool `json:"temperatureMonitoringEnabled"`
PVETagColors map[string]string `json:"pveTagColors,omitempty"`
+ // templateVMIDs tracks Proxmox template VMIDs (not shown in UI, used for backup orphan detection).
+ // Unexported so it is never serialised to JSON or the API.
+ templateVMIDs map[string]map[int]string // instance -> VMID -> node
}
// Alert represents an active alert (simplified for State)
@@ -3062,6 +3065,23 @@ func (s *State) GetContainers() []Container {
return containers
}
+// UpdateTemplateVMIDsForInstance stores the VMID→node mapping for Proxmox template guests
+// for a given instance. Templates are excluded from the main VM/container lists (they are not
+// monitored) but must be known to the backup orphan-detection logic so their backups are not
+// incorrectly flagged as orphaned. Pass nil or an empty map to clear the instance's entries.
+func (s *State) UpdateTemplateVMIDsForInstance(instance string, vmids map[int]string) {
+ s.mu.Lock()
+ defer s.mu.Unlock()
+ if s.templateVMIDs == nil {
+ s.templateVMIDs = make(map[string]map[int]string)
+ }
+ if len(vmids) == 0 {
+ delete(s.templateVMIDs, instance)
+ } else {
+ s.templateVMIDs[instance] = vmids
+ }
+}
+
// UpdateContainerDockerStatus updates the Docker detection status for a specific container.
func (s *State) UpdateContainerDockerStatus(containerID string, hasDocker bool, checkedAt time.Time) bool {
s.mu.Lock()
diff --git a/internal/models/state_snapshot.go b/internal/models/state_snapshot.go
index f121ef0215..518f28afdd 100644
--- a/internal/models/state_snapshot.go
+++ b/internal/models/state_snapshot.go
@@ -32,6 +32,9 @@ type StateSnapshot struct {
LastUpdate time.Time `json:"lastUpdate"`
TemperatureMonitoringEnabled bool `json:"temperatureMonitoringEnabled"`
PVETagColors map[string]string `json:"pveTagColors,omitempty"`
+ // TemplateVMIDs holds Proxmox template VMID→node mappings per instance.
+ // Not serialised to JSON or the frontend API; used only for backup orphan detection.
+ TemplateVMIDs map[string]map[int]string `json:"-"`
}
// GetSnapshot returns a snapshot of the current state without mutex
@@ -92,6 +95,16 @@ func (s *State) GetSnapshot() StateSnapshot {
snapshot.PVETagColors[k] = v
}
}
+ if len(s.templateVMIDs) > 0 {
+ snapshot.TemplateVMIDs = make(map[string]map[int]string, len(s.templateVMIDs))
+ for instance, vmids := range s.templateVMIDs {
+ vmap := make(map[int]string, len(vmids))
+ for vmid, node := range vmids {
+ vmap[vmid] = node
+ }
+ snapshot.TemplateVMIDs[instance] = vmap
+ }
+ }
return snapshot
}
diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go
index af697fdce4..a0d555b9f5 100644
--- a/internal/monitoring/monitor.go
+++ b/internal/monitoring/monitor.go
@@ -7254,6 +7254,7 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam
var allVMs []models.VM
var allContainers []models.Container
+ templateNodeMap := make(map[int]string) // VMID -> node, for template backup orphan detection
for _, res := range resources {
// Generate canonical guest ID: instance:node:vmid
@@ -7279,8 +7280,10 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam
var osName, osVersion, agentVersion string
if res.Type == "qemu" {
- // Skip templates if configured
+ // Skip templates — they are not monitored but track their VMID→node so backup
+ // orphan detection does not flag backups of templates as orphaned.
if res.Template == 1 {
+ templateNodeMap[res.VMID] = res.Node
continue
}
@@ -8000,8 +8003,9 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam
m.alertManager.CheckGuest(vm, instanceName)
} else if res.Type == "lxc" {
- // Skip templates if configured
+ // Skip templates — same rationale as qemu above.
if res.Template == 1 {
+ templateNodeMap[res.VMID] = res.Node
continue
}
@@ -8240,7 +8244,7 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam
Int("prevContainers", prevContainerCount).
Msg("Cluster returned zero resources but had resources before - likely cluster health issue, preserving all previous resources")
- // Preserve all previous VMs and containers for this instance
+ // Preserve all previous VMs, containers, and template VMIDs for this instance
for _, vm := range prevState.VMs {
if vm.Instance == instanceName {
allVMs = append(allVMs, vm)
@@ -8251,6 +8255,11 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam
allContainers = append(allContainers, container)
}
}
+ if prevTemplates, ok := prevState.TemplateVMIDs[instanceName]; ok {
+ for vmid, node := range prevTemplates {
+ templateNodeMap[vmid] = node
+ }
+ }
}
// Check for nodes that are within grace period but not in cluster/resources response
@@ -8323,6 +8332,7 @@ func (m *Monitor) pollVMsAndContainersEfficient(ctx context.Context, instanceNam
// Always update state when using efficient polling path
// Even if arrays are empty, we need to update to clear out VMs from genuinely offline nodes
m.state.UpdateVMsForInstance(instanceName, allVMs)
+ m.state.UpdateTemplateVMIDsForInstance(instanceName, templateNodeMap)
// Check Docker presence for containers that need it (new, restarted, started)
allContainers = m.CheckContainersForDocker(ctx, allContainers)
@@ -9976,6 +9986,14 @@ func (m *Monitor) pollStorageBackupsWithNodes(ctx context.Context, instanceName
guestNodeMap[ct.VMID] = ct.Node
}
}
+ // Also map template VMIDs so backup node assignment is correct for template backups.
+ if templates, ok := snapshot.TemplateVMIDs[instanceName]; ok {
+ for vmid, node := range templates {
+ if _, exists := guestNodeMap[vmid]; !exists {
+ guestNodeMap[vmid] = node
+ }
+ }
+ }
// For each node, get storage and check content
for _, node := range nodes {
@@ -10396,6 +10414,26 @@ func buildGuestLookups(snapshot models.StateSnapshot, metadataStore *config.Gues
enrichWithPersistedMetadata(metadataStore, byVMID)
}
+ // Add template VMIDs so the backup orphan-detection check does not flag backups of
+ // existing templates as orphaned. Templates are excluded from the main VM/container
+ // lists (they are not monitored), so without this they would appear as unknown guests.
+ for instance, vmids := range snapshot.TemplateVMIDs {
+ for vmid, node := range vmids {
+ info := alerts.GuestLookup{
+ ResourceID: makeGuestID(instance, node, vmid),
+ Instance: instance,
+ Node: node,
+ VMID: vmid,
+ }
+ key := alerts.BuildGuestKey(instance, node, vmid)
+ if _, exists := byKey[key]; !exists {
+ byKey[key] = info
+ }
+ vmidKey := strconv.Itoa(vmid)
+ byVMID[vmidKey] = append(byVMID[vmidKey], info)
+ }
+ }
+
return byKey, byVMID
}
@@ -10981,6 +11019,7 @@ func (m *Monitor) removeFailedPVENode(instanceName string) {
// Remove all other resources associated with this instance
m.state.UpdateVMsForInstance(instanceName, []models.VM{})
+ m.state.UpdateTemplateVMIDsForInstance(instanceName, nil)
m.state.UpdateContainersForInstance(instanceName, []models.Container{})
m.state.UpdateStorageForInstance(instanceName, []models.Storage{})
m.state.UpdateCephClustersForInstance(instanceName, []models.CephCluster{})