adding ai summary - default is disabled

This commit is contained in:
2026-01-26 17:13:11 -06:00
parent 2820944ec6
commit 921b6a81a4
13 changed files with 1357 additions and 43 deletions

View File

@@ -3,6 +3,7 @@
from dataclasses import dataclass
from typing import Optional, Union
from app.models.ai_summary import SummaryNotification
from app.models.alerts import AggregatedAlert, AlertType, TriggeredAlert
from app.utils.http_client import HttpClient
from app.utils.logging_config import get_logger
@@ -20,6 +21,15 @@ class NotificationResult:
error: Optional[str] = None
@dataclass
class SummaryNotificationResult:
"""Result of sending a summary notification."""
summary: SummaryNotification
success: bool
error: Optional[str] = None
class NotificationServiceError(Exception):
"""Raised when notification service encounters an error."""
@@ -175,3 +185,54 @@ class NotificationService:
tags = list(self.ALERT_TYPE_TAGS.get(alert.alert_type, self.default_tags))
return tags
def send_summary(self, summary: SummaryNotification) -> SummaryNotificationResult:
"""Send an AI-generated summary notification.
Args:
summary: The summary notification to send.
Returns:
SummaryNotificationResult indicating success or failure.
"""
url = f"{self.server_url}/{self.topic}"
# Build headers
headers = {
"Title": summary.title,
"Priority": self.priority,
"Tags": ",".join(summary.tags),
}
if self.access_token:
headers["Authorization"] = f"Bearer {self.access_token}"
self.logger.debug(
"sending_summary_notification",
location=summary.location,
alert_count=summary.alert_count,
)
response = self.http_client.post(
url,
data=summary.message.encode("utf-8"),
headers=headers,
)
if response.success:
self.logger.info(
"summary_notification_sent",
location=summary.location,
alert_count=summary.alert_count,
has_changes=summary.has_changes,
)
return SummaryNotificationResult(summary=summary, success=True)
else:
error_msg = f"HTTP {response.status_code}: {response.text[:100]}"
self.logger.error(
"summary_notification_failed",
error=error_msg,
)
return SummaryNotificationResult(
summary=summary, success=False, error=error_msg
)