Werk #8293: Alert handlers: optionally process every single check execution, inline alert handlers

Component The Checkmk Micro Core
Title Alert handlers: optionally process every single check execution, inline alert handlers
Date Jul 22, 2015
Checkmk Edition Checkmk Enterprise (CEE)
Checkmk Version 1.2.7i3
Level Prominent Change
Class New Feature
Compatibility Compatible - no manual interaction needed

The new alert handlers can now optionally be called at every check execution. This is a possible way to bring check results into some external system (like a database). Please note that this can cost many CPU ressources and slow down the monitoring if the alert handler cannot process the data fast enough.

In order to implement more performance alert handlers, these can now optionally be written as Python functions that are being called without creating a new process. Such an inline alert handler has the following structure:

/omd/sites/mysite/local/share/check_mk/alert_handlers/foo

#!/usr/bin/python
# Inline: yes

# Do some basic initialization (optional)
def handle_init():
    log("INIT")

# Called at shutdown (optional)
def handle_shutdown():
    log("SHUTDOWN")

# Called at every alert (mandatory)
def handle_alert(context):
    log("ALERT: %s" % context)

You need to define at least handle_alert. The argument context is a dictionary with keys like "HOSTNAME". You can use the function log(...), which will write some diagnostic text into var/log/alerts.log - marked with the name of you alert handler.

The two global variables omd_root and omd_site are set to the home directory and to the name of the OMD site.

It is allowed to use import commands in your handler.

Note that in the second line you need to put # Inline: yes. That way Check_MK nows that the alert handler should be loaded as inline Python function and not run as a script.

Note also that after each change to an inline alert handler you need to restart the CMC:

OMD[mysite]:~$ omd restart cmc

To the list of all Werks