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 93c34df0 authored by thl-cmk's avatar thl-cmk :flag_na:
Browse files

update project

parent bce78154
No related branches found
No related tags found
No related merge requests found
[PACKAGE]: ../../raw/master/mkp/inv_lldp_cache-0.9.3-20240320.mkp "inv_lldp_cache-0.9.3-20240320.mkp"
[PACKAGE]: ../../raw/master/mkp/inv_lldp_cache-0.9.4-20240405.mkp "inv_lldp_cache-0.9.4-20240405.mkp"
# LLDP inventory plugin
Adds the LLDP information from network devices to the inventory
......
File added
......@@ -26,9 +26,11 @@
# 2023-02-16: replaced TypedDic (Neighbour) with Dict, removed Dataclass --> wasn't working in CMK 2.1
# 2023-02-17: moved wato/metrics from ~/local/share/.. to ~/local/lib/... for CMK2.1
# 2023-10-13: refactoring: render ipv4/ipv6/mac address
# fixed handling sub types for chassis and ports
# fixed handling sub types for chassis and ports
# 2023-12-21: streamlined LLDP and CDP inventory
# 2024-03-20: added host label nvdct/has_lldp_neighbours:yes if the device has at least one lldp neighbour
# 2024-04-05: drop neighbours without chassis id
# drop invalid MAC addresses (length != 6)
#
from dataclasses import dataclass
......@@ -55,6 +57,7 @@ from cmk.base.plugins.agent_based.agent_based_api.v1 import (
register,
)
_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S.%m'
_interface_displayhints = {
'ethernet': 'eth',
......@@ -115,8 +118,8 @@ _lldp_capabilities = {
@dataclass(frozen=True)
class LldpGlobal:
local_id: str
local_name: str
local_id: str | None
local_name: str | None
@dataclass(frozen=True)
......@@ -195,20 +198,18 @@ def _render_capabilities(bytes_):
def _render_chassis_id(chassis_id_sub_type: str, chassis_id: str) -> str:
if chassis_id_sub_type == '4' and len(chassis_id) == 6: # mac address
chassis_id = _render_mac_address(chassis_id)
if chassis_id_sub_type == '4': # drop if incorrect data and len(chassis_id) == 6: # mac address
return _render_mac_address(chassis_id)
elif chassis_id_sub_type == '5': # network address
chassis_id = _render_networkaddress(chassis_id)
return _render_networkaddress(chassis_id)
else:
chassis_id = ''.join(chr(m) for m in chassis_id)
return chassis_id
return ''.join(chr(m) for m in chassis_id)
def parse_inv_lldp_cache(string_table: List[StringByteTable]) -> Lldp:
lldp_info, if_info, lldp_global, lldp_mgmt_addresses = string_table
mgmt_addresses = [oud_end for oud_end, lldp_rem_man_addr_if_subtype in lldp_mgmt_addresses]
mgmt_addresses = [oid_end for oid_end, lldp_rem_man_addr_if_subtype in lldp_mgmt_addresses]
global_chassis_id_type, global_chassis_id, global_system_name = lldp_global[0]
......@@ -226,6 +227,12 @@ def parse_inv_lldp_cache(string_table: List[StringByteTable]) -> Lldp:
for oid_end, chassis_id_sub_type, chassis_id, port_id_sub_type, port_id, port_description, \
neighbour_name, system_description, capabilities_map_supported, cache_capabilities in lldp_info:
# skip neighbours chassis id
if not chassis_id:
continue
chassis_id = _render_chassis_id(chassis_id_sub_type, chassis_id)
neighbour_address = ''
for mgmt_address in mgmt_addresses:
if mgmt_address.startswith(oid_end):
......@@ -257,9 +264,7 @@ def parse_inv_lldp_cache(string_table: List[StringByteTable]) -> Lldp:
else:
local_port = ''.join(chr(m) for m in interface['if_name'])
chassis_id = _render_chassis_id(chassis_id_sub_type, chassis_id)
if port_id_sub_type == '3' and len(port_id) == 6: # mac address
if port_id_sub_type == '3': # drop if incorrect data and len(port_id) == 6: # mac address
port_id = _render_mac_address(port_id)
elif port_id_sub_type in ['5', '7']: # network address, local
port_id = _render_networkaddress(port_id)
......@@ -294,10 +299,11 @@ def inventory_lldp_cache(params, section: Lldp) -> InventoryResult:
yield Attributes(
path=path,
inventory_attributes={
'local_id': section.lldp_global.local_id,
'local_name': section.lldp_global.local_name,
**({"local_id": section.lldp_global.local_id} if section.lldp_global.local_id else {}),
**({"local_name": section.lldp_global.local_name} if section.lldp_global.local_name else {}),
}
)
path = path + ['neighbours']
for neighbour in section.lldp_neighbours:
......
......@@ -17,7 +17,7 @@
'web': ['plugins/views/inv_lldp_cache.py']},
'name': 'inv_lldp_cache',
'title': 'inventory for LLDP cache',
'version': '0.9.3-20240320',
'version': '0.9.4-20240405',
'version.min_required': '2.2.0b1',
'version.packaged': '2.2.0p17',
'version.packaged': '2.2.0p24',
'version.usable_until': None}
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