display and acknowledge alerts

This commit is contained in:
Andreas Wrede
2026-04-03 06:35:45 -04:00
parent c5770006f7
commit 941f3ea4b0
6 changed files with 414 additions and 62 deletions
+22
View File
@@ -56,6 +56,8 @@ class AlertState:
self.threshold_value = None # The threshold value that triggered alert
self.operator = None # The comparison operator (>, <, >=, etc.)
self.formatted_message = None # Formatted display message for UI
self.acknowledged = False # Whether alert has been acknowledged
self.acknowledged_at = None # Timestamp when acknowledged
def update(
self,
@@ -101,6 +103,11 @@ class AlertState:
self.level = level
self.since = now
self.notification_count = 0
# Reset acknowledgment on state change
if level != AlertLevel.OK:
# Only reset if changing to a different alert level
self.acknowledged = False
self.acknowledged_at = None
return True
return False
@@ -114,8 +121,13 @@ class AlertState:
"last_value": self.last_value,
"last_check": self.last_check,
"notification_count": self.notification_count,
"acknowledged": self.acknowledged,
}
# Include acknowledgment timestamp if acknowledged
if self.acknowledged_at is not None:
result["acknowledged_at"] = self.acknowledged_at
# Include threshold info if available
if self.threshold_value is not None:
result["threshold_value"] = self.threshold_value
@@ -125,6 +137,12 @@ class AlertState:
result["formatted_message"] = self.formatted_message
return result
def acknowledge(self):
"""Acknowledge this alert to stop reminder notifications."""
self.acknowledged = True
self.acknowledged_at = time.time()
logger.info("Alert acknowledged for %s", self.metric_path)
def __str__(self):
return self.to_dict().__str__()
@@ -1014,6 +1032,10 @@ class ThresholdChecker:
if alert_state.level == AlertLevel.OK:
return
# Skip reminders if alert has been acknowledged
if alert_state.acknowledged:
return
now = time.time()
# Check if we should re-notify