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("checkmk-msg-bot@somejabberserver.tld", "yourpassword" , os.environ["NOTIFY_PARAMETER_1"], message)
Now call the script with the destination (youruser@somejabberserver.tld) 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)