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