Parse_function is never called


I am currently writing my first special agent (to monitor a Things Network Gateway). I am using check_mk 1.6.0p19. I have it almost working, but I have problems writing the actual check.
I wrote a parse function and registered it using check_info, but it never gets called, instead the “unparsed” regular info structure is passed into the inventory and check functions…

The code is there:

If I run cmk --debug --checks=ttn_gateway.lastseen --cache -vvII ttig,
the pprint at the top of the inventory function will print parsed as:
[[u’Markus’, u’TTIG’, u’(The’, u’Things’, u’Indoor’, u’Gateway’, u’2.0.0):’, u’52’]]
instead of the dictionary that should have been built in the parse function…

Can someone help me howto fix or further debug this?


Please test with the parse function changed from

def parse_ttn_gateway_info(lines)


def parse_ttn_gateway_info(info)

Thanks Andreas.
I tried that – see updated gist – but it did not work.
I reloaded check_mk with cmk -R and then tried again. Same behaviour as before :frowning:

You defined the check as


The dot indicates that this is a sub-check of the main check ttn_gateway. For subchecks, there can only be one parse function: that of the main check. You cannot have separate parse functions for the main check and subchecks.

Btw, the check function can be simplified to

def check_ttn_gateway_lastseen(item, params, parsed):
    if not parsed or item not in parsed:

    if isinstance(params, tuple):
        warn, crit = params
        warn, crit = params['levels']
    value = saveint(parsed[item])
    perfdata = [('last seen', value, warn, crit)]
    if value < warn:
        yield 0, "%d s since last seen" % value, perfdata
    elif value < crit:
        yield 1, "%d s since last seen" % value, perfdata
        yield 2, "%d s since last seen" % value, perfdata

No need for the for loop because item is already the key to the parsed structure.


Hi Dirk,

thanks! That helped a lot.

I did not have a main check at all, so renaming the key in check_info to ‘ttn_gateway’ solved it => the parse function gets called correctly.
Thank you also for the suggestion about removing the for loop in the check function. Now a feel a bit stupid :slightly_smiling_face:

One last thing: the info that is passed into the parse function is still preprocessed. So I had to change the code of the parse function a bit, because I actually do not get the raw output of the agent (other than I expected), see for the current version.
I used the join method to restore the lines – see line 26.
Is there a better way of doing that?


The join is ok. Another option is to use the separator inside the agent output header.
Example <<<plugin_name:sep(0)>>> this will tell CMK that is should split the output at ASCII 0 and not at ASCII 32 what is the default. As you will not have ASCII 0 inside your string you will get every line already as one string and don’t need the join.

You can also remove the if not line.startswith("<<<"): line as the header from you plugin output is already removed from CheckMK.


If the agent output looks like this:

Markus TTIG (The Things Indoor Gateway 2.0.0):	64

Then I’d suggest the colon : as separator, i.e.

Markus TTIG (The Things Indoor Gateway 2.0.0):	64

The parse function can then be written as

def parse_ttn_gateway_info(info):
    parsed = {}
    for gateway, value in info:
        parsed[gateway.strip()] = saveint(value.strip())
    return parsed

This will result in

parsed = {
    'Markus TTIG (The Things Indoor Gateway 2.0.0)': 64

Note: the parse function will crash if the agent output does not contain exactly two fields separated by a : (as does your version, btw.). To circumvent this, use the following instead:

def parse_ttn_gateway_info(info):
    parsed = {}
    for line in info:
        if len(line)==2:
            (gateway, value) = line
            parsed[gateway.strip()] = saveint(value.strip())
    return parsed

Update: I’ve put the call to saveint into the parse function here, so you can drop that step from the check function. Or drop it here and keep it in the check function. Actually, it doesn’t matter and I have to confess I don’t do it consistently myself. :wink:

1 Like

Thanks for your help, Dirk. I’ve learned quite a bit from your answers! :+1: