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
Adopt the agent's preferred host when re-registering a matched node
rcourtmanf850099134b6
diff --git a/internal/api/config_setup_handlers.go b/internal/api/config_setup_handlers.goindex 84ac011e74..4c76c62054 100644--- a/internal/api/config_setup_handlers.go+++ b/internal/api/config_setup_handlers.go@@ -424,6 +424,22 @@ func canonicalAutoRegisterMatchMessage(reason string) string {return "Canonical auto-register matched existing node by " + reason}+// shouldPreserveExistingAutoRegisterHost reports whether an identity-matched+// node keeps its stored host on re-registration. The agent orders+// candidateHosts by preference, so an existing host that appears anywhere in+// that list was deliberately outranked by the selected host and is replaced.+// A host absent from the list is an admin-managed endpoint the agent cannot+// see; keep it.+func shouldPreserveExistingAutoRegisterHost(existingHost string, candidateHosts []string) bool {+ existing := strings.TrimSpace(existingHost)+ for _, candidate := range candidateHosts {+ if strings.EqualFold(strings.TrimSpace(candidate), existing) {+ return false+ }+ }+ return true+}+func canonicalAutoRegisterCompletionPayloadMessage() string {return "Incomplete canonical auto-register token completion payload"}@@ -1314,10 +1330,11 @@ func (h *ConfigHandlers) handleCanonicalAutoRegister(w http.ResponseWriter, r *h}if hostsShareResolvedIdentity(node.Host, host) {existingIndex = i- preserveHost = true+ preserveHost = shouldPreserveExistingAutoRegisterHost(node.Host, candidateHosts)log.Info().Str("existingHost", node.Host).Str("newHost", host).+ Bool("preserveHost", preserveHost).Str("type", "pve").Msg(canonicalAutoRegisterMatchMessage("resolved host identity"))break@@ -1391,10 +1408,11 @@ func (h *ConfigHandlers) handleCanonicalAutoRegister(w http.ResponseWriter, r *h}if hostsShareResolvedIdentity(node.Host, host) {existingIndex = i- preserveHost = true+ preserveHost = shouldPreserveExistingAutoRegisterHost(node.Host, candidateHosts)log.Info().Str("existingHost", node.Host).Str("newHost", host).+ Bool("preserveHost", preserveHost).Str("type", "pbs").Msg(canonicalAutoRegisterMatchMessage("resolved host identity"))breakdiff --git a/internal/api/config_setup_handlers_test.go b/internal/api/config_setup_handlers_test.gonew file mode 100644index 0000000000..f57d5c6741--- /dev/null+++ b/internal/api/config_setup_handlers_test.go@@ -0,0 +1,46 @@+package api++import "testing"++func TestShouldPreserveExistingAutoRegisterHost(t *testing.T) {+ tests := []struct {+ name string+ existingHost string+ candidateHosts []string+ want bool+ }{+ {+ name: "existing host outranked in candidate list is replaced",+ existingHost: "https://pve02:8006",+ candidateHosts: []string{"https://192.168.1.12:8006", "https://pve02:8006"},+ want: false,+ },+ {+ name: "existing host matches candidate case-insensitively",+ existingHost: "https://PVE02:8006",+ candidateHosts: []string{"https://192.168.1.12:8006", "https://pve02:8006"},+ want: false,+ },+ {+ name: "admin-managed host absent from candidates is preserved",+ existingHost: "https://pve02.internal.example.com:8006",+ candidateHosts: []string{"https://192.168.1.12:8006", "https://pve02:8006"},+ want: true,+ },+ {+ name: "empty candidate list preserves existing host",+ existingHost: "https://pve02:8006",+ candidateHosts: nil,+ want: true,+ },+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ if got := shouldPreserveExistingAutoRegisterHost(tt.existingHost, tt.candidateHosts); got != tt.want {+ t.Fatalf("shouldPreserveExistingAutoRegisterHost(%q, %v) = %v, want %v",+ tt.existingHost, tt.candidateHosts, got, tt.want)+ }+ })+ }+}