feat(CORE-001D3B): surface alert history degraded state
This commit is contained in:
@@ -8,6 +8,12 @@ from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
|
||||
class AlertHistoryLoadError(RuntimeError):
|
||||
def __init__(self, history_path: Path, message: str) -> None:
|
||||
super().__init__(message)
|
||||
self.history_path = history_path
|
||||
|
||||
|
||||
@dataclass
|
||||
class AlertEvent:
|
||||
severity: str
|
||||
@@ -36,6 +42,8 @@ class AlertStatus:
|
||||
critical_threshold: float
|
||||
email_alerts_enabled: bool
|
||||
history: list[AlertEvent]
|
||||
history_unavailable: bool = False
|
||||
history_notice: str | None = None
|
||||
|
||||
|
||||
class AlertHistoryRepository:
|
||||
@@ -53,10 +61,12 @@ class AlertHistoryRepository:
|
||||
try:
|
||||
with self.history_path.open() as f:
|
||||
data = json.load(f)
|
||||
except (json.JSONDecodeError, OSError):
|
||||
return []
|
||||
except json.JSONDecodeError as exc:
|
||||
raise AlertHistoryLoadError(self.history_path, f"Alert history is not valid JSON: {exc}") from exc
|
||||
except OSError as exc:
|
||||
raise AlertHistoryLoadError(self.history_path, f"Alert history could not be read: {exc}") from exc
|
||||
if not isinstance(data, list):
|
||||
return []
|
||||
raise AlertHistoryLoadError(self.history_path, "Alert history payload must be a list")
|
||||
return [AlertEvent.from_dict(item) for item in data if isinstance(item, dict)]
|
||||
|
||||
def save(self, events: list[AlertEvent]) -> None:
|
||||
|
||||
Reference in New Issue
Block a user