Need help with snmp detect function

CMK version:2.4.0p24
OS version:Debian

Error message:Unimplemented check ascom_basic_check

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

I’m trying to build a check for ascom IPBS3 dect. As far as i understand is the detect function wrong and I can’t figure out why. Below is the code with im trying to test.

PS: the check when i test it works on a spohos firewall.

#!/usr/bin/env python3

from cmk.agent_based.v2 import (
    all_of,
    CheckPlugin,
    CheckResult,
    startswith,
    DiscoveryResult,
    Result,
    Service,
    SimpleSNMPSection,
    SNMPTree,
    State,
    StringTable,
    equals,
)

def parse_ascom(string_table):
    print(string_table)
    result = {}
    result["contact"] = string_table[0][0]
    result["name"] = string_table[0][1]
    result["location"] = string_table[0][2]
    print(result)
    return result

def discover_ascom(section):
    yield Service()

def check_ascom(section):
    missing = 0
    for e in ["contact", "name", "location"]:
        if section[e] == "":
            missing += 1
            yield Result(state=State.CRIT, summary=f"Missing information: {e}!")
    if missing > 0:
        yield Result(state=State.CRIT, summary=f"Missing fields: {missing}!")
    else:
        yield Result(state=State.OK, summary="All required information is available.")

snmp_section_ascom_setup_check = SimpleSNMPSection(
    name = "ascom_basic_config",
    parse_function = parse_ascom,
    detect = all_of(
            equals('.1.3.6.1.2.1.1.2.0', '.1.3.6.1.4.1.27614'),
            equals('.1.3.6.1.4.1.27614.1.1.1.3.1.0', 'IPBS3-A3/2A2'),
    ),
    fetch = SNMPTree(
        base = '.1.3.6.1.2.1.1',
        oids = ['4.0', '5.0', '6.0'],
    ),
)

check_plugin_ascom_setup_check = CheckPlugin(
    name = "ascom_basic_check",
    sections = [ "ascom_basic_config" ],
    service_name = "Ascom basic check",
    discovery_function = discover_ascom,
    check_function = check_ascom,
)

Output of the SNMPwalk for the OIDs used.

#.1.3.6.1.2.1.1.1.0  IPBS3[13.1.2], Bootcode[13.1.2], Hardware[IPBS3-A3/2A2]
#.1.3.6.1.2.1.1.2.0 .1.3.6.1.4.1.27614
#.1.3.6.1.2.1.1.3.0 188486800
#.1.3.6.1.2.1.1.4.0 it@xxxxxxx.com
#.1.3.6.1.2.1.1.5.0 BS01_XXX_XXXX
#.1.3.6.1.2.1.1.2.0 .1.3.6.1.4.1.2761
#.1.3.6.1.4.1.27614.1.1.1.3.1.0 IPBS3-A3/2A2

I gave your plugin a quick test run, it looks good so far.
The only issu with the discovery was the caching of cmk. Here a omd restart automation-helper as site user helps.

You can check on the CLI if your plugin works by doing a discovery like so

cmk -vII <your-ascom-host-name>

Sould look like this (I have removed the print command from your code)

OMD[build]:~$ cmk --debug -vII ascom
Discovering services and host labels on: ascom
ascom:
+ FETCHING DATA
Get piggybacked data
+ ANALYSE DISCOVERED HOST LABELS
SUCCESS - Found no host labels
+ ANALYSE DISCOVERED SERVICES
+ EXECUTING DISCOVERY PLUGINS (4)
  1 ascom_basic_check
  1 snmp_info
  1 uptime
SUCCESS - Found 3 services

If this works, after a restart of the automation-helper, it sould also work in the UI.

The rest of the plugin, I have not tested

cheers
thomas

Regarding the detect function I would reduce it to the first “equals” statement. The idea behind a detect function is not to request additional OIDs, but use OIDs needed by multiple checks.

THX for the Help

Using “exists” solved the problem

Now i have a diferent problem with my check.

Any idea how i can check an OID that returns an empty value by design?

Hello!

If one of the answers helped you solve your question, please mark it as the solution. This way, you thank the person who helped you and also indicate that the question has been resolved. This, in turn, helps others who come across the same question.

Thank you!