XMPP notifications for check_mk

Want to have your check_mk notifiy you via XMPP / Jabber if something goes boom? Here’s a little Python notification script which does just that…

You’ll need sleekxmpp installed, either via pip install sleekxmpp  or apt-get install python3-sleekxmpp  if you’re running Ubuntu.

Next, just add the script to check_mk by placing it here: […]/share/check_mk/notifications/xmpp

#!/usr/bin/env python
# Send Notifications via XMPP

import sleekxmpp
import sys
import os
import logging
import time

class SendMsgBot(sleekxmpp.ClientXMPP):
    def __init__(self, jid, password, recipient, msg):
        super(SendMsgBot, self).__init__(jid, password)
        self.recipient = recipient
        logging.debug("Recipient: %s" % recipient)
        self.msg = msg
        logging.debug("Message: %s" % msg)
        self.add_event_handler('session_start', self.start)
        self.connect()
        self.process(threaded=False)

    def start(self, event):
        self.send_presence()
        self.get_roster()
        self.send_message(mto=self.recipient, mbody=self.msg)
        logging.debug("Message send")
        self.disconnect(wait=True)

if __name__ == '__main__':
    logging.basicConfig(filename='/tmp/notifications.log', format='%(asctime)s %(levelname)s:%(message)s', level=logging.ERROR)
    logging.debug("Start")
    message = os.environ["NOTIFY_NOTIFICATIONTYPE"]+"\nHost: "+os.environ["NOTIFY_HOSTNAME"]+" - "+os.environ["NOTIFY_HOSTSTATE"]+"\nHost-Plugin-Output: "+os.environ["NOTIFY_HOSTOUTPUT"]+"\nService: "+os.environ["NOTIFY_SERVICEDESC"]+" - "+os.environ["NOTIFY_SERVICESTATE"]+"\nService-Plugin-Output:"+os.environ["NOTIFY_SERVICEOUTPUT"]+"\n-------------------------\n\n"
    if os.environ["NOTIFY_SERVICEDESC"] != '$SERVICEDESC$':
        message = "SERVICE"
    else:
        message = "HOST"
        message = message+"-"+os.environ["NOTIFY_NOTIFICATIONTYPE"]+"\n"+os.environ["NOTIFY_SHORTDATETIME"]+"\nHost: "+os.environ["NOTIFY_HOSTNAME"]+" - "+os.environ["NOTIFY_HOSTSTATE"]
    if os.environ["NOTIFY_SERVICEDESC"] == '$SERVICEDESC$':
        message = message+"\nHost-Plugin-Output: "+os.environ["NOTIFY_HOSTOUTPUT"]
    else:
        message = message+"\nService: "+os.environ["NOTIFY_SERVICEDESC"]+" - "+os.environ["NOTIFY_SERVICESTATE"]+"\nService-Plugin-Output:"+os.environ["NOTIFY_SERVICEOUTPUT"]
        message = message+"\n-------------------------\n\n"
        logging.debug("%s" % message)
xmpp = SendMsgBot("[email protected]", "yourpassword" , os.environ["NOTIFY_PARAMETER_1"], message)

Now call the script with the destination ([email protected]) you want notified as custom parameter from within check_mk and give it a try by triggering some alert.

(Originally from here, but last time I checked indentation was broken and the site mostly down)

Event Console not showing up in check_mk

After spending the last couple hours trying to figure out why the event console wasn’t showing up in my manually upgraded OMD/check_mk install (that is OMD 1.2 w/ check_mk 1.2.4p5 upgraded to 1.2.6b10) even though mkeventd is running – here’s what you got to do: manually copy the files from your check_mk source directory into the install director. The setup script does everything else for your, except that.

cd ~
cd check_mk-1.2.6b10/mkeventd.src
rsync -av web/* ~/local/share/check_mk/web/
sending incremental file list
htdocs/
htdocs/mkeventd.py
htdocs/images/button_mkeventd_hi.png
htdocs/images/button_mkeventd_lo.png
htdocs/images/icon_ack.png
htdocs/images/icon_clear.png
htdocs/images/icon_counting.png
htdocs/images/icon_delayed.png
htdocs/images/icon_mkeventd.png
htdocs/images/icon_resetcounters.png
plugins/
plugins/config/
plugins/config/mkeventd.py
plugins/icons/
plugins/icons/mkeventd.py
plugins/sidebar/
plugins/sidebar/mkeventd.py
plugins/views/
plugins/views/mkeventd.py
plugins/visuals/
plugins/visuals/mkeventd.py
plugins/wato/
plugins/wato/mkeventd.py

sent 210,421 bytes received 346 bytes 421,534.00 bytes/sec
total size is 209,125 speedup is 0.99

That’s it. WATO should now show the event console again and things like rule based notification will also work.