You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.3 KiB
Bash

#!/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