SNMP Custom Check Crash

Hello,

I’m trying to create my first custom SNMP check, so I have tried to start off as simple as possible with minimal code to get a stable result and work from there, but I am getting a an error generated from "cmk -vp --debug " Not sure what I have done wrong in my code for it to be crashing. Any pointers would be greatly appreciated. Thanks

CMK version: 2.0.0p25 (CEE)
OS version: Ubuntu 18.04.4 LTS

Error message:

Traceback (most recent call last):
  File "/omd/sites/Azure/bin/cmk", line 98, in <module>
    exit_status = modes.call("--check", None, opts, args)
  File "/omd/sites/Azure/lib/python3/cmk/base/modes/__init__.py", line 69, in call
    return handler(*handler_args)
  File "/omd/sites/Azure/lib/python3/cmk/base/modes/check_mk.py", line 1643, in mode_check
    return checking.do_check(
  File "/omd/sites/Azure/lib/python3/cmk/base/decorator.py", line 37, in wrapped_check_func
    status, infotexts, long_infotexts, perfdata = check_func(hostname, *args, **kwargs)
  File "/omd/sites/Azure/lib/python3/cmk/base/checking.py", line 212, in do_check
    num_success, plugins_missing_data = _do_all_checks_on_host(
  File "/omd/sites/Azure/lib/python3/cmk/base/checking.py", line 343, in _do_all_checks_on_host
    success = execute_check(
  File "/omd/sites/Azure/lib/python3/cmk/base/checking.py", line 486, in execute_check
    submit, data_received, result = get_aggregated_result(
  File "/omd/sites/Azure/lib/python3/cmk/base/checking.py", line 564, in get_aggregated_result
    result = _aggregate_results(check_function(**kwargs))
  File "/omd/sites/Azure/lib/python3/cmk/base/checking.py", line 796, in _aggregate_results
    perfdata, results = _consume_and_dispatch_result_types(subresults)
  File "/omd/sites/Azure/lib/python3/cmk/base/checking.py", line 840, in _consume_and_dispatch_result_types
    for subr in subresults:
  File "/omd/sites/Azure/lib/python3/cmk/base/api/agent_based/register/check_plugins.py", line 89, in filtered_generator
    for element in generator(*args, **kwargs):
  File "/omd/sites/Azure/local/lib/python3/cmk/base/plugins/agent_based/airfiber.py", line 41, in check_Ubiquiti
    if item[0].contains("low"):
AttributeError: 'str' object has no attribute 'contains'

SNMP Check Code

from .agent_based_api.v1 import *
from .agent_based_api.v1.type_defs import (
    CheckResult,
    DiscoveryResult,
)

register.snmp_section(
    name = "snmp_Ubiquiti",
    detect = startswith(".1.3.6.1.2.1.1.9.1.3.4", "Ubiquiti"),
    fetch = SNMPTree(
        base = '.1.3.6.1.4.1.41112.1.3.2.1',
        oids = [
            '41.1',
        ],
    ),
)

def discover_Ubiquiti(section) -> DiscoveryResult:
    for item in section:
        yield Service(item=item)

def check_Ubiquiti(params, section) -> CheckResult:
    for item in section:
        if item[0].contains("low"):
            yield Result(state=State.OK, summary="Found value")
            return
    yield Result(state=State.CRIT, summary="Not found")

register.check_plugin(
    name = "snmp_Ubiquiti",
    service_name = "Ubiquiti Test",
    discovery_function = discover_Ubiquiti,
    check_function = check_Ubiquiti,
    check_default_parameters={},
)

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.