Skip to content

Commit

Permalink
Updated SIGNL4 Notification Plugin
Browse files Browse the repository at this point in the history
Updated SIGNL4 notification plugin for better support of service alerting and two-way status updates.

Change-Id: I93cbcc81971d8636c6ac67b296fa676cf3dcc0ea
  • Loading branch information
rons4 authored and makanakoeln committed Oct 30, 2023
1 parent 566052a commit f0d585e
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 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 @@ -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": "",
Expand All @@ -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,
}

Expand Down

0 comments on commit f0d585e

Please sign in to comment.