Using Parse Functions

Dies ist die alte Dokumentation.
Sie können die neue Dokumentation hier finden, die im Laufe der Zeit die Artikel hier nach und nach ersetzt.
Dieser Artikel wird nicht mehr gepflegt und ist unter Umständen nicht mehr gültig - der neue Artikel hierzu ist jedoch noch nicht fertig!

1. Parse Functions

Some agent based checks have to deal with more complex agent output then simply a few well defined rows and columns. One such example is the check multipath, which needs to deal with a great variety of bizarre output formats of the command multipath -l on Linux.

The typical implementation of such a check is to shift the task of parsing the stuff that arrives the inventory- or check function in the info parameter to a helper function. That function parses the raw agent output into some convenient data structure - often, but now always, a dictionary. While this works pretty well, it has one drawback: If the check deals with more than one item then the same parsing has to be done over and over again.

Beginning with version 1.2.5i7 Checkmk's check API now allows to declare a "parse_function" in the check_info declaration. Here is an example:

check_info["multipath"] = {
    'check_function':          check_multipath,
    'inventory_function':      inventory_multipath,
    'parse_function':          parse_multipath,
    'service_description':     'Multipath %s',
    'group':                   'multipath',

You need to define this function in the same file. It gets the one argument info and must return some parsed representation of that data:

def parse_multipath(info):
    parsed = {}
    # Do some bizarre parsing from info into the new variable parsed
    return parsed

Checkmk will now automatically process all agent output with the parse function before it calls the inventory or check function. In order to make this clear, you should not anymore use the name info as argument, but rather parsed:

def inventory_multipath(parsed):
    # parsed is already in convenient parsed form

... and ...

def check_multipath(item, params, parsed):
    # parsed is already in convenient parsed form

Note: Parse functions cannot be defined for sub checks like Define it on the main check foo. All subchecks will the automatically also use the parse function. If there is no man check then you have bad luck and cannot use parse functions.