Fix stale alerts for deleted agents on command deck
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user