"""Message formatting for Zulip notifications.""" from typing import Union from .models import AlertNotification, ReachabilityNotification class ZulipMessageFormatter: """Format Netdata notifications for Zulip messages.""" def format_alert(self, alert: AlertNotification) -> tuple[str, str]: """Format alert notification for Zulip. Returns: Tuple of (topic, message_content) """ topic = alert.severity.value # Severity emoji mapping severity_emoji = { "critical": "🔴", "warning": "âš ī¸", "clear": "✅" } emoji = severity_emoji.get(alert.severity.value, "📊") message = f"""{emoji} **{alert.alert}** **Space:** {alert.space} **Chart:** {alert.chart} **Context:** {alert.context} **Severity:** {alert.severity.value.title()} **Time:** {alert.date.strftime('%Y-%m-%d %H:%M:%S UTC')} **Details:** {alert.info} **Summary:** {alert.message} [View Alert]({alert.alert_url})""" return topic, message def format_reachability(self, notification: ReachabilityNotification) -> tuple[str, str]: """Format reachability notification for Zulip. Returns: Tuple of (topic, message_content) """ topic = "reachability" status_emoji = "✅" if notification.status.reachable else "❌" severity_emoji = "🔴" if notification.severity.value == "critical" else "â„šī¸" message = f"""{severity_emoji} **Host {notification.status.text.title()}** **Host:** {notification.host} **Status:** {status_emoji} {notification.status.text.title()} **Severity:** {notification.severity.value.title()} **Summary:** {notification.message} [View Host]({notification.url})""" return topic, message def format_notification(self, notification: Union[AlertNotification, ReachabilityNotification]) -> tuple[str, str]: """Format any notification type for Zulip. Returns: Tuple of (topic, message_content) """ if isinstance(notification, AlertNotification): return self.format_alert(notification) elif isinstance(notification, ReachabilityNotification): return self.format_reachability(notification) else: raise ValueError(f"Unknown notification type: {type(notification)}")