Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions cmk/notification_plugins/msteams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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