Skip to content

Commit e5628ba

Browse files
authored
Merge pull request #7 from intelligent-bytes/feature/emojis
add emojis according to notification state
2 parents a162529 + 4b2f5b1 commit e5628ba

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

check_mk_telegram-notify.sh

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Push Notification (using Telegram)
2+
# Push Notification with Emojis (using Telegram)
33
#
44
# Script Name : check_mk_telegram-notify.sh
55
# Description : Send Check_MK notifications by Telegram
@@ -8,7 +8,7 @@
88
# ======================================================================================
99

1010
# Telegram API Token
11-
# Find telegram bot named "@botfarther", type /mybots, select your bot and select "API Token" to see your current token
11+
# Find telegram bot named "@botfather", type /mybots, select your bot and select "API Token" to see your current token
1212
if [ -z ${NOTIFY_PARAMETER_1} ]; then
1313
echo "No Telegram token ID provided. Exiting" >&2
1414
exit 2
@@ -58,9 +58,30 @@ else
5858
echo "Invalid privacy parameter, check your Check_MK settings." >&2
5959
fi
6060

61+
# Set an appropriate emoji for the current state
62+
if [[ ${NOTIFY_WHAT} == "SERVICE" ]]; then
63+
STATE="${NOTIFY_SERVICESHORTSTATE}"
64+
else
65+
STATE="${NOTIFY_HOSTSHORTSTATE}"
66+
fi
67+
case "${STATE}" in
68+
OK|UP)
69+
EMOJI=""
70+
;;
71+
WARN)
72+
EMOJI=""
73+
;;
74+
CRIT|DOWN)
75+
EMOJI="🔥 "
76+
;;
77+
UNKN)
78+
EMOJI=""
79+
;;
80+
esac
81+
6182
# Create a MESSAGE variable to send to your Telegram bot
6283
MESSAGE="${NOTIFY_HOSTNAME} (${NOTIFY_HOSTALIAS})%0A"
63-
MESSAGE+="${NOTIFY_WHAT} ${NOTIFY_NOTIFICATIONTYPE}%0A%0A"
84+
MESSAGE+="${EMOJI}${NOTIFY_WHAT} ${NOTIFY_NOTIFICATIONTYPE}%0A%0A"
6485
if [[ ${NOTIFY_WHAT} == "SERVICE" ]]; then
6586
MESSAGE+="${NOTIFY_SERVICEDESC}%0A"
6687
MESSAGE+="State changed from ${NOTIFY_PREVIOUSSERVICEHARDSHORTSTATE} to ${NOTIFY_SERVICESHORTSTATE}%0A"
46.3 KB
Loading

0 commit comments

Comments
 (0)