Fix stale alerts for deleted agents on command deck

This commit is contained in:
AetherForge
2026-06-02 22:09:09 -07:00
parent 96f683a72a
commit 9407efd960
3 changed files with 35 additions and 0 deletions

View File

@@ -194,6 +194,30 @@ func (e *Evaluator) ActiveAlerts() []AlertEvent {
return out
}
// ClearAgent removes all in-memory alert state for a specific agent.
// Call this when an agent is deleted so stale alerts stop appearing on the
// dashboard for machines that no longer exist.
func (e *Evaluator) ClearAgent(agentID string) {
e.mu.Lock()
defer e.mu.Unlock()
// Remove cached alerts for this agent.
filtered := e.activeAlerts[:0]
for _, a := range e.activeAlerts {
if a.AgentID != agentID {
filtered = append(filtered, a)
}
}
e.activeAlerts = filtered
// Remove cooldown + baseline entries so the agent's next appearance
// (e.g. re-registration) starts fresh.
delete(e.baseline, agentID)
for k := range e.lastFired {
if len(k) > len(agentID) && k[len(k)-len(agentID):] == agentID {
delete(e.lastFired, k)
}
}
}
func formatPct(v float64) string {
if v < 0 {
v = 0