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.

Add periodic Proxmox registration health check loop

rcourtman40a25f82d16a
diff --git a/internal/hostagent/agent.go b/internal/hostagent/agent.go
index 048f67753b..1dd7965a12 100644
--- a/internal/hostagent/agent.go
+++ b/internal/hostagent/agent.go
@@ -382,6 +382,7 @@ func (a *Agent) Run(ctx context.Context) error {
// Proxmox setup (if enabled)
if a.cfg.EnableProxmox {
a.runProxmoxSetup(ctx)
+ go a.runProxmoxHealthCheckLoop(ctx)
}
// Start command client in background for AI command execution
@@ -1339,6 +1340,66 @@ func (a *Agent) runProxmoxSetup(ctx context.Context) {
}
}
+const (
+ proxmoxHealthCheckInitialDelay = 2 * time.Minute
+ proxmoxHealthCheckInterval = 5 * time.Minute
+)
+
+// runProxmoxHealthCheckLoop periodically verifies that Proxmox nodes registered
+// at startup are still connected to Pulse. This closes the cold-startup race
+// where the monitor may not have connection data at the time of the initial
+// registration check, causing a stale-token node to be silently skipped.
+func (a *Agent) runProxmoxHealthCheckLoop(ctx context.Context) {
+ // Wait for the monitor to build initial connection-health state before
+ // the first check so that a stale token is detectable.
+ select {
+ case <-ctx.Done():
+ return
+ case <-time.After(proxmoxHealthCheckInitialDelay):
+ }
+
+ ticker := time.NewTicker(proxmoxHealthCheckInterval)
+ defer ticker.Stop()
+
+ for {
+ select {
+ case <-ctx.Done():
+ return
+ case <-ticker.C:
+ setup := NewProxmoxSetup(
+ a.logger,
+ a.httpClient,
+ a.collector,
+ a.trimmedPulseURL,
+ a.cfg.APIToken,
+ a.cfg.ProxmoxType,
+ a.hostname,
+ a.reportIP,
+ a.stateDir,
+ a.cfg.InsecureSkipVerify,
+ )
+ results, err := setup.RunHealthCheck(ctx)
+ if err != nil {
+ a.logger.Warn().Err(err).Msg("Proxmox health check failed")
+ continue
+ }
+ for _, result := range results {
+ if result.Registered {
+ a.logger.Info().
+ Str("type", result.ProxmoxType).
+ Str("host", result.NodeHost).
+ Msg("Proxmox node re-registered via health check")
+ } else {
+ a.logger.Warn().
+ Str("type", result.ProxmoxType).
+ Str("host", result.NodeHost).
+ Msg("Proxmox health check: token rotated but registration failed")
+ }
+ }
+ }
+ }
+}
+
// isLXCContainer detects if we're running inside an LXC container.
// LXC containers share the host's /sys/class/dmi/id/product_uuid, which causes
// gopsutil to return identical HostIDs for all LXC containers on the same host.
diff --git a/internal/hostagent/proxmox_setup.go b/internal/hostagent/proxmox_setup.go
index d602f0cee6..5642864eb1 100644
--- a/internal/hostagent/proxmox_setup.go
+++ b/internal/hostagent/proxmox_setup.go
@@ -468,6 +468,69 @@ func (p *ProxmoxSetup) RunAll(ctx context.Context) ([]*ProxmoxSetupResult, error
return results, nil
}
+// RunHealthCheck verifies that every previously-registered Proxmox type is
+// still connected to Pulse. If a type's registration is confirmed stale by the
+// server (node exists in config but connection is broken), RunHealthCheck
+// re-registers it with a fresh token.
+//
+// Types with no local registration marker are intentionally skipped. Those
+// need a full RunAll cycle (typically at next agent startup) rather than a
+// health-check rotation, which would cause uncontrolled token churn if Pulse
+// is temporarily unreachable.
+func (p *ProxmoxSetup) RunHealthCheck(ctx context.Context) ([]*ProxmoxSetupResult, error) {
+ pulseURL, err := normalizePulseURL(p.pulseURL)
+ if err != nil {
+ return nil, fmt.Errorf("invalid pulse URL: %w", err)
+ }
+ p.pulseURL = pulseURL
+
+ forcedTypeStr, err := normalizeProxmoxType(string(p.proxmoxType))
+ if err != nil {
+ return nil, err
+ }
+ forcedType := proxmoxProductType(forcedTypeStr)
+
+ var typesToCheck []proxmoxProductType
+ if forcedType != "" {
+ typesToCheck = []proxmoxProductType{forcedType}
+ } else {
+ typesToCheck = p.detectProxmoxTypes()
+ }
+
+ var results []*ProxmoxSetupResult
+ for _, ptype := range typesToCheck {
+ // Skip types with no local marker — they need a full startup setup
+ // cycle, not a periodic health-check rotation.
+ if !p.isTypeRegistered(ptype) {
+ continue
+ }
+
+ hostURL := p.getHostURL(ctx, ptype)
+ registered, err := p.checkRegistrationWithPulse(ctx, ptype, hostURL)
+ if err != nil {
+ p.logger.Warn().Err(err).Str("type", string(ptype)).
+ Msg("Proxmox health check: could not verify registration with Pulse")
+ continue
+ }
+ if registered {
+ continue // still healthy
+ }
+
+ p.logger.Info().Str("type", string(ptype)).Str("host", hostURL).
+ Msg("Proxmox health check: node disconnected, re-registering")
+ result, err := p.runForType(ctx, ptype)
+ if err != nil {
+ p.logger.Error().Err(err).Str("type", string(ptype)).
+ Msg("Proxmox health check: re-registration failed")
+ continue
+ }
+ if result != nil {
+ results = append(results, result)
+ }
+ }
+ return results, nil
+}
+
// runForType executes setup for a specific Proxmox type.
func (p *ProxmoxSetup) runForType(ctx context.Context, ptype proxmoxProductType) (*ProxmoxSetupResult, error) {
normalizedTypeStr, err := normalizeProxmoxType(string(ptype))