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: allow duplicate hostnames for different Proxmox hosts. Related to #891

rcourtman92988ae0e6e3
diff --git a/cmd/pulse-agent/main.go b/cmd/pulse-agent/main.go
index c4a1aa2398..47efa53928 100644
--- a/cmd/pulse-agent/main.go
+++ b/cmd/pulse-agent/main.go
@@ -134,6 +134,7 @@ func main() {
Logger: &logger,
EnableProxmox: cfg.EnableProxmox,
ProxmoxType: cfg.ProxmoxType,
+ DisableCommands: cfg.DisableCommands,
}
agent, err := hostagent.New(hostCfg)
@@ -347,6 +348,9 @@ type Config struct {
// Auto-update
DisableAutoUpdate bool
+ // Security
+ DisableCommands bool // Disable command execution for AI auto-fix
+
// Health/metrics server
HealthAddr string
@@ -376,6 +380,7 @@ func loadConfig() Config {
envEnableProxmox := utils.GetenvTrim("PULSE_ENABLE_PROXMOX")
envProxmoxType := utils.GetenvTrim("PULSE_PROXMOX_TYPE")
envDisableAutoUpdate := utils.GetenvTrim("PULSE_DISABLE_AUTO_UPDATE")
+ envDisableCommands := utils.GetenvTrim("PULSE_DISABLE_COMMANDS")
envHealthAddr := utils.GetenvTrim("PULSE_HEALTH_ADDR")
envKubeconfig := utils.GetenvTrim("PULSE_KUBECONFIG")
envKubeContext := utils.GetenvTrim("PULSE_KUBE_CONTEXT")
@@ -433,6 +438,7 @@ func loadConfig() Config {
enableProxmoxFlag := flag.Bool("enable-proxmox", defaultEnableProxmox, "Enable Proxmox mode (creates API token, registers node)")
proxmoxTypeFlag := flag.String("proxmox-type", envProxmoxType, "Proxmox type: pve or pbs (auto-detected if not specified)")
disableAutoUpdateFlag := flag.Bool("disable-auto-update", utils.ParseBool(envDisableAutoUpdate), "Disable automatic updates")
+ disableCommandsFlag := flag.Bool("disable-commands", utils.ParseBool(envDisableCommands), "Disable command execution for AI auto-fix")
healthAddrFlag := flag.String("health-addr", defaultHealthAddr, "Health/metrics server address (empty to disable)")
kubeconfigFlag := flag.String("kubeconfig", envKubeconfig, "Path to kubeconfig (optional; uses in-cluster config if available)")
kubeContextFlag := flag.String("kube-context", envKubeContext, "Kubeconfig context (optional)")
@@ -502,6 +508,7 @@ func loadConfig() Config {
EnableProxmox: *enableProxmoxFlag,
ProxmoxType: strings.TrimSpace(*proxmoxTypeFlag),
DisableAutoUpdate: *disableAutoUpdateFlag,
+ DisableCommands: *disableCommandsFlag,
HealthAddr: strings.TrimSpace(*healthAddrFlag),
KubeconfigPath: strings.TrimSpace(*kubeconfigFlag),
KubeContext: strings.TrimSpace(*kubeContextFlag),
diff --git a/internal/api/config_handlers.go b/internal/api/config_handlers.go
index c33eaa5cbc..146a40aa91 100644
--- a/internal/api/config_handlers.go
+++ b/internal/api/config_handlers.go
@@ -1175,6 +1175,47 @@ func normalizeNodeHost(rawHost, nodeType string) (string, error) {
return parsed.String(), nil
}
+// disambiguateNodeName ensures a node name is unique by appending the host IP if needed.
+// This handles cases where multiple Proxmox hosts have the same hostname (e.g., "px1" on different networks).
+// Returns the original name if unique, or "name (ip)" if duplicates exist.
+func (h *ConfigHandlers) disambiguateNodeName(name, host, nodeType string) string {
+ if name == "" {
+ return name
+ }
+
+ // Check if any existing node has the same name
+ hasDuplicate := false
+ if nodeType == "pve" {
+ for _, node := range h.config.PVEInstances {
+ if strings.EqualFold(node.Name, name) && node.Host != host {
+ hasDuplicate = true
+ break
+ }
+ }
+ } else if nodeType == "pbs" {
+ for _, node := range h.config.PBSInstances {
+ if strings.EqualFold(node.Name, name) && node.Host != host {
+ hasDuplicate = true
+ break
+ }
+ }
+ }
+
+ if !hasDuplicate {
+ return name
+ }
+
+ // Extract IP/hostname from host URL for disambiguation
+ parsed, err := url.Parse(host)
+ if err != nil || parsed.Host == "" {
+ // Fallback: use a short hash of the host
+ return fmt.Sprintf("%s (%s)", name, host[:min(15, len(host))])
+ }
+
+ hostname := parsed.Hostname()
+ return fmt.Sprintf("%s (%s)", name, hostname)
+}
+
// HandleAddNode adds a new node
func (h *ConfigHandlers) HandleAddNode(w http.ResponseWriter, r *http.Request) {
// Prevent node modifications in mock mode
@@ -5848,8 +5889,11 @@ func (h *ConfigHandlers) HandleAutoRegister(w http.ResponseWriter, r *http.Reque
MonitorGarbageJobs: &boolFalse,
}
- // Check if a node with this host or name already exists
- // Match by host URL or by node name (to handle hostname vs IP differences)
+ // Check if a node with this host already exists
+ // IMPORTANT: Only match by Host URL, NOT by name!
+ // Different physical hosts can have the same hostname (e.g., "px1" on different networks).
+ // Matching by name caused duplicate hostnames to be collapsed into one entry.
+ // See: Issue #891, #104, and multiple fix attempts in Dec 2025.
existingIndex := -1
if req.Type == "pve" {
for i, node := range h.config.PVEInstances {
@@ -5857,11 +5901,6 @@ func (h *ConfigHandlers) HandleAutoRegister(w http.ResponseWriter, r *http.Reque
existingIndex = i
break
}
- // Also match by name if ServerName matches existing node name
- if req.ServerName != "" && strings.EqualFold(node.Name, req.ServerName) {
- existingIndex = i
- break
- }
}
} else {
for i, node := range h.config.PBSInstances {
@@ -5869,11 +5908,6 @@ func (h *ConfigHandlers) HandleAutoRegister(w http.ResponseWriter, r *http.Reque
existingIndex = i
break
}
- // Also match by name if ServerName matches existing node name
- if req.ServerName != "" && strings.EqualFold(node.Name, req.ServerName) {
- existingIndex = i
- break
- }
}
}
@@ -6021,8 +6055,11 @@ func (h *ConfigHandlers) HandleAutoRegister(w http.ResponseWriter, r *http.Reque
monitorBackups = *nodeConfig.MonitorBackups
}
+ // Disambiguate node name if duplicate hostnames exist
+ displayName := h.disambiguateNodeName(nodeConfig.Name, nodeConfig.Host, "pve")
+
newInstance := config.PVEInstance{
- Name: nodeConfig.Name,
+ Name: displayName,
Host: nodeConfig.Host,
TokenName: nodeConfig.TokenName,
TokenValue: nodeConfig.TokenValue,
@@ -6070,8 +6107,11 @@ func (h *ConfigHandlers) HandleAutoRegister(w http.ResponseWriter, r *http.Reque
monitorGarbageJobs = *nodeConfig.MonitorGarbageJobs
}
+ // Disambiguate node name if duplicate hostnames exist
+ pbsDisplayName := h.disambiguateNodeName(nodeConfig.Name, nodeConfig.Host, "pbs")
+
newInstance := config.PBSInstance{
- Name: nodeConfig.Name,
+ Name: pbsDisplayName,
Host: nodeConfig.Host,
TokenName: nodeConfig.TokenName,
TokenValue: nodeConfig.TokenValue,
diff --git a/internal/api/config_handlers_auto_register_test.go b/internal/api/config_handlers_auto_register_test.go
index 4291801242..e055c39b2e 100644
--- a/internal/api/config_handlers_auto_register_test.go
+++ b/internal/api/config_handlers_auto_register_test.go
@@ -108,3 +108,159 @@ func TestHandleAutoRegisterAcceptsWithSetupToken(t *testing.T) {
t.Fatalf("expected 1 PVE instance stored, got %d", len(cfg.PVEInstances))
}
}
+
+// TestDisambiguateNodeName verifies that duplicate hostnames get disambiguated
+// with their IP address appended. Issue #891.
+func TestDisambiguateNodeName(t *testing.T) {
+ tempDir := t.TempDir()
+ t.Setenv("PULSE_DATA_DIR", tempDir)
+
+ cfg := &config.Config{
+ DataPath: tempDir,
+ ConfigPath: tempDir,
+ PVEInstances: []config.PVEInstance{
+ {Name: "px1", Host: "https://10.0.1.100:8006"},
+ },
+ }
+
+ handler := newTestConfigHandlers(t, cfg)
+
+ tests := []struct {
+ name string
+ nodeName string
+ host string
+ nodeType string
+ want string
+ }{
+ {
+ name: "unique name unchanged",
+ nodeName: "px2",
+ host: "https://10.0.2.200:8006",
+ nodeType: "pve",
+ want: "px2", // No disambiguation needed
+ },
+ {
+ name: "duplicate name gets IP appended",
+ nodeName: "px1",
+ host: "https://10.0.2.224:8006",
+ nodeType: "pve",
+ want: "px1 (10.0.2.224)", // Disambiguated with IP
+ },
+ {
+ name: "same host same name is not duplicate",
+ nodeName: "px1",
+ host: "https://10.0.1.100:8006", // Same host as existing
+ nodeType: "pve",
+ want: "px1", // Same host = same node, no disambiguation
+ },
+ {
+ name: "empty name unchanged",
+ nodeName: "",
+ host: "https://10.0.3.100:8006",
+ nodeType: "pve",
+ want: "",
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := handler.disambiguateNodeName(tt.nodeName, tt.host, tt.nodeType)
+ if got != tt.want {
+ t.Errorf("disambiguateNodeName() = %q, want %q", got, tt.want)
+ }
+ })
+ }
+}
+
+// TestAutoRegisterDuplicateHostnameSeparateNodes verifies that two Proxmox hosts
+// with the same hostname but different IPs are stored as separate nodes.
+// This is a regression test for Issue #891.
+func TestAutoRegisterDuplicateHostnameSeparateNodes(t *testing.T) {
+ tempDir := t.TempDir()
+ t.Setenv("PULSE_DATA_DIR", tempDir)
+
+ cfg := &config.Config{
+ DataPath: tempDir,
+ ConfigPath: tempDir,
+ }
+
+ handler := newTestConfigHandlers(t, cfg)
+
+ // Create setup token
+ const tokenValue = "TEMP-TOKEN"
+ tokenHash := internalauth.HashAPIToken(tokenValue)
+
+ // Register first node "px1" at 10.0.1.100
+ handler.codeMutex.Lock()
+ handler.setupCodes[tokenHash] = &SetupCode{
+ ExpiresAt: time.Now().Add(5 * time.Minute),
+ NodeType: "pve",
+ }
+ handler.codeMutex.Unlock()
+
+ reqBody1 := AutoRegisterRequest{
+ Type: "pve",
+ Host: "https://10.0.1.100:8006",
+ TokenID: "pulse-monitor@pam!token1",
+ TokenValue: "secret-token-1",
+ ServerName: "px1",
+ AuthToken: tokenValue,
+ }
+
+ body1, _ := json.Marshal(reqBody1)
+ req1 := httptest.NewRequest(http.MethodPost, "/api/auto-register", bytes.NewReader(body1))
+ rec1 := httptest.NewRecorder()
+ handler.HandleAutoRegister(rec1, req1)
+
+ if rec1.Code != http.StatusOK {
+ t.Fatalf("first registration failed: status=%d, body=%s", rec1.Code, rec1.Body.String())
+ }
+
+ // Register second node "px1" at 10.0.2.224 (same hostname, different host)
+ handler.codeMutex.Lock()
+ handler.setupCodes[tokenHash] = &SetupCode{
+ ExpiresAt: time.Now().Add(5 * time.Minute),
+ NodeType: "pve",
+ }
+ handler.codeMutex.Unlock()
+
+ reqBody2 := AutoRegisterRequest{
+ Type: "pve",
+ Host: "https://10.0.2.224:8006",
+ TokenID: "pulse-monitor@pam!token2",
+ TokenValue: "secret-token-2",
+ ServerName: "px1", // Same hostname as first node
+ AuthToken: tokenValue,
+ }
+
+ body2, _ := json.Marshal(reqBody2)
+ req2 := httptest.NewRequest(http.MethodPost, "/api/auto-register", bytes.NewReader(body2))
+ rec2 := httptest.NewRecorder()
+ handler.HandleAutoRegister(rec2, req2)
+
+ if rec2.Code != http.StatusOK {
+ t.Fatalf("second registration failed: status=%d, body=%s", rec2.Code, rec2.Body.String())
+ }
+
+ // Verify we have TWO separate nodes (regression test for Issue #891)
+ if len(cfg.PVEInstances) != 2 {
+ t.Fatalf("expected 2 PVE instances, got %d (duplicate hostnames were incorrectly merged!)", len(cfg.PVEInstances))
+ }
+
+ // Verify the names are disambiguated
+ node1 := cfg.PVEInstances[0]
+ node2 := cfg.PVEInstances[1]
+
+ if node1.Host == node2.Host {
+ t.Error("both nodes have the same host - they should be different!")
+ }
+
+ // First node should keep original name, second should be disambiguated
+ if node1.Name != "px1" {
+ t.Errorf("first node name = %q, want %q", node1.Name, "px1")
+ }
+
+ if node2.Name != "px1 (10.0.2.224)" {
+ t.Errorf("second node name = %q, want %q (should be disambiguated)", node2.Name, "px1 (10.0.2.224)")
+ }
+}
diff --git a/internal/hostagent/agent.go b/internal/hostagent/agent.go
index 99ef748751..5c4e40c2e2 100644
--- a/internal/hostagent/agent.go
+++ b/internal/hostagent/agent.go
@@ -44,6 +44,9 @@ type Config struct {
// Proxmox integration
EnableProxmox bool // If true, creates Proxmox API token and registers node on startup
ProxmoxType string // "pve", "pbs", or "" for auto-detect
+
+ // Security options
+ DisableCommands bool // If true, disables the command execution feature (AI auto-fix)
}
// Agent is responsible for collecting host metrics and shipping them to Pulse.
@@ -224,8 +227,12 @@ func New(cfg Config) (*Agent, error) {
reportBuffer: buffer.New[agentshost.Report](bufferCapacity),
}
- // Create command client for AI command execution
- agent.commandClient = NewCommandClient(cfg, agentID, hostname, platform, agentVersion)
+ // Create command client for AI command execution (unless disabled)
+ if !cfg.DisableCommands {
+ agent.commandClient = NewCommandClient(cfg, agentID, hostname, platform, agentVersion)
+ } else {
+ cfg.Logger.Info().Msg("Command execution disabled via --disable-commands flag")
+ }
return agent, nil
}