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 PVE stale token self-healing after failed registration

rcourtman501c61b82fef
diff --git a/internal/api/config_setup_handlers.go b/internal/api/config_setup_handlers.go
index 224b45e054..6d22f99f91 100644
--- a/internal/api/config_setup_handlers.go
+++ b/internal/api/config_setup_handlers.go
@@ -479,16 +479,32 @@ func (h *ConfigHandlers) autoRegisteredNodeExists(ctx context.Context, req *Auto
return false
}
+ // Snapshot connection statuses once; nil if monitor not available yet.
+ var connStatuses map[string]bool
+ if m := h.getMonitor(ctx); m != nil {
+ connStatuses = m.GetConnectionStatuses()
+ }
+
switch req.Type {
case "pve":
for _, node := range h.getConfig(ctx).PVEInstances {
if autoRegisterHostMatchesCandidates(node.Host, candidates) {
+ // Node exists in config. If the monitor has definitively confirmed
+ // it is disconnected (stale token), allow re-registration so the
+ // agent can update the token. Default to "registered" when there
+ // is no monitor status yet (e.g. startup race).
+ if isKnownDisconnected(connStatuses, "pve", node.Name, node.Host) {
+ return false
+ }
return true
}
}
case "pbs":
for _, node := range h.getConfig(ctx).PBSInstances {
if autoRegisterHostMatchesCandidates(node.Host, candidates) {
+ if isKnownDisconnected(connStatuses, "pbs", node.Name, node.Host) {
+ return false
+ }
return true
}
}
@@ -497,6 +513,26 @@ func (h *ConfigHandlers) autoRegisteredNodeExists(ctx context.Context, req *Auto
return false
}
+// isKnownDisconnected reports whether the monitor has a definitive "unhealthy"
+// entry for the given instance. Returns false (i.e., assume connected) when
+// there is no monitor data yet so we don't mistakenly trigger re-registration
+// on every cold startup before the monitor has had a chance to poll.
+func isKnownDisconnected(connStatuses map[string]bool, instanceType, name, host string) bool {
+ if connStatuses == nil {
+ return false
+ }
+ instanceName := strings.TrimSpace(name)
+ if instanceName == "" {
+ instanceName = strings.TrimSpace(host)
+ }
+ if instanceName == "" {
+ return false
+ }
+ key := instanceType + "-" + instanceName
+ connected, known := connStatuses[key]
+ return known && !connected
+}
+
func buildCanonicalAutoRegisterResponse(req *AutoRegisterRequest, host string, actualName string, tokenID string, tokenValue string) AutoRegisterResponse {
nodeName := canonicalAutoRegisterNodeIdentity(req, actualName, host)
return AutoRegisterResponse{
diff --git a/internal/hostagent/proxmox_setup.go b/internal/hostagent/proxmox_setup.go
index a78a3db8f3..d602f0cee6 100644
--- a/internal/hostagent/proxmox_setup.go
+++ b/internal/hostagent/proxmox_setup.go
@@ -10,6 +10,7 @@ import (
"net"
"net/http"
"net/url"
+ "os"
"path/filepath"
"regexp"
"strings"
@@ -498,6 +499,11 @@ func (p *ProxmoxSetup) runForType(ctx context.Context, ptype proxmoxProductType)
p.logger.Info().Str("type", string(ptype)).Msg("Setting up Proxmox type")
+ // Clear the registration marker before token operations so that a failed
+ // Pulse update (rotation succeeds but registration fails) leaves the system
+ // retriable on the next startup rather than stuck on a stale state file.
+ p.clearTypeRegisteredMarker(ptype)
+
// Create monitoring user and token
tokenID, tokenValue, err := p.setupToken(ctx, ptype)
if err != nil {
@@ -1522,3 +1528,13 @@ func (p *ProxmoxSetup) markTypeAsRegistered(ptype proxmoxProductType) {
p.logger.Warn().Err(err).Str("type", string(ptype)).Msg("Failed to enforce type state file permissions")
}
}
+
+// clearTypeRegisteredMarker removes the registration state file for a specific
+// Proxmox type. Called before token rotation so that a failed Pulse update
+// leaves the system in a retriable state rather than silently stale.
+func (p *ProxmoxSetup) clearTypeRegisteredMarker(ptype proxmoxProductType) {
+ stateFile := p.stateFileForType(ptype)
+ if err := os.Remove(stateFile); err != nil && !os.IsNotExist(err) {
+ p.logger.Warn().Err(err).Str("type", string(ptype)).Msg("Failed to clear type registration marker")
+ }
+}