Collection of CheckMK checks (see https://checkmk.com/). All checks and plugins are provided as is. Absolutely no warranty. Send any comments to thl-cmk[at]outlook[dot]com

Skip to content
Snippets Groups Projects
Commit 0fdfbd96 authored by thl-cmk's avatar thl-cmk :flag_na:
Browse files

fixed wrong snmp_section/inventory_plugin identifier

parent 4812df22
No related branches found
No related tags found
No related merge requests found
[PACKAGE]: ../../raw/master/mkp/inv_ifname-0.3.2-20250323.mkp "inv_ifname-0.3.2-20250323.mkp"
[PACKAGE]: ../../raw/master/mkp/inv_ifname-0.3.3-20250403.mkp "inv_ifname-0.3.3-20250403.mkp"
# inventory of interface names
adds the following to the inventory:
......
File added
......@@ -16,6 +16,10 @@
# 2024-04-19: refactoring for CMK2.3.0b5 (removed description/alias), only if_index is key column now again.
# 2024-07-22: detect function changed to check if IF-MIB::ifXTable.ifName exists
# 2025-03-23: modified for CMK 2.4.0x
# 2025-04-03: fixed wrong snmp_section/inventory_plugin identifier
# changed string_table to list, why???
# File "/omd/sites/build/lib/python3/cmk/base/api/agent_based/register/section_plugins.py", line 184, in _validate_type_list_snmp_trees
# raise TypeError("value of 'fetch' keyword must be SNMPTree or non-empty list of SNMPTrees")
# sample snmpwalk
# .1.3.6.1.2.1.31.1.1.1.1.1 = STRING: lo
......@@ -29,7 +33,7 @@
# .1.3.6.1.2.1.31.1.1.1.1.9 = STRING: bond1.3001
#
from typing import Mapping
from typing import Mapping, Sequence
from cmk.agent_based.v2 import (
InventoryPlugin,
InventoryResult,
......@@ -42,11 +46,14 @@ from cmk.agent_based.v2 import (
)
def parse_inv_ifname(string_table: StringTable) -> Mapping[int, str]:
return {int(if_index): if_name for if_index, if_name in string_table if if_name and if_index.isdigit()}
def parse_inv_if_name(string_table: Sequence[StringTable]) -> Mapping[int, str] | None:
try:
return {int(if_index): if_name for if_index, if_name in string_table[0] if if_name and if_index.isdigit()}
except IndexError:
return None
def inventory_inv_ifname(section: Mapping[int, str]) -> InventoryResult:
def inventory_inv_if_name(section: Mapping[int, str]) -> InventoryResult:
path = ['networking', 'interfaces']
for if_index, if_name in section.items():
yield TableRow(
......@@ -60,21 +67,22 @@ def inventory_inv_ifname(section: Mapping[int, str]) -> InventoryResult:
)
if_name_snmp_section = SNMPSection(
name='inv_ifname',
parse_function=parse_inv_ifname,
fetch= SNMPTree(
snmp_section_inv_if_name = SNMPSection(
name='inv_if_name',
parse_function=parse_inv_if_name,
fetch=[
SNMPTree(
base='.1.3.6.1.2.1.31.1.1.1', # IF-MIB::ifXTable
oids=[
OIDEnd(), # ifIndex
'1', # ifName
'1', # ifName
]
),
detect=exists('.1.3.6.1.2.1.31.1.1.1.1.*'),
)
],
detect=exists('.1.3.6.1.2.1.31.1.1.1.1.*')
)
if_name_inventory_plugin = InventoryPlugin(
name='inv_ifname',
inventory_function=inventory_inv_ifname,
inventory_plugin_if_name = InventoryPlugin(
name='inv_if_name',
inventory_function=inventory_inv_if_name,
)
......@@ -5,7 +5,7 @@
'web': ['plugins/views/inv_ifname.py']},
'name': 'inv_ifname',
'title': 'Add interface name to inventory',
'version': '0.3.2-20250323',
'version': '0.3.3-20250403',
'version.min_required': '2.3.0b4',
'version.packaged': 'cmk-mkp-tool 0.2.0',
'version.usable_until': '2.5.0b1'}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment