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
fix: Docker agent token conflict on reconnect. Related to #1008
rcourtmanc654f1486d3b
diff --git a/internal/monitoring/docker_host_identity.go b/internal/monitoring/docker_host_identity.goindex 03f2426528..adfc6fba9c 100644--- a/internal/monitoring/docker_host_identity.go+++ b/internal/monitoring/docker_host_identity.go@@ -102,6 +102,17 @@ func findMatchingDockerHost(hosts []models.DockerHost, report agentsdocker.Repor}}+ // Fallback: match by Hostname and Token only (when MachineID is missing)+ // This fixes issues where containerized agents without persistent machine-id+ // reconnect with the same token but are treated as new agents.+ if hostname != "" && tokenID != "" {+ for _, host := range hosts {+ if strings.TrimSpace(host.Hostname) == hostname && strings.TrimSpace(host.TokenID) == tokenID {+ return host, true+ }+ }+ }+if machineID != "" && tokenID == "" {for _, host := range hosts {if strings.TrimSpace(host.MachineID) == machineID && strings.TrimSpace(host.TokenID) == "" {diff --git a/internal/monitoring/monitor_docker_test.go b/internal/monitoring/monitor_docker_test.goindex 5c12d445e6..9e6e515044 100644--- a/internal/monitoring/monitor_docker_test.go+++ b/internal/monitoring/monitor_docker_test.go@@ -870,3 +870,90 @@ func TestApplyDockerReport_MissingHostname(t *testing.T) {t.Errorf("expected 'missing hostname' in error message, got: %v", err)}}++func TestApplyDockerReport_ReconnectWithoutMachineID(t *testing.T) {+ monitor := newTestMonitor(t)++ // Report with NO AgentID and NO MachineID, but valid Hostname.+ // This simulates a containerized agent without persistent ID or machine-id mount.+ report := agentsdocker.Report{+ Agent: agentsdocker.AgentInfo{+ ID: "", // Empty AgentID+ Version: "1.0.0",+ IntervalSeconds: 30,+ },+ Host: agentsdocker.HostInfo{+ Hostname: "reconnect-host",+ MachineID: "", // Empty MachineID+ },+ Timestamp: time.Now().UTC(),+ }++ token := &config.APITokenRecord{ID: "token-reconnect", Name: "Test Token"}++ // First report - should succeed+ host1, err := monitor.ApplyDockerReport(report, token)+ if err != nil {+ t.Fatalf("First ApplyDockerReport failed: %v", err)+ }+ if host1.ID == "" {+ t.Fatal("First host has empty ID")+ }++ // Second report - identical to first+ // This must succeed by matching the existing host via Hostname + Token+ host2, err := monitor.ApplyDockerReport(report, token)+ if err != nil {+ t.Fatalf("Second ApplyDockerReport failed: %v", err)+ }++ // Verify that we matched the existing host instead of creating a new one+ if host1.ID != host2.ID {+ t.Errorf("Host IDs mismatch: %q vs %q - expected them to remain the same", host1.ID, host2.ID)+ }+}++func TestApplyDockerReport_SameHostnameDifferentTokens(t *testing.T) {+ monitor := newTestMonitor(t)++ // Two agents with the same hostname but different tokens should be treated as DIFFERENT hosts.+ // This tests that our Hostname+Token matching doesn't incorrectly merge unrelated agents.+ reportA := agentsdocker.Report{+ Agent: agentsdocker.AgentInfo{+ ID: "", // Empty AgentID+ Version: "1.0.0",+ IntervalSeconds: 30,+ },+ Host: agentsdocker.HostInfo{+ Hostname: "shared-hostname",+ MachineID: "", // Empty MachineID+ },+ Timestamp: time.Now().UTC(),+ }++ tokenA := &config.APITokenRecord{ID: "token-A", Name: "Token A"}+ tokenB := &config.APITokenRecord{ID: "token-B", Name: "Token B"}++ // Agent A reports first+ hostA, err := monitor.ApplyDockerReport(reportA, tokenA)+ if err != nil {+ t.Fatalf("Agent A report failed: %v", err)+ }++ // Agent B reports with same hostname but different token+ hostB, err := monitor.ApplyDockerReport(reportA, tokenB)+ if err != nil {+ t.Fatalf("Agent B report failed: %v", err)+ }++ // They should have DIFFERENT IDs since they use different tokens+ if hostA.ID == hostB.ID {+ t.Errorf("Hosts should have different IDs but both have %q", hostA.ID)+ }++ // Verify both hosts exist in state+ hosts := monitor.state.GetDockerHosts()+ if len(hosts) != 2 {+ t.Errorf("Expected 2 hosts in state, got %d", len(hosts))+ }+}