CMK version: 2.2.0p23 MSP
OS version: Ubuntu 22.04 LTS
We’re trying to monitor our Fortiweb through SNMP. Sadly out of the box it does not recognize memory and CPU usage the way CheckMK does for Fortigates.
We’re trying to build a custom python script, but are very new when it comes to both Python & SNMP. We’ve been following the guide and looking at other python SNMP plugins to figure this out.
We keep getting the error:
Error in plugin file /omd/sites/US01/local/share/check_mk/checks/fortiweb_memory.py: No module named ‘cmk.agent_based’
Error in agent based plugin fortiweb_memory: No module named ‘cmk.agent_based’
Our custom plugin:
#!/usr/bin/env python3
# This file is explained in the Checkmk User Guide:
# https://docs.checkmk.com/master/en/devel_check_plugins_snmp.html#scaffold
#
# Store in your Checkmk site at:
# local/lib/python3/cmk_addons/plugins/flintstone_setup_check/agent_based/flintstone_setup_check.py
from cmk.agent_based.v2 import (
CheckPlugin,
CheckResult,
startswith,
DiscoveryResult,
Result,
Service,
SimpleSNMPSection,
SNMPTree,
State,
StringTable,
)
def parse_fortiweb(string_table):
return {}
def discover_fortiweb(section):
yield Service()
def check_fortiweb(section):
yield Result(state=State.OK, summary="Everything is fine")
snmp_section_fortiweb_setup = SimpleSNMPSection(
name = "fortiweb_base_config",
parse_function = parse_fortiweb,
detect = startswith(".1.3.6.1.2.1.1.1.0", "fortiweb-us"),
fetch = SNMPTree(base='.1.3.6.1.4.1.12356.107.2.1', oids=['7.0']),
)
check_plugin__fortiweb_memory = CheckPlugin(
name = "fortiweb_memory",
sections = [ "fortiweb_base_config" ],
service_name = "fortiweb setup check",
discovery_function = discover_fortiweb,
check_function = check_fortiweb,
)
#.1.3.6.1.2.1.1.1.0 fortiweb-us --> SNMPv2-MIB::sysDescr.0
#.1.3.6.1.4.1.12356.107.2.1.7.0 41 --> FORTINET-FORTIWEB-MIB::fwSysMemUsage.0
#.1.3.6.1.4.1.12356.107.2.1.8.0 8025 --> FORTINET-FORTIWEB-MIB::fwSysMemCapacity.0
Error message of --debug -vvn:
OMD[US01]:~$ cmk --debug -vvn Fortiweb-US
Trying to acquire lock on /omd/sites/US01/var/check_mk/crashes/base/f89df7aa-4437-11ef-93a5-d754f1109228/crash.info
Got lock on /omd/sites/US01/var/check_mk/crashes/base/f89df7aa-4437-11ef-93a5-d754f1109228/crash.info
Releasing lock on /omd/sites/US01/var/check_mk/crashes/base/f89df7aa-4437-11ef-93a5-d754f1109228/crash.info
Released lock on /omd/sites/US01/var/check_mk/crashes/base/f89df7aa-4437-11ef-93a5-d754f1109228/crash.info
Traceback (most recent call last):
File "/omd/sites/US01/bin/cmk", line 97, in <module>
errors = config.load_all_agent_based_plugins(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/omd/sites/US01/lib/python3/cmk/base/config.py", line 1661, in load_all_agent_based_plugins
errors = agent_based_register.load_all_plugins()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/omd/sites/US01/lib/python3/cmk/base/api/agent_based/register/__init__.py", line 48, in load_all_plugins
raise exception
File "/omd/sites/US01/lib/python3/cmk/utils/plugin_loader.py", line 49, in load_plugins_with_exceptions
importlib.import_module(full_name)
File "/omd/sites/US01/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/omd/sites/US01/local/lib/python3/cmk/base/plugins/agent_based/fortiweb_memory.py", line 8, in <module>
from cmk.agent_based.v2 import (
ModuleNotFoundError: No module named 'cmk.agent_based'
Error message when testing detection of the plugin:
OMD[US01]:~/local/lib/check_mk/base/plugins/agent_based$ cmk -vI --detect-plugins=fortiweb_memory.py Fortiweb-US
Error in plugin file /omd/sites/US01/local/share/check_mk/checks/fortiweb_memory.py: No module named 'cmk.agent_based'
Error in agent based plugin fortiweb_memory: No module named 'cmk.agent_based'
Discovering services and host labels on: Fortiweb-US
Fortiweb-US:
+ FETCHING DATA
[SNMPFetcher] Execute data source
[PiggybackFetcher] Execute data source
No piggyback files for 'Fortiweb-US'. Skip processing.
No piggyback files for '10.126.0.130'. Skip processing.
+ ANALYSE DISCOVERED HOST LABELS
SUCCESS - Found no new host labels
+ ANALYSE DISCOVERED SERVICES
+ EXECUTING DISCOVERY PLUGINS (0)
SUCCESS - Found no new services