diff --git a/config/zones.d/sown/notifications.conf b/config/zones.d/sown/notifications.conf index b07d1df..63f006e 100644 --- a/config/zones.d/sown/notifications.conf +++ b/config/zones.d/sown/notifications.conf @@ -26,6 +26,16 @@ object NotificationCommand "irc-service-notification" { } } +object NotificationCommand "discord-host-notification" { + import "irc-host-notification" + command = [ SOWNScriptsDir + "/discord-notification.sh" ] +} + +object NotificationCommand "discord-service-notification" { + import "irc-service-notification" + command = [ SOWNScriptsDir + "/discord-notification.sh" ] +} + template Notification "generic-notification" { types = [ Problem, Acknowledgement, Recovery, Custom, FlappingStart, FlappingEnd ] } @@ -47,3 +57,21 @@ apply Notification "irc" to Service { interval = 24 * 60 * 60 assign where true } + +apply Notification "discord" to Host { + states = [ Up, Down ] + users = [ "icingaadmin" ] + import "generic-notification" + command = "discord-host-notification" + interval = 24 * 60 * 60 + assign where true +} + +apply Notification "discord" to Service { + states = [ OK, Warning, Critical ] + users = [ "icingaadmin" ] + import "generic-notification" + command = "discord-service-notification" + interval = 24 * 60 * 60 + assign where true +} diff --git a/scripts/.gitignore b/scripts/.gitignore new file mode 100644 index 0000000..4b3b818 --- /dev/null +++ b/scripts/.gitignore @@ -0,0 +1 @@ +discord-notification-creds diff --git a/scripts/discord-notification.sh b/scripts/discord-notification.sh new file mode 100755 index 0000000..54bea59 --- /dev/null +++ b/scripts/discord-notification.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +DIR=$(dirname "${BASH_SOURCE[0]}") +. $DIR/discord-notification-creds + +state="${SERVICESTATE:-$HOSTSTATE}"; +laststate="${LASTSERVICESTATE:-$LASTHOSTSTATE}"; + +type="$NOTIFICATIONTYPE" + +prefix="" +middle="" +if [ "$NOTIFICATIONUMBER" -gt 1 ] && [ "$NOTIFICATIONTYPE" != "ACKNOWLEDGEMENT" ] +then + if [ "$laststate" == "$state" ] + then + prefix="Reminder of " + middle="still " + suffix=" ($NOTIFICATIONUMBER reminders since $(date -d @$LONGDATETIME))" + else + middle="State change $laststate -> " + fi +fi + +if [ -z "$SERVICESTATE" ] +then + alert="$HOSTNAME" +else + alert="$HOSTNAME/$SERVICENAME" +fi + +line="$prefix$type - $alert $middle$state$suffix" + +curl -d "username=Icinga 2" -d "content=$line" "https://discord.com/api/webhooks/$discord_webhook_id/$discord_webhook_token"