CMK version: 2.2.0p34 CEE
OS version: Ubuntu 22.04.5
Hello anyone,
at the work, we need to read a special info from a networkdevice. The info is deliver from the device with snmp - CheckMK dont know what to do with it.
To get the info in the monitoring, I writed a snmp plugin by my self. The problem is, i cant test it, because CheckMK doent know his own module?
When executing the script, I made sure that it is CheckMK’s Python that executes the module. However, this did not help.
Script:
#!/usr/bin/env python3
from cmk.agent_based.v2 import (
CheckPlugin,
CheckResult,
startswith,
DiscoveryResult,
Result,
Service,
SimpleSNMPSection,
SNMPTree,
State,
StringTable,
)
def parse_vpnsumup(data) -> str:
return data
def discover_vpnsumup(data) -> str:
yield Service()
def check_vpnsumup(data) -> str:
if data == "":
yield Result(state=State.CRIT, summary=f"Crit.")
elif data == 0:
yield Result(state=State.INFO, summary=f"Info.")
else:
yield Result(state=State.OK, summary=f"Ok.")
snmp_section_flintstone_setup = SimpleSNMPSection(
name = "vpnsumup_snmp_config",
parse_function = parse_vpnsumup,
detect = all_of(
startswith(".0.0.0", "text"),
startswith(".0.0.0", "text"),
exists(".0.0.0"),
),
fetch = SNMPTree(
base = ".0.0.0"
),
)
check_plugin__vpnsumup = CheckPlugin(
name = "vpnsumup_snmp_scan",
sections = [ "vpnsumup" ],
service_name = "vpnsumup",
discovery_function = discover_vpnsumup,
check_function = check_vpnsumup,
)
As template, I have take the offical docu from CheckMk, see for more infos the link below.
SNMP-basierte Check-Plugins schreiben
Path:
OMD[prod]:~/local/lib/python3/cmk_addons/plugins/genua/agent_based$ ll
total 4
-rwx------ 1 prod prod 2331 Sep 27 09:59 vpnsumup.py*
Execution:
OMD[prod]:~/local/lib/python3/cmk_addons/plugins/genua/agent_based$ ./vpnsumup.py
Error message:
Traceback (most recent call last):
File "/opt/omd/sites/prod/local/lib/python3/cmk_addons/plugins/genua/agent_based/./vpnsumup.py", line 21, in <module>
from cmk.agent_based.v2 import (
ModuleNotFoundError: No module named 'cmk.agent_based'
Does anyone have an idea?
With best Regards
Alphabeit