Unclear dokumentation on how to use params in check function

I try to code a plugin, but due to the lack of up to date documentation, this became a mess already …
so far i got most things sorted out, except how to use params inside checks …

I created the variable, I yielded it in the inventory like the tutorial suggested, but this just gives me “UNKNOWN - invalid output from agent or error in check implementation” in the webfront but no error in the console (‘check_mk --no-cache --checks bitbox_ram -I tom01-adm’)

I then found an option for the check_info (“default_levels_variable” : “ram_default_levels”) which at least gave me an empty dictionary as param “{}” but still not the variable i defined …
What am I missing? Is there any working documentation/tutorial?

ram_default_levels = (2, 1) # this is, what i would like to get as params in the check
def inventory_bitbox_ram(info):
    for line in info:
        yield line[0], "ram_default_levels"

def check_bitbox_ram(item, params, info):
    warn, crit = params # this is an empty dict, even if it should not be :(
    for line in info:
        if item == line[0]:
            perfdata= [("free", line[2], "", "", 0, line[1]),
                ("available", line[3], "", "", 0, line[1])]
            if line[3] > warn:
                return 0, "OK - %s RAM: %.2fGB available of %.2fGB (%.2fGB free)." % (line[0], line[3], line[1], line[2]), perfdata

            elif line[3] > crit:
                return 1, "WARNING - %s RAM: %.2fGB available of %.2fGB (%.2fGB free)." % (line[0], line[3], line[1], line[2]), perfdata

            elif line[3] <= crit:
                return 2, "CRITICAL - %s RAM: %.2fGB available of %.2fGB (%.2fGB free)." % (line[0], line[3], line[1], line[2]), perfdata


check_info["bitbox_ram"] = {
    "snmp_scan_function"    : scan_bitbox,
    "parse_function"        : parse_bitbox_ram,
    "inventory_function"    : inventory_bitbox_ram,
    "check_function"        : check_bitbox_ram,
    "default_levels_variable" : "ram_default_levels", # without this, the whole check seems to not execute at all without any further information
    "has_perfdata"          : True,
    "group"                 : "bitbox",
    "service_description"   : "RAM %s",
    "snmp_info"             : ( ".1.3.6.1.4.1.30205.18.1.1", ["1", "6", "7", "8"])
}
1 Like

Try to :

factory_settings[“ram_default_levels”] = {
“levels” : (2,1)
}

in the check funtion assume values as :

warn, crit = params[“levels”]

Hope it helps.

Cheers,

3 Likes

Or you can ease up on these by:

factory_settings["ram_default_levels"] = (2, 1)

#inside check_function
...
warn, crit = params

This is not recommended. The answer from @ricardoftribeiro is better for today.