SNMP-Plugin: Struggle to fetch a list of SNMPTrees

CMK version: 2.4.0p17

Error message: TypeError: value of ‘fetch’ keyword must be SNMPTree or non-empty list of SNMPTrees

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

Trying to acquire lock on /omd/sites/fstest/var/check_mk/crashes/base/d4ad510c-fd12-11f0-afb3-005056b3c57a/crash.info
Got lock on /omd/sites/fstest/var/check_mk/crashes/base/d4ad510c-fd12-11f0-afb3-005056b3c57a/crash.info
Releasing lock on /omd/sites/fstest/var/check_mk/crashes/base/d4ad510c-fd12-11f0-afb3-005056b3c57a/crash.info
Released lock on /omd/sites/fstest/var/check_mk/crashes/base/d4ad510c-fd12-11f0-afb3-005056b3c57a/crash.info
Traceback (most recent call last):
File “/omd/sites/fstest/bin/cmk”, line 135, in
errors = config.load_all_plugins(
^^^^^^^^^^^^^^^^^^^^^^^^
File “/omd/sites/fstest/lib/python3/cmk/base/config.py”, line 1421, in load_all_plugins
errors = agent_based_register.load_all_plugins(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/omd/sites/fstest/lib/python3.12/contextlib.py”, line 81, in inner
return func(*args, **kwds)
^^^^^^^^^^^^^^^^^^^
File “/omd/sites/fstest/lib/python3/cmk/base/api/agent_based/register/_discover.py”, line 76, in load_all_plugins
_register_plugin_by_type(location, plugin, validate=raise_errors)
File “/omd/sites/fstest/lib/python3/cmk/base/api/agent_based/register/_discover.py”, line 112, in _register_plugin_by_type
register_snmp_section(plugin, location, validate=validate)
File “/omd/sites/fstest/lib/python3/cmk/base/api/agent_based/register/_discover.py”, line 146, in register_snmp_section
section_plugin = create_snmp_section_plugin(section, location, validate=validate)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/omd/sites/fstest/lib/python3/cmk/base/api/agent_based/register/section_plugins.py”, line 290, in create_snmp_section_plugin
_validate_fetch_spec(snmp_section_spec.fetch)
File “/omd/sites/fstest/lib/python3/cmk/base/api/agent_based/register/section_plugins.py”, line 190, in _validate_fetch_spec
_validate_type_list_snmp_trees(trees)
File “/omd/sites/fstest/lib/python3/cmk/base/api/agent_based/register/section_plugins.py”, line 186, in _validate_type_list_snmp_trees
raise TypeError(“value of ‘fetch’ keyword must be SNMPTree or non-empty list of SNMPTrees”)
TypeError: value of ‘fetch’ keyword must be SNMPTree or non-empty list of SNMPTrees

Hi everyone,

I’m trying to write a SNMP-Plugin and I’m struggling fetching multiple SNMPTrees. As far as I can see this should be a non-empty list of SNMPTrees or am I missing something?

snmp_section_lynx_cards = SimpleSNMPSection(
    name = "lynx_cards",
    parse_function = parse_lynx_cards,
    detect = startswith(".1.3.6.1.2.1.1.2.0", ".1.3.6.1.4.1.14755"),
    fetch = [
        SNMPTree(base=".1.3.6.1.4.1.14755.2.1490.588.1.1", oids=[OIDEnd(), "2", "3", "9"]),
        SNMPTree(base=".1.3.6.1.4.1.14755.2.2001.403.1.1", oids=[OIDEnd(), "2", "3", "9"]),
        SNMPTree(base=".1.3.6.1.4.1.14755.2.2004.503.1.1", oids=[OIDEnd(), "2", "3", "9"]),
        SNMPTree(base=".1.3.6.1.4.1.14755.2.2016.1119.1.1", oids=[OIDEnd(), "2", "3", "9"]),
        SNMPTree(base=".1.3.6.1.4.1.14755.2.2016.1122.1.1", oids=[OIDEnd(), "2", "3", "9"]),
        SNMPTree(base=".1.3.6.1.4.1.14755.2.2028.568.1.1", oids=[OIDEnd(), "2", "3", "9"]),
        SNMPTree(base=".1.3.6.1.4.1.14755.2.2032.626.1.1", oids=[OIDEnd(), "2", "3", "9"]),
        SNMPTree(base=".1.3.6.1.4.1.14755.2.2243.526.1.1", oids=[OIDEnd(), "2", "3", "9"]),
        SNMPTree(base=".1.3.6.1.4.1.14755.2.2258.704.1.1", oids=[OIDEnd(), "2", "3", "9"]),
        SNMPTree(base=".1.3.6.1.4.1.14755.2.2259.619.1.1", oids=[OIDEnd(), "2", "3", "9"]),
        ]
)

When testing with a single SNMPTree it works.

Best Regards
Florian

You need to use SNMPSection instead of SimpleSNMPSection.

SimpleSNMPSection can only contain one SNMPTree.

2 Likes

That fixed it, thank you so much!

1 Like