-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated SIGNL4 notification plugin for better support of service alerting and two-way status updates. Change-Id: I93cbcc81971d8636c6ac67b296fa676cf3dcc0ea
- Loading branch information
1 parent
566052a
commit f0d585e
Showing
1 changed file
with
30 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -25,23 +27,44 @@ def _signl4_url() -> str: | |
|
||
def _signl4_msg(context: dict[str, str]) -> dict[str, object]: | ||
host_name = context["HOSTNAME"] | ||
service_desc = context.get("SERVICEDESC", "") | ||
host_state = "" | ||
notification_type = context["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 | ||
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": "", | ||
|
@@ -58,7 +81,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, | ||
} | ||
|
||
|