
Gotify ist ein kostenloser, einfacher self hosted Notification Server der Nachrichten senden und empfangen kann.
Damit Checkmk Alarmierungen an einen Gotify Server schicken kann, benötigt man nur ein kleines Skript und natürlich einen Gotify Server.
Gotify – Application anlegen
Entweder man hat schon eine oder erstellt sich eine neue Application für Checkmk.
Checkmk – das Gotify Notify Skript
Als Vorlage nehme ich dieses Telegram Skript und passe es ein wenig für die Benachrichtigung mit Gotify an.
https://github.com/filipnet/checkmk-telegram-notify/blob/main/check_mk_telegram-notify.sh
#!/bin/bash
# Gotify
#
# ======================================================================================
# Script Name : checkmk_gotify-notify.sh
# Description : Send Checkmk notifications by Gotify
# Author : https://github.com/filipnet/checkmk-telegram-notify
# License : BSD 3-Clause "New" or "Revised" License
#
# forked from : https://github.com/filipnet/checkmk-telegram-notify
# modified by : https://www.bachmann-lan.de/checkmk-alarmierungen-an-gotify-senden/
# ======================================================================================
# Gotify Server URL
if [ -z ${NOTIFY_PARAMETER_1} ]; then
echo "No Gotify Server URL provided. Exiting" >&2
exit 2
else
SERVER="${NOTIFY_PARAMETER_1}"
fi
# Gotify API Token
if [ -z ${NOTIFY_PARAMETER_2} ]; then
echo "No Gotify token ID provided. Exiting" >&2
exit 2
else
TOKEN="${NOTIFY_PARAMETER_2}"
fi
# Set an appropriate emoji for the current state. Feel free to change the emoji to your own taste.
if [[ ${NOTIFY_WHAT} == "SERVICE" ]]; then
STATE="${NOTIFY_SERVICESHORTSTATE}"
else
STATE="${NOTIFY_HOSTSHORTSTATE}"
fi
case "${STATE}" in
OK|UP)
EMOJI=$'\xF0\x9F\x9F\xA2' # green circle
;;
WARN)
EMOJI=$'\xF0\x9F\x9F\xA1' # yellow circle
;;
CRIT|DOWN)
EMOJI=$'\xF0\x9F\x94\xB4' # red circle
;;
UNKN)
EMOJI=$'\xF0\x9F\x9F\xA0' # orange circle
;;
esac
# Create a MESSAGE variable to send to Gotify
MESSAGE="${NOTIFY_HOSTNAME} (${NOTIFY_HOST_ADDRESS_4})"
MESSAGE+=" ${EMOJI} ${NOTIFY_WHAT} ${NOTIFY_NOTIFICATIONTYPE}\n"
if [[ ${NOTIFY_WHAT} == "SERVICE" ]]; then
MESSAGE+="${NOTIFY_SERVICEDESC}\n"
MESSAGE+="State changed from ${NOTIFY_PREVIOUSSERVICEHARDSHORTSTATE} to ${NOTIFY_SERVICESHORTSTATE}\n"
MESSAGE+="${NOTIFY_SERVICEOUTPUT}\n"
else
MESSAGE+="State changed from ${NOTIFY_PREVIOUSHOSTHARDSHORTSTATE} to ${NOTIFY_HOSTSHORTSTATE}\n"
MESSAGE+="${NOTIFY_HOSTOUTPUT}\n"
fi
MESSAGE+="Date: ${NOTIFY_SHORTDATETIME}"
# Send message to Gotify Server
curl -s -S --data '{"message": "'"${MESSAGE}"'", "title": "'"${NOTIFY_HOSTNAME}"'", "priority":'"5"', "extras": {"client::display": {"contentType": "text/markdown"}}}' -X POST -H Content-Type:application/json "${SERVER}/message?token=${TOKEN}"
if [ $? -ne 0 ]; then
echo "Not able to send Gotify message" >&2
exit 2
else
exit 0
fi
Skript in Checkmk einbinden
Das Skript ins entsprechende Verzeichnis auf den Checkmk Server kopieren und ausführbar machen.
# zum SITE User wechseln $ su - MYSITE # ins notifications Verzeichnis wechseln $ cd ~/local/share/check_mk/notifications/ # das Gotify Skript herunterladen $ wget https://bachmann-lan.de/projects/checkmk-gotify/checkmk_gotify-notify.sh # Datei ausführbar machen $ chmod +x checkmk_gotify-notify.sh
Setup → Notifications → Add rule. Gotify auswählen, Parameter 1 ist die URL des Servers, Parameter 2 ist der Token der angelegten App.
Zum testen mal ein paar fake checks von einem Service erstellen. Sollten dann sofort im Gotify Server ankommen.







Hallo,
erstmal vielen Dank für Script. Ich habe das Problem, dass ich nur ein Parameter angeben kann, sprich die URL. Das 2. Feld wo der App Token eingetragen werden soll, erscheint gar nicht erst bei mir. Weißt du woran das liegen kann ?
Gruß Tobi
Kann nicht sein!?
Sobald du in das erste Feld etwas eingibst, wird automatisch immer ein weiteres Feld hinzugefügt.
Du hast natürlich absolut Recht. Das war wohl noch ein wenig zu früh heute morgen :)
Das ist gut. Sonst hätte nämlich deine Checkmk Installation ein Problem.
Vielen Dank für das Script!!!
Funktioniert einwandfrei.
Jetzt bin ich nur noch auf der Suche nach einem Plugin, um Gotify dazu zu bringen, Nachrichten an mehrere User zu senden. Sowie wie das bei Pushover mit den Groups möglich ist.
Schöne Grüße
Michael
Vielen Dank,
Olaf
Ahoi, das klappt prima, allerdings bekomme ich für jede Notification 4 Messages in Gotify. Woran kann das liegen?
Das kann ich dir leider nicht sagen. Nutze aktuell kein Gotify mehr.
Ok, working perfectly now. The cause was that i set checkmk to notify all users and i had 4 so i switched to one specific user in checkmk notification rule and everything is working.
I also switched to https and added -k in the curl command. Yes i will fix this by trusting my cert, sometimes later ;)
Thanks for your feedback.
Hallo
hast bzw. erstellst du auch noch ein Skript für Signal?
Leider hat es mit Gotify nicht funktionert und wenn Gotify mir eine Nachricht sendet, wir es im Sperrbildschirm usw. nicht beim IPhone angezeigt
mfg
Th. Seide
Nein, habe ich nicht. Ob ich mal eins erstelle kann ich dir nicht versprechen.