Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add emojis according to notification state #7

Merged
merged 2 commits into from
Sep 9, 2021

Conversation

reduxionist
Copy link
Contributor

Hi,

Thanks for sharing your code! When we switched from Nagios to Checkmk, the feature our team missed from the previous Telegram-notification plug-in we used was the emojis: they found them helpful when scanning through the channel history or quickly parsing a pop-up notification and requested they be restored.

In case you thought the functionality worth providing to others too, may we present this PR for your consideration. Just let us know if there's any changes you'd like made...

Yours gratefully,
Jonathan Barratt
(Intelligent-Bytes)

@riccardospeggiorin-centropaghe

Thanks 👌!

@filipnet filipnet added the enhancement New feature or request label Sep 8, 2021
@@ -1,5 +1,5 @@
#!/bin/bash
# Push Notification (using Telegram)
# Push Notification with Emojis (using Telegram)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment in line 2 should "not" be changed, because Check_MK uses it for GUI configuration, so existing installations would have an impact.

Push Notification (using Telegram)

@@ -58,9 +58,30 @@ else
echo "Invalid privacy parameter, check your Check_MK settings." >&2
fi

# Set an appropriate emoji for the current state
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the UTF-8 encoded emojis in the source code to the "bytes (UTF-8)" notation. This makes more sense from my point of view for compatibility and customizing. The choice of emojis is a matter of taste.

Set an appropriate emoji for the current state

Feel free to change the emoji to your own taste. This is done by customizing the UTF8 code. Examples here: https://apps.timwhitlock.info/emoji/tables/u$

if [[ ${NOTIFY_WHAT} == "SERVICE" ]]; then
STATE="${NOTIFY_SERVICESHORTSTATE}"
else
STATE="${NOTIFY_HOSTSHORTSTATE}"
fi
case "${STATE}" in
OK|UP)
EMOJI=$'\xE2\x9C\x85' # white heavy check mark
;;
WARN)
EMOJI=$'\xE2\x9A\xA0' # warning sign
;;
CRIT|DOWN)
EMOJI=$'\xF0\x9F\x86\x98' # squared sos
;;
UNKN)
EMOJI=$'\xF0\x9F\x94\x84' # anticlockwise downwards and upwards open circle arrows
;;
esac

# Create a MESSAGE variable to send to your Telegram bot
MESSAGE="${NOTIFY_HOSTNAME} (${NOTIFY_HOSTALIAS})%0A"
MESSAGE+="${NOTIFY_WHAT} ${NOTIFY_NOTIFICATIONTYPE}%0A%0A"
MESSAGE+="${EMOJI}${NOTIFY_WHAT} ${NOTIFY_NOTIFICATIONTYPE}%0A%0A"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I would not generate the space between emoji and text in the variable, but in the code.

MESSAGE+="${EMOJI} ${NOTIFY_WHAT} ${NOTIFY_NOTIFICATIONTYPE}%0A%0A"

@filipnet
Copy link
Owner

filipnet commented Sep 8, 2021

Hello,

with pleasure! I'm very happy to see others using the module and even contributing valuable input like you do. I have looked at the changes and tested it in the sandbox. Thank you, I like the improvement very much, great idea.

I would like to integrate the pull request into the code, but have comments and ideas before. I have already enhanced the code of the pull request as notes. Would you like to make the changes yourself and thus immortalize yourself as a contributor to the project? I would add the README myself afterwards, provide for new screenshots.

@reduxionist
Copy link
Contributor Author

Hello,

No need to delay committing as changed! They were all issues I deliberated on myself but guessed wrong as to your preferences:

  1. I wasn't sure whether you'd want to allow for installation of both versions in case existing users wanted to test side-by-side or give different preferences to different users.
  2. I was too lazy to figure out bash syntax for the python byte string I had, and so resorted to the copy-paste approach which was just too easy in my UTF8-friendly terminal font; my apologies for cutting corners here! 八
  3. In the case of generating the spaces in the message itself, we're introducing a blank space when some unforeseen new status code[1] appears and we don't set an emoji. So we might either want to use the ${EMJOI:+ } syntax (if it's not zsh specific) or add a *) default clause to the new case statement (I couldn't settle on a good emoji for this and it seemed unlikely enough that I wanted to keep new code introduced as minimal as possible).

Thrilled you appreciate the contribution and please feel free to merge your own changes and avoid duplicate typing! ;)

p.s. I did add one screenshot after the fact, but if you tell me what other states you'd like screenshots of, then I'll be happy to provide those myself and save you the time (also let me know if you require the IPv6 masked address included; my home router wouldn't cooperate but I can capture images from staging instead).

[1]: e.g. Nagios reported an UNREACHABLE state for hosts, which I couldn't find reference to in checkmk's host state output, so I skipped the nice "🚧" emoji I'd found for it...

@filipnet filipnet merged commit e5628ba into filipnet:main Sep 9, 2021
@reduxionist reduxionist deleted the feature/emojis branch September 24, 2021 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants