Service discovered with UNKNOWN status

I have made a small check plugin for checking the status of a remote device using SNMP. I have added debugging to check that I am getting data, it is working well, except that the Service always shows up as a vanished service with status “UNKN”.

The following file I “install” in cmk using the command install -m755 /tmp/device_info.py ~/local/lib/python3/cmk/base/plugins/agent_based/ without any issue. The name device_info is just a placeholder name, I use a unique name in reality.

from .agent_based_api.v1 import (
    register, SNMPTree, contains, Service, Result, State
)
from cmk.utils import debug
from pprint import pprint

def parse_device_info(string_table):
    if debug.enabled():
        pprint("Parsing")
        pprint(string_table)

    return string_table[0]

register.snmp_section(
    name="device_info",
    parse_function=parse_device_info,
    detect=contains(".1.2.3.4.5.0", ".5.4.3.2.1.12345"),
    fetch=SNMPTree(
        base=".5.4.3.2.1.12345",
        oids=[
            "1.1",
            "1.2",
        ],
    ),
)

def discovery_device_info(section):
    if debug.enabled():
        pprint('Discovered')
    yield Service()

def check_device_info(section):
    if debug.enabled():
        print('Checking')
        pprint(section)
    yield Result(state=State.OK, summary="Device is of type %s" % section[0])

register.check_plugin(
    name="device_info",
    service_name="Device info",
    discovery_function=discovery_device_info,
    check_function=check_device_info,
)

To test out this plugin I execute:

>>> cmk --debug --detect-plugins device_info --II <HOSTNAME>
'Parsing'
[['v1', '12345']]
'Discovered'

This makes this service show up in CMK UI as a vanished service with Status UNKN. The clue from the debug is that the printout in ‘check_function’ is never printed, which must mean the function is never called. Now the issue is that I cannot understand why it is not called, and was hoping for a simple explanation of what I am doing wrong.

Many thanks!

I am still in desperate need for any idea or suggestion on what I am doing wrong. Is there additional information needed in order to determine what is the cause?

When you call “cmk” with “-I” only the discovery function is called.
I don’t currently see an obvious error in your code, but you can check with
"cmk --debug -v " after you discoverd your service if your print statements show up and maybe this helps?

Thank you, when I execute cmk --debug -v <HOSTNAME> there are no print statements. If I also add --detect-plugins device_info the result is the same.

>> cmk --debug -v <HOSTNAME>
+ FETCHING DATA
[SNMPFETCHER] Execute data source
[PiggybackFetcher] Execute data source
No piggyback files for <HOSTNAME>
No piggyback files for <HOSTIP>
+ PARSE FETCHER RESULTS
Received no piggyback data
[snmp] Success, execution time 0.0 sec | .....

Can you share the full original code (or replace a little less?) I’m not sure if maybe the changes in the OIDs, Variable names etc hid the problem…

also, maybe add a second “-v” to see if the snmp output yields anything.
An execution time of 0.0 seems like your device is not even contacted.

The only things I have changed are the oids. It could happen that the device was not reachable earlier. Now it is showing SNMP results, amongst them, the oids I have specified, and a lot of other oids. And the service is showing up with an OK status. It might have been a timeout issue all along, which there was not really any indication of in the calls. I changed the timeout for snmp calls to 10 seconds but fewer retries, and now it appears to be running smoothly…