From b751280a430b6312cf52cf2129461ff31556ecb4 Mon Sep 17 00:00:00 2001 From: mkleger Date: Wed, 6 Aug 2025 14:30:04 +0200 Subject: [PATCH] Icons have been added to the title so that it is easier to distinguish between them, return value adjusted so that something is only output if there really is a problem. --- cmk/notification_plugins/msteams.py | 32 +++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/cmk/notification_plugins/msteams.py b/cmk/notification_plugins/msteams.py index 6526088cd02..c37e47dd601 100644 --- a/cmk/notification_plugins/msteams.py +++ b/cmk/notification_plugins/msteams.py @@ -30,11 +30,28 @@ "ACKNOWLEDGEMENT": "Problem acknowledged", } +EMOJIS: dict[str, str] = { + "OK": "🟢", + "UP": "🟢", + "WARNING": "🟡", + "CRITICAL": "🔴", + "DOWN": "🔴", + "UNKNOWN": "⚪", + "ACKNOWLEDGEMENT": "✅", + "DOWNTIMESTART": "🕒", + "DOWNTIMEEND": "🕒", + "DOWNTIMECANCELLED": "🕒", +} def _msteams_msg( context: PluginNotificationContext, ) -> dict[str, object]: title, summary, details, subtitle = _get_text_fields(context, notify_what := context["WHAT"]) + + state = context.get("SERVICESTATE", context.get("HOSTSTATE", "")) + emoji = EMOJIS.get(state, "") + title_with_emoji = f"{emoji} {substitute_context(title, context)}" + actions = [] if info_url := ( service_url_from_context(context) @@ -63,7 +80,7 @@ def _msteams_msg( "body": [ { "type": "TextBlock", - "text": substitute_context(title, context), + "text": title_with_emoji, "weight": "bolder", "size": "large", "style": "heading", @@ -171,6 +188,13 @@ def _get_section_facts(context: PluginNotificationContext) -> Iterable[dict[str, def main() -> int: - # 200: old webhooks (deprecated) - # 202: workflows - return process_by_status_code(post_request(_msteams_msg), (200, 202)) + try: + response = post_request(_msteams_msg) + if response.status_code in (200, 201, 202): + return 0 + else: + print(f"Error: Status {response.status_code} - Response: {response.text}") + return 1 + except Exception as e: + print(f"Exception while sending notification: {e}") + return 2