Adding WATO check_parameters breaks the check function

CMK version: 2.1.0p21.cre
OS version: Ubuntu 20.04

Hi everyone!
I have written a custom plugin to monitor temperatures via SNMP of a tcw122b temperature controller.
It works OK, and draws a graph.
However, I have hard-coded TEMP_CRIT & TEMP_WARN and I would like to set these parameters from the GUI (with WATO?).

First of all, I have tried looking around in the forum and on the internet for a solution but couldn’t find any… Maybe I just use poor keywords, so I don’t take any offense if someone just provides an all-solving URL.

I’ve read the documentation, and found out I had to look for a corresponding rule set (temperature?), but adding

    check_ruleset_name="temperature",
    check_default_parameters={},

at the bottom of register.check_plugin(), brings up the following error when running
cmk --detect-plugins=tcw122b_sensors_temp -vI tc1:

Error in agent based plugin tcw122b_sensors_temp: check_function: 'params' argument expected if and only if default parameters are not None

I have trouble understanding this message as I can’t find the params argument this error is talking about…
Anyways, I tried adding params to my check_function arguments like this

def check_tcw122b_sensors_temp(params, section)

But I get another error:

Error in agent based plugin tcw122b_sensors_temp: Check ruleset temperature has checks with and without item! At least one of the checks in this group needs to be changed (offending plugin: tcw122b_sensors_temp)

I have tried adding also an item parameter but with no luck:

Error in agent based plugin tcw122b_sensors_temp: check_function: unexpected 'item' argument

I am stuck on this issue for several days now, I would be very happy if someone can point me in the right direction…

Here is the working version of the plugin

#!/usr/bin/env python3
# -*- encoding: utf-8; py-indent-offset: 4 -*-

# from official docs https://docs.checkmk.com/latest/en/devel_check_plugins.html#snmp
from .agent_based_api.v1 import *

# Hard-coded parameters -> to be replaced by WATO
TEMP_CRIT = 50
TEMP_WARN = 35

def discover_tcw122b_sensors_temp(section):
    yield Service()

def check_tcw122b_sensors_temp(section):
    max_temp = 0
    for temp in section:
        if temp > max_temp:
            max_temp = temp

    if max_temp > TEMP_CRIT:
        state = State.CRIT
    elif (max_temp > TEMP_WARN):
        state = State.WARN
    else:
        state = State.OK

    yield Metric("Temperature", value=max_temp, levels=(TEMP_WARN, TEMP_CRIT), boundaries=(0, 100))
    yield Result(state=state, summary="Temperature: {}°C".format(max_temp))
    return

def parse_tcw122b_sensors_temp(string_table):
    parsed = []
    for temp in string_table:
        # Turn temperature from 10*C° to C°
        parsed.append(int(temp[0])/10)

    return parsed

# SNMP section
register.snmp_section(
    name = 'tcw122b_sensors_temp',
    detect = startswith('.1.3.6.1.2.1.1.1.0', 'TCW122B'),
    parse_function = parse_tcw122b_sensors_temp,
    fetch = SNMPTree(
        base = '.1.3.6.1.4.1.38783.3',
        oids = [
            '9',                     # temp1x10Int
            #'10',                   # temp2x10Int
            #'11',                   # humi1x10Int
            #'12',                   # humi2x10Int
        ]
    ),
)

register.check_plugin(
    name = 'tcw122b_sensors_temp',
    service_name = 'TCW122B Temperature',
    discovery_function = discover_tcw122b_sensors_temp,
    check_function = check_tcw122b_sensors_temp,
)

The ruleset you are trying to use always requires an item in the check.

I.e. in the discovery function you have to yield Service(item=…), the check_function needs an item argument and the service_name should contain %s to be replaced with the item.

3 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.