Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIGNL4 Notification Plugin Update #603

Closed
wants to merge 7 commits into from
Closed
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
41 changes: 33 additions & 8 deletions cmk/notification_plugins/signl4.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/env python3
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# SIGNL4 Alerting

# (c) 2020 Derdack GmbH - License: GNU Public License v2
# (c) 2023 Derdack GmbH - License: GNU Public License v2
# SIGNL4 <[email protected]>
# Reliable team alerting using SIGNL4.
# SIGNL4: Mobile alerting and incident response.

import base64
from os import environ

from cmk.notification_plugins.utils import post_request, process_by_result_map
Expand All @@ -24,24 +26,46 @@ def _signl4_url() -> str:


def _signl4_msg(context: dict[str, str]) -> dict[str, object]:
host_name = context["HOSTNAME"]
rons4 marked this conversation as resolved.
Show resolved Hide resolved
notification_type = context["NOTIFICATIONTYPE"]
rons4 marked this conversation as resolved.
Show resolved Hide resolved
host_name = context.get("HOSTNAME", "")
service_desc = context.get("SERVICEDESC", "")
host_state = ""
notification_type = context.get("NOTIFICATIONTYPE", "")
host_problem_id = context.get("HOSTPROBLEMID", "")
service_problem_id = context.get("SERVICEPROBLEMID", "")
description = f"{notification_type} on {host_name}"

# Prepare description information
if context.get("WHAT", "") == "SERVICE":
if notification_type in ["PROBLEM", "RECOVERY"]:
description += " (" + service_desc + ")"
else:
description += " (" + service_desc + ")"
else:
if notification_type in ["PROBLEM", "RECOVERY"]:
host_state = context.get("HOSTSTATE", "") or ""
description += " (" + host_state + ")"
else:
description += " (" + host_state + ")"
# Remove placeholder "$SERVICEPROBLEMID$" if exists
if service_problem_id.find("$") != -1:
service_problem_id = ""

# Check if this is a new problem or a recovery
s4_status = "new" if notification_type != "RECOVERY" else "resolved"

# Base64 encode the SERVICEDESC for matching updates for service alerts
makanakoeln marked this conversation as resolved.
Show resolved Hide resolved
service_desc = context.get("SERVICEDESC", "")
service_desc_base64 = ""
service_desc_id_part = ""
if len(service_desc) > 0:
service_desc_bytes = service_desc.encode("ascii")
service_desc_base64 = base64.b64encode(service_desc_bytes).decode()
service_desc_id_part = ":ServiceDesc:" + service_desc_base64
return {
"Title": f"{notification_type} on {host_name}",
"Title": description,
"HostName": host_name,
"NotificationType": notification_type,
"ServiceState": context.get("SERVICESTATE", ""),
"ServiceDescription": context.get("SERVICEDESC", ""),
"ServiceDescription": service_desc,
"ServiceOutput": context.get("SERVICEOUTPUT", ""),
"HostState": context.get("HOSTSTATE", ""),
"NotificationComment": "",
Expand All @@ -58,7 +82,8 @@ def _signl4_msg(context: dict[str, str]) -> dict[str, object]:
+ "-"
+ host_problem_id
+ "-"
+ service_problem_id,
+ service_problem_id
+ service_desc_id_part,
"X-S4-Status": s4_status,
}

Expand Down