Enforced Checks problems

Version: Checkmk Managed Services Edition 2.3.0p10

Edit:
Somehow I have problems with all enforced checks. Previously with the “ManualCheckParameterRulespec” in the old API it worked without any problems.
Is the syntax of the enforced checks different from the discovered rules (CheckParameters)? Is there an example of a working enforced check somewhere? I have not found one in the CMk repositories.


Original Post:
Hello everyone,

I have a problem with a new SNMP check. I have created a check that is supposed to monitor a number of failed logs. The check should be an enforced check, as it should not be rolled out automatically on every suitable device.

The check generally works, I can create corresponding rules and they work correctly.
However, when I call up the service via the “Parameters for this Service” menu, I get the following errors:

Source Code Check (snipped):

def check_fortigate_log_devices(params, section):

    log_devices_disabled = []
    failed_count_warn, failed_count_crit = params["failedcount_params"][1]

    for log_device in section:

        # entryindex = int(section[log_device]["EntryIndex"])
        enabled = str(section[log_device]["Enabled"])
        name = str(section[log_device]["Name"])
        sentcount = int(section[log_device]["SentCount"])
        relayedcount = int(section[log_device]["RelayedCount"])
        cachedcount = int(section[log_device]["CachedCount"])
        failedcount = int(section[log_device]["FailedCount"])
        droppedcount = int(section[log_device]["DroppedCount"])

        if enabled == "1":

            check_state = State.OK 
            check_notice = " "

            if failedcount >= failed_count_crit:
                check_state = State.CRIT
                check_notice = f"'{name}' has {failedcount} failed messages."
            elif failedcount >= failed_count_warn:
                check_state = State.WARN
                check_notice = f"'{name}' has {failedcount} failed messages."

            yield Result(state=State.OK, notice=" ", details=f"\nLog device: {name} \nSentCount: {sentcount} \nRelayedCount:{relayedcount} \nCachedCount: {cachedcount} \nDroppedCount: {droppedcount}")
            yield Result(state=check_state, notice=check_notice, details=f"FailedCount: {failedcount}")

        else:
            log_devices_disabled.append(name)

    log_devices_disabled_list = ", ".join(log_devices_disabled)
    yield Result(state=State.OK, notice=" ", details=f"\nDisabled log devices: {log_devices_disabled_list}")


check_plugin_fortigate_log_devices = CheckPlugin(
    name="fortigate_log_devices",
    service_name="Log devices",
    discovery_function=discover_fortigate_log_devices,
    check_function=check_fortigate_log_devices,
    check_default_parameters={"failedcount_params": ("fixed", (100, 200))},
    check_ruleset_name="fortigate_log_devices",
)

Source Code ruleset:

from cmk.rulesets.v1 import Title
from cmk.rulesets.v1.rule_specs import Topic, HostCondition, EnforcedService
from cmk.rulesets.v1.form_specs import (
    DefaultValue,
    DictElement,
    Dictionary,
    Integer,
    LevelDirection,
    SimpleLevels,
)


def _parameter_valuespec_fortigate_log_devices() -> Dictionary:
    return Dictionary(
        elements = {
            "failedcount_params": DictElement(
                parameter_form = SimpleLevels(
                    level_direction = LevelDirection.UPPER,
                    form_spec_template = Integer(unit_symbol='messages'),
                    prefill_fixed_levels = DefaultValue(value=(100, 200)),
                    title=Title("Failed Messages"),
                )
            ),
        }
    )


rule_spec_fortigate_log_devices = EnforcedService(
    name = "fortigate_log_devices",
    title = Title("Fortigate Log Devices"),
    topic = Topic.NETWORKING,
    parameter_form = _parameter_valuespec_fortigate_log_devices,
    condition = HostCondition(),
)

Currently I have the assumption that I cannot use “SimpleLevels” from rulesets.v1.form_specs if I do not use the function “check_levels” in the check? But that doesn’t make any sense either.

…or I just miss something stupid :slight_smile:
I hope you have en idea what is wrong here.

Thanks in advance!
Kind regards, Marc