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!