Skip to content

Commit

Permalink
add discord notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
TimStallard authored and root committed Nov 14, 2022
1 parent e363fef commit 3974e89
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
28 changes: 28 additions & 0 deletions config/zones.d/sown/notifications.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
}
Expand All @@ -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
}
1 change: 1 addition & 0 deletions scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
discord-notification-creds
34 changes: 34 additions & 0 deletions scripts/discord-notification.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 3974e89

Please sign in to comment.