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 alert history duration and re-evaluation threshold bugs

rcourtmanb5373749dbe3
diff --git a/internal/alerts/alerts.go b/internal/alerts/alerts.go
index 7ca5db7f54..1d925712b3 100644
--- a/internal/alerts/alerts.go
+++ b/internal/alerts/alerts.go
@@ -1746,6 +1746,18 @@ func (m *Manager) reevaluateActiveAlertsLocked() {
alertsToResolve = append(alertsToResolve, alertID)
continue
}
+ thresholds := m.config.HostDefaults
+ // Overrides are keyed by raw host ID (without the "host:" prefix
+ // that hostResourceID adds to the resource ID used in alert IDs).
+ rawHostID := strings.TrimPrefix(resourceID, "host:")
+ if override, exists := m.config.Overrides[rawHostID]; exists {
+ if override.Disabled {
+ alertsToResolve = append(alertsToResolve, alertID)
+ continue
+ }
+ thresholds = m.applyThresholdOverride(thresholds, override)
+ }
+ threshold = getThresholdForMetric(thresholds, metricType)
}
if alert.Type == "docker-host-offline" ||
@@ -1835,7 +1847,7 @@ func (m *Manager) reevaluateActiveAlertsLocked() {
alertsToResolve = append(alertsToResolve, alertID)
continue
}
- thresholds := m.config.NodeDefaults
+ thresholds := m.config.PBSDefaults
if override, exists := m.config.Overrides[resourceID]; exists {
if override.CPU != nil && metricType == "cpu" {
threshold = ensureHysteresisThreshold(override.CPU)
@@ -6661,6 +6673,11 @@ func (m *Manager) preserveAlertState(alertID string, updated *Alert) {
}
func (m *Manager) removeActiveAlertNoLock(alertID string) {
+ // Before deleting, update the history entry with the alert's final LastSeen
+ // timestamp so the stored duration reflects how long the alert was actually active.
+ if alert, exists := m.activeAlerts[alertID]; exists && alert != nil {
+ m.historyManager.UpdateAlertLastSeen(alertID, alert.LastSeen)
+ }
delete(m.activeAlerts, alertID)
// NOTE: Don't delete ackState here - preserve it so if the same alert
// reappears (e.g., powered-off VM during backup), the acknowledgement
diff --git a/internal/alerts/history.go b/internal/alerts/history.go
index c79a47de0a..cdd9a3c8fa 100644
--- a/internal/alerts/history.go
+++ b/internal/alerts/history.go
@@ -107,6 +107,23 @@ func (hm *HistoryManager) AddAlert(alert Alert) {
}
}
+// UpdateAlertLastSeen updates the LastSeen timestamp on the most recent
+// history entry matching the given alert ID. This is called when an alert is
+// resolved so that the stored history reflects the true duration of the alert,
+// not just the snapshot captured at creation time.
+func (hm *HistoryManager) UpdateAlertLastSeen(alertID string, lastSeen time.Time) {
+ hm.mu.Lock()
+ defer hm.mu.Unlock()
+
+ // Iterate from newest to oldest to find the most recent entry for this alert
+ for i := len(hm.history) - 1; i >= 0; i-- {
+ if hm.history[i].Alert.ID == alertID {
+ hm.history[i].Alert.LastSeen = lastSeen
+ return
+ }
+ }
+}
+
// GetHistory returns alert history within the specified time range
func (hm *HistoryManager) GetHistory(since time.Time, limit int) []Alert {
hm.mu.RLock()