Unable to set parameters on custom snmp agents

CMK version: 2.3.0p30 Raw
OS version: RHEL 9

Error message:

Output of “cmk --debug -vvn hostname”: (If it is a problem with checks or plugins)

Hi All, are you able to tell me what I am doing wrong with setting up my snmp agent? I wanted to set default upper and lower warning and critical thresholds for my snmp check which returns Air Pressure ¶. The issues I am running into is -
A: when I set a check_ruleset_name to anything I get an error relating to a KeyError when I click the parameters for this service.
B: If I set it to ‘none’ I no longer get the error however I want the user to be able to modify the thresholds which is via the parameters for this service and there is no option for it. Any help is greatly appreciated!

#!/usr/bin/env python3
# -*- encoding: utf-8; py-indent-offset: 4 -*-
from cmk.agent_based.v2 import (
    CheckPlugin,
    Service,
    SNMPSection,
    SNMPTree,
    startswith,
    State,
    Result,
    Metric,
)

def parse_pdu_air_pressure(string_table):
    """
    Parse air pressure data from PDU SNMP data
    Values are likely in decipascals (dPa), so we'll convert to pascals
    """
    parsed = {}
    
    if string_table and string_table[0]:
        try:
            raw_value = int(string_table[0][0])
            # Convert to pascals
            pressure_pa = raw_value / 10.0
            parsed['pressure_pa'] = pressure_pa
        except (ValueError, TypeError):
            pass
    
    return parsed

snmp_section_pdu_air_pressure = SNMPSection(
    name='pdu_air_pressure',
    detect=startswith('.1.3.6.1.2.1.1.1.0', 'PX2'),
    parse_function=parse_pdu_air_pressure,
    fetch=SNMPTree(
        base='.1.3.6.1.4.1.13742.6.5.5.3.1.4',
        oids=[
            '1.2',  # Air pressure value
        ]
    ),
)

def discovery_pdu_air_pressure(section):
    """
    Discover air pressure service if data is available
    """
    if section and 'pressure_pa' in section:
        yield Service()

def check_pdu_air_pressure(item, params, section):
    """
    Check PDU air pressure with simpler threshold handling
    """
    if not section or 'pressure_pa' not in section:
        return
    
    pressure_pa = section['pressure_pa']
    
    # Default thresholds
    warn_upper = 45
    crit_upper = 60
    warn_lower = 5
    crit_lower = 0
    
    if params:
        if 'levels_upper' in params:
            warn_upper, crit_upper = params['levels_upper']
        if 'levels_lower' in params:
            warn_lower, crit_lower = params['levels_lower']
    
    state = State.OK
    state_txt = "OK"
    
    if pressure_pa >= crit_upper or pressure_pa <= crit_lower:
        state = State.CRIT
        state_txt = "CRITICAL"
    elif pressure_pa >= warn_upper or pressure_pa <= warn_lower:
        state = State.WARN
        state_txt = "WARNING"
    
    # Create message
    message = f"Air Pressure: {pressure_pa:.1f} Pa"
    
    # Add threshold information if in warning/critical state
    if state != State.OK:
        if pressure_pa > 0:
            message += f" (threshold: {warn_upper:.1f}/{crit_upper:.1f} Pa)"
        else:
            message += f" (threshold: {warn_lower:.1f}/{crit_lower:.1f} Pa)"
    
    yield Result(state=state, summary=message)
    yield Metric("pressure", pressure_pa)

check_plugin_pdu_air_pressure = CheckPlugin(
    name='pdu_air_pressure',
    service_name='PDU Air Pressure',
    discovery_function=discovery_pdu_air_pressure,
    check_function=check_pdu_air_pressure,
    check_default_parameters={
        'levels_upper': (45, 60),
        'levels_lower': (5, 0)
    },
    check_ruleset_name=None,
)

Have a look at the check_levels method of the check API. It has everything you need.

If you want to be able to set threshold values in the GUI, you need to define a Rule Set. Have a look in part 5 of this document: Writing agent-based check plug-ins