From 1383430da0c0e6b13258b2302d79f107c72b0e2f Mon Sep 17 00:00:00 2001 From: Eric Loyd Date: Mon, 28 Aug 2023 11:47:29 -0400 Subject: [PATCH] Adding notify-by-ntfy.sh to send things through personal EWG server --- notify-by-ntfy.sh | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 notify-by-ntfy.sh diff --git a/notify-by-ntfy.sh b/notify-by-ntfy.sh new file mode 100644 index 0000000..c7b2c6d --- /dev/null +++ b/notify-by-ntfy.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +notify_host="https://notify.everwatch.global" +channel="EWG" +alertType="" +msgTitle="" +message="" +tag="exclamation" +priority="3" +state="" + +case "$NAGIOS_NOTIFICATIONTYPE" in + PROBLEM) tag="bangbang";; + RECOVERY) tag="ok";; + ACKNOWLEDGEMENT) tag="ok_hand";; + FLAPPINGSTART) tag="hatched_chick";; + FLAPPINGSTOP) tag="hourglass_flowing_sand";; + DOWNTIMESTART) tag="sleeping_bed";; + DOWNTIMEEND) tag="sunny";; + *) tag="exclamation";; +esac + +do_notify() { + [ -n "$1" ] && channel="${channel}-${1}" + curl -s \ + -H "Title: ${msgTitle}" \ + -H "Tags: ${tag}" \ + -H "Priority: ${priority}" \ + -d "${message}" \ + ${notify_host}/${channel} +} + +do_host() { + msgTitle="HOST ${NAGIOS_NOTIFICATIONTYPE}" + message="$NAGIOS_NOTIFICATIONTYPE $NAGIOS_HOSTNAME is $NAGIOS_HOSTSTATE $NAGIOS_LONGDATETIME" + do_notify "Hosts" +} + +do_service() { + msgTitle="SERVICE ${NAGIOS_NOTIFICATIONTYPE}" + message="$NAGIOS_NOTIFICATIONTYPE $NAGIOS_SERVICEDESC @ $NAGIOS_HOSTALIAS is $NAGIOS_SERVICESTATE $NAGIOS_LONGDATETIME" + do_notify "Services" +} + +while [ -n "$1" ]; do + case "$1" in + -t|--type) alertType="$2"; shift 2;; + *) shift 1;; + esac +done + +case "$alertType" in + h|host|host) do_host;; + s|svc|service) do_service;; + *) shift 1;; +esac + +exit