Checkmk: Notifications about Mastodon
Notifications from Checkmk can also be displayed on Mastodon with little effort - even privately

Check mk offers all sorts of internal possibilities, to be informed about status changes. There are more in the Checkmk Exchange and the homemade one that we here for Telegram accomplished is also child's play (in the meantime, however unnecessary). Mastodon could be increasingly interesting, after all, you can also do it in-house!
Checkmk + Mastodon + toot
The procedure is very simple: First you need a Script, which reads and processes the data of the notification from Checkmk. In order for the script to be triggered in the event of a notification, you also need one Checkmk rule and the script must be in a specific directory lie.
The script base is the program toot, a simple command line client for Mastodon. We'll show you how to set up toot here.
create script
First, here is the script mastodon_notifier within the Checkmk instance, speak under OMD[mysite]:~/local/share/check_mk/notifications/mastodon_notifier:
#!/bin/bash
# Mastodoner
env | grep NOTIFY_ | sort > $OMD_ROOT/tmp/foobar.out
cat $OMD_ROOT/tmp/foobar.out |\
egrep "NOTIFY_HOSTNAME=|NOTIFY_LASTHOSTSTATE=|NOTIFY_HOSTSTATE=" |\
sed ' s/NOTIFY_HOSTNAME=/Host:/ ; s/NOTIFY_LASTHOSTSTATE=/Alt:/ ; s/NOTIFY_HOSTSTATE=/Neu:/ ' |\
/home/mirco/.nvm/versions/node/v18.14.0/bin/toot --config /home/mirco/.mastodon.json --visibility direct
exit 0
# Mastodon is the title as it is also displayed in Checkmk. The line with env gets the notification, sorts it and saves it to the file foobar.out.
Then foobar.out will be over cat spent, gooseberry reduced to the fields required here: host name, last and current status, thirst replaces the variable names with Host:, Old: and New:, to make it look pretty.
Then he follows toot call: Here you need the absolute path and the manual specification of the configuration file - after all, toot was installed under a user account (here "mirco") and not as an instance user (here "mysite"). The visibility get up here direct, so that the toot is only visible to directly mentioned users - in this case only to the sender himself.
Tip: You might think you could take the intermediate step over the file foobar.out save. But if you put egrep directly on the sort command, the script will be executed multiple times and toots will hail...
Tip 2: A nice overview of all available notification fields can be found in Checkmk at Setup/Events/Notifications/Show analysis. In the list of recent notifications, click one of the scrolls Icons, to see the full context:

Don't forget: Make the script executable!
chmod +x mastodon_notifier
That was it in the terminal.
create rule
Now create one Notifications rule and puts as Notification method Your script – plus any filters.

And the result on Mastodon:
