From dd6573219fed55cc0c63eda6cd55b24c112d11a4 Mon Sep 17 00:00:00 2001 From: Piteball Date: Thu, 23 Jun 2022 23:00:14 +0200 Subject: [PATCH] first commit --- README.md | 1 + check_mk_telegram-notify.sh | 66 +++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 README.md create mode 100644 check_mk_telegram-notify.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ + diff --git a/check_mk_telegram-notify.sh b/check_mk_telegram-notify.sh new file mode 100644 index 0000000..7f222a2 --- /dev/null +++ b/check_mk_telegram-notify.sh @@ -0,0 +1,66 @@ +#!/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 \ No newline at end of file