f.zz.de
posts /

Pushover and icinga1

Posted Mon 06 Jul 2020 01:24:06 PM CEST Florian Lohoff
in

Yes i know - icinga1 is legacy and old but still there are installations running and we want modern notifications. I had a look at pushover.net which looked awesome. So i created an account and integrated it into icinga1.

This is my /usr/local/sbin/pushover

#!/bin/sh

TOKEN=$1
USER=$2
TITLE=$3

T=`tempfile`
trap "rm ${T}" exit

cat >>${T}

curl -s \
        --form-string "token=${TOKEN}" \
        --form-string "user=${USER}" \
        --form-string "title=${TITLE}" \
        -F "message=<${T}" \
        https://api.pushover.net/1/messages.json \
        logger -t pushover

It accepts the message on stdin, uses the user and api token and title from the command line. So i define the app and user token in the contacts definition:

define contact{
        contact_name                    flo-pushover
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    w,u,c,r
        host_notification_options       d,r
        service_notification_commands   notify-service-by-pushover
        host_notification_commands      notify-host-by-pushover
        _pushovertoken                  dDiFlqCnOrandomgenerated2lgWlNo9
        _pushoveruser                   jdf3jf6OVrandomgeneratedP1ywAP4z
}

Here is the service command definition:

define command{
        command_name    notify-service-by-pushover
        command_line    /usr/bin/printf <message> | /usr/local/sbin/pushover $_CONTACTPUSHOVERTOKEN$ $_CONTACTPUSHOVERUSER$ "<title>"
}