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.

Retain last-known platform on removed agents for scoped cleanup handoff

rcourtman671b1597113f
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.md
index 85ca5943d4..0c2185e5c5 100644
--- a/docs/release-control/v6/internal/subsystems/monitoring.md
+++ b/docs/release-control/v6/internal/subsystems/monitoring.md
@@ -1812,6 +1812,21 @@ platforms and unverified FreeBSD/pfSense installer state fail closed for
upgrade-command support. `internal/fleethealth/agent_test.go` and
`internal/monitoring/agent_fleet_doctor_test.go` are the focused runtime proofs.
+Removed-agent rows keep command-scoping identity instead of losing it with the
+live record: host and Docker removal capture the agent's last-known reported
+platform onto the removed record (`RemovedHostAgent.Platform`,
+`RemovedDockerHost.Platform`), and the fleet diagnostic resolves that retained
+value through the same strict platform normalization as live subjects, so
+`/api/agents/diagnostics` reports a platform for a removed agent only when its
+last live report identified one. A retained value that does not normalize to a
+known agent platform yields an empty diagnostic platform rather than a guess,
+and removed Kubernetes clusters retain no platform because the cluster report
+never carries one; downstream host-side cleanup handoffs must treat an empty
+platform as "offer explicitly labeled commands for every family, never one
+guessed executable". The retained field is additive and optional on the
+serialized removed lists, so snapshots recorded before the field existed load
+unchanged with an empty platform.
+
### Unified Agent destination delivery metrics
The local agent health listener exports
diff --git a/internal/models/models.go b/internal/models/models.go
index 4ecb59219d..7815d954d5 100644
--- a/internal/models/models.go
+++ b/internal/models/models.go
@@ -912,6 +912,7 @@ type RemovedDockerHost struct {
ID string `json:"id"`
Hostname string `json:"hostname,omitempty"`
DisplayName string `json:"displayName,omitempty"`
+ Platform string `json:"platform,omitempty"` // last-known reported platform, retained for host-side cleanup guidance
RemovedAt time.Time `json:"removedAt"`
}
@@ -920,6 +921,7 @@ type RemovedHostAgent struct {
ID string `json:"id"`
Hostname string `json:"hostname,omitempty"`
DisplayName string `json:"displayName,omitempty"`
+ Platform string `json:"platform,omitempty"` // last-known reported platform, retained for host-side cleanup guidance
MachineID string `json:"machineId,omitempty"`
TokenID string `json:"tokenId,omitempty"`
LinkedVMID string `json:"linkedVmId,omitempty"`
diff --git a/internal/monitoring/agent_fleet_doctor.go b/internal/monitoring/agent_fleet_doctor.go
index 4be8731342..ec57cd4f63 100644
--- a/internal/monitoring/agent_fleet_doctor.go
+++ b/internal/monitoring/agent_fleet_doctor.go
@@ -140,6 +140,7 @@ type agentFleetSubject struct {
kubernetes *models.KubernetesCluster
removed bool
removedAt time.Time
+ removedPlatform string // last-known reported platform retained on the removed record
}
// GetAgentFleetDiagnostics preserves the original call contract for callers
@@ -297,13 +298,14 @@ func buildAgentFleetSubjects(state models.StateSnapshot) []agentFleetSubject {
for i := range state.RemovedDockerHosts {
removed := state.RemovedDockerHosts[i]
subjectsByID["removed-docker:"+removed.ID] = &agentFleetSubject{
- rowKey: "removed-docker-" + removed.ID,
- id: removed.ID,
- name: firstNonEmpty(removed.DisplayName, removed.Hostname, removed.ID),
- hostname: removed.Hostname,
- types: map[string]struct{}{"docker": {}},
- removed: true,
- removedAt: removed.RemovedAt,
+ rowKey: "removed-docker-" + removed.ID,
+ id: removed.ID,
+ name: firstNonEmpty(removed.DisplayName, removed.Hostname, removed.ID),
+ hostname: removed.Hostname,
+ types: map[string]struct{}{"docker": {}},
+ removed: true,
+ removedAt: removed.RemovedAt,
+ removedPlatform: removed.Platform,
}
order = append(order, "removed-docker:"+removed.ID)
}
@@ -311,13 +313,14 @@ func buildAgentFleetSubjects(state models.StateSnapshot) []agentFleetSubject {
for i := range state.RemovedHostAgents {
removed := state.RemovedHostAgents[i]
subjectsByID["removed-host:"+removed.ID] = &agentFleetSubject{
- rowKey: "removed-host-" + removed.ID,
- id: removed.ID,
- name: firstNonEmpty(removed.DisplayName, removed.Hostname, removed.ID),
- hostname: removed.Hostname,
- types: map[string]struct{}{"host": {}},
- removed: true,
- removedAt: removed.RemovedAt,
+ rowKey: "removed-host-" + removed.ID,
+ id: removed.ID,
+ name: firstNonEmpty(removed.DisplayName, removed.Hostname, removed.ID),
+ hostname: removed.Hostname,
+ types: map[string]struct{}{"host": {}},
+ removed: true,
+ removedAt: removed.RemovedAt,
+ removedPlatform: removed.Platform,
}
order = append(order, "removed-host:"+removed.ID)
}
@@ -674,6 +677,13 @@ func agentFleetIdentityForSubject(subject agentFleetSubject) agentFleetIdentityE
interfaces = append(interfaces, docker.NetworkInterfaces...)
}
+ if identity.platform == "" && strings.TrimSpace(subject.removedPlatform) != "" {
+ // Removed subjects have no live host/docker record; resolve the
+ // platform retained on the removed record through the same strict
+ // normalization so downstream commands never scope from a guess.
+ identity.platform, _ = safeAgentUpdatePlatform(subject)
+ }
+
identity.machineIDFingerprint = machineIDFingerprint(machineID)
identity.interfaceAddresses = safeDiagnosticInterfaceAddresses(interfaces)
return identity
@@ -724,6 +734,7 @@ func safeAgentUpdatePlatform(subject agentFleetSubject) (string, bool) {
if subject.docker != nil {
values = append(values, subject.docker.OS)
}
+ values = append(values, subject.removedPlatform)
for _, value := range values {
appliance := strings.ToLower(strings.TrimSpace(value))
diff --git a/internal/monitoring/agent_fleet_doctor_test.go b/internal/monitoring/agent_fleet_doctor_test.go
index 4517663ce4..c9beb4b9a5 100644
--- a/internal/monitoring/agent_fleet_doctor_test.go
+++ b/internal/monitoring/agent_fleet_doctor_test.go
@@ -272,6 +272,71 @@ func TestAgentFleetDiagnosticsDetectsProfileVersionDrift(t *testing.T) {
}
}
+func TestAgentFleetDiagnosticsRetainPlatformForRemovedAgents(t *testing.T) {
+ now := time.Date(2026, 7, 22, 12, 0, 0, 0, time.UTC)
+ monitor := newAgentFleetDoctorTestMonitor(t)
+ monitor.removedDockerHosts = make(map[string]time.Time)
+ monitor.dockerTokenBindings = make(map[string]string)
+ monitor.dockerCommands = make(map[string]*dockerHostCommand)
+ monitor.dockerCommandIndex = make(map[string]string)
+
+ monitor.state.UpsertHost(models.Host{
+ ID: "removed-windows",
+ Hostname: "win-node",
+ Platform: "Microsoft Windows Server 2022",
+ Status: "online",
+ LastSeen: now.Add(-time.Minute),
+ })
+ monitor.state.UpsertHost(models.Host{
+ ID: "removed-unknown",
+ Hostname: "mystery-node",
+ Platform: "BeOS",
+ Status: "online",
+ LastSeen: now.Add(-time.Minute),
+ })
+ monitor.state.UpsertDockerHost(models.DockerHost{
+ ID: "removed-docker",
+ Hostname: "docker-node",
+ OS: "Ubuntu 22.04",
+ Status: "online",
+ LastSeen: now.Add(-time.Minute),
+ })
+
+ for _, hostID := range []string{"removed-windows", "removed-unknown"} {
+ if _, err := monitor.RemoveHostAgent(hostID); err != nil {
+ t.Fatalf("RemoveHostAgent(%s): %v", hostID, err)
+ }
+ }
+ if _, err := monitor.RemoveDockerHost("removed-docker"); err != nil {
+ t.Fatalf("RemoveDockerHost: %v", err)
+ }
+ monitor.state.AddRemovedKubernetesCluster(models.RemovedKubernetesCluster{
+ ID: "removed-k8s",
+ Name: "cluster",
+ RemovedAt: now,
+ })
+
+ diagnostics := monitor.GetAgentFleetDiagnostics("6.2.0", now)
+ tests := []struct {
+ rowKey string
+ wantPlatform string
+ }{
+ {rowKey: "removed-host-removed-windows", wantPlatform: platformsupport.RuntimePlatformWindows},
+ {rowKey: "removed-host-removed-unknown", wantPlatform: ""},
+ {rowKey: "removed-docker-removed-docker", wantPlatform: platformsupport.RuntimePlatformLinux},
+ {rowKey: "removed-k8s-removed-k8s", wantPlatform: ""},
+ }
+ for _, test := range tests {
+ agent := requireAgentDiagnostic(t, diagnostics, test.rowKey)
+ if agent.Status != AgentFleetStatusRemoved {
+ t.Fatalf("%s status = %q, want %q", test.rowKey, agent.Status, AgentFleetStatusRemoved)
+ }
+ if agent.Platform != test.wantPlatform {
+ t.Fatalf("%s platform = %q, want %q", test.rowKey, agent.Platform, test.wantPlatform)
+ }
+ }
+}
+
func newAgentFleetDoctorTestMonitor(t *testing.T) *Monitor {
t.Helper()
return &Monitor{
diff --git a/internal/monitoring/monitor_agents.go b/internal/monitoring/monitor_agents.go
index c46462bfa1..aa0cbc23eb 100644
--- a/internal/monitoring/monitor_agents.go
+++ b/internal/monitoring/monitor_agents.go
@@ -84,6 +84,7 @@ func (m *Monitor) RemoveDockerHost(hostID string) (models.DockerHost, error) {
ID: hostID,
Hostname: host.Hostname,
DisplayName: host.DisplayName,
+ Platform: host.OS,
RemovedAt: removedAt,
})
@@ -222,6 +223,7 @@ func (m *Monitor) RemoveHostAgent(hostID string) (models.Host, error) {
ID: hostID,
Hostname: host.Hostname,
DisplayName: host.DisplayName,
+ Platform: firstNonEmpty(host.Platform, host.OSName),
MachineID: host.MachineID,
TokenID: host.TokenID,
LinkedVMID: host.LinkedVMID,
diff --git a/internal/monitoring/monitor_host_agents_test.go b/internal/monitoring/monitor_host_agents_test.go
index bdbc6b941b..9cd33609bb 100644
--- a/internal/monitoring/monitor_host_agents_test.go
+++ b/internal/monitoring/monitor_host_agents_test.go
@@ -3858,3 +3858,46 @@ func TestHostFromReadStateViewMapsIntegrationSource(t *testing.T) {
t.Fatalf("agent-sourced host must map empty IntegrationSource, got %q", got)
}
}
+
+// Removal must retain the agent's last-known platform on the removed record so
+// the fleet doctor can still scope host-side cleanup commands after the live
+// host record is gone.
+func TestRemoveHostAgentRetainsLastKnownPlatform(t *testing.T) {
+ monitor := &Monitor{
+ state: models.NewState(),
+ config: &config.Config{},
+ }
+
+ now := time.Now().UTC()
+ monitor.state.UpsertHost(models.Host{
+ ID: "removed-platform-host",
+ Hostname: "win-node",
+ Platform: "Microsoft Windows Server 2022",
+ Status: "online",
+ LastSeen: now.Add(-time.Minute),
+ })
+ monitor.state.UpsertHost(models.Host{
+ ID: "removed-osname-host",
+ Hostname: "debian-node",
+ OSName: "Debian GNU/Linux",
+ Status: "online",
+ LastSeen: now.Add(-time.Minute),
+ })
+
+ for _, hostID := range []string{"removed-platform-host", "removed-osname-host"} {
+ if _, err := monitor.RemoveHostAgent(hostID); err != nil {
+ t.Fatalf("RemoveHostAgent(%s): %v", hostID, err)
+ }
+ }
+
+ got := make(map[string]string)
+ for _, entry := range monitor.state.GetRemovedHostAgents() {
+ got[entry.ID] = entry.Platform
+ }
+ if got["removed-platform-host"] != "Microsoft Windows Server 2022" {
+ t.Fatalf("removed record platform = %q, want last-known reported platform", got["removed-platform-host"])
+ }
+ if got["removed-osname-host"] != "Debian GNU/Linux" {
+ t.Fatalf("removed record platform = %q, want OS-name fallback when Platform was never reported", got["removed-osname-host"])
+ }
+}