diff --git a/elementary/monitor/data_monitoring/alerts/integrations/teams/teams.py b/elementary/monitor/data_monitoring/alerts/integrations/teams/teams.py
index ba4fdceee..512ae89ab 100644
--- a/elementary/monitor/data_monitoring/alerts/integrations/teams/teams.py
+++ b/elementary/monitor/data_monitoring/alerts/integrations/teams/teams.py
@@ -1,6 +1,6 @@
import json
from datetime import datetime, timedelta
-from typing import Dict, List, Optional, Union
+from typing import Dict, List, Optional, Sequence, Union
import pandas as pd
from pymsteams import cardsection, potentialaction # type: ignore
@@ -520,6 +520,30 @@ def _get_group_by_table_template(
self._get_section("*Test errors*", f"{text}")
)
+ def _get_sub_group_detailed_section(
+ self,
+ alerts: Sequence[
+ Union[
+ TestAlertModel,
+ ModelAlertModel,
+ SourceFreshnessAlertModel,
+ GroupedByTableAlerts,
+ ],
+ ],
+ sub_title: str,
+ bullet_icon: str,
+ ) -> cardsection:
+ formatted_sub_title = f"*{sub_title}*"
+ rows = []
+ for alert in alerts:
+ row = f"{bullet_icon} {alert.summary}"
+ if report_link := alert.get_report_link():
+ link = f'{report_link.text}'
+ row = f"{row} - {link}"
+ rows.append(row)
+ text = "
".join(rows)
+ return self._get_section(formatted_sub_title, text)
+
def _get_alerts_group_template(self, alert: AlertsGroup, *args, **kwargs): # type: ignore[override]
title = f"{self._get_display_name(alert.status)}: {alert.summary}"
@@ -556,31 +580,39 @@ def _get_alerts_group_template(self, alert: AlertsGroup, *args, **kwargs): # ty
self.message_builder.text(subtitle)
if alert.model_errors:
- rows = [alert.summary for alert in alert.model_errors]
- text = "
".join([f"😵 {row}" for row in rows])
self.message_builder.addSection(
- self._get_section("*Model errors*", f"{text}")
+ self._get_sub_group_detailed_section(
+ alerts=alert.model_errors,
+ sub_title="Model errors",
+ bullet_icon="😵",
+ )
)
if alert.test_failures:
- rows = [alert.summary for alert in alert.test_failures]
- text = "
".join([f"🔺 {row}" for row in rows])
self.message_builder.addSection(
- self._get_section("*Test failures*", f"{text}")
+ self._get_sub_group_detailed_section(
+ alerts=alert.test_failures,
+ sub_title="Test failures",
+ bullet_icon="🔺",
+ )
)
if alert.test_warnings:
- rows = [alert.summary for alert in alert.test_warnings]
- text = "
".join([f"⚠ {row}" for row in rows])
self.message_builder.addSection(
- self._get_section("*Test warnings*", f"{text}")
+ self._get_sub_group_detailed_section(
+ alerts=alert.test_warnings,
+ sub_title="Test warnings",
+ bullet_icon="⚠",
+ )
)
if alert.test_errors:
- rows = [alert.summary for alert in alert.test_errors]
- text = "
".join([f"❗ {row}" for row in rows])
self.message_builder.addSection(
- self._get_section("*Test errors*", f"{text}")
+ self._get_sub_group_detailed_section(
+ alerts=alert.test_errors,
+ sub_title="Test errors",
+ bullet_icon="❗",
+ )
)
def _get_fallback_template(