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

update project

parent 0e04f7dd
No related branches found
No related tags found
No related merge requests found
[PACKAGE]: ../../raw/master/mkp/inv_cdp_cache-0.7.3-20240407.mkp "inv_cdp_cache-0.7.3-20240407.mkp"
[PACKAGE]: ../../raw/master/mkp/inv_cdp_cache-0.7.4-20240408.mkp "inv_cdp_cache-0.7.4-20240408.mkp"
# CDP inventory plugin
Adds the CDP information from network devices to the inventory
......
File added
......@@ -29,6 +29,11 @@
# 2024-04-05: fixed incomplete global cdp data (Meraki)
# 2024-04-07: fixed missing/empty global cdp data
# improved validation if SNMP input data
# fix crash on empty neighbour_name
# 2024-04-08: stop (early) if interface table can not be created
from dataclasses import dataclass
from typing import List
......@@ -192,6 +197,11 @@ def parse_inv_cdp_cache(string_table: List[StringByteTable]) -> Cdp | None:
except ValueError:
return
try:
interface_by_index = {if_index: if_name for if_index, if_name in if_info}
except ValueError:
return
try:
cdp_run, cdp_message_interval, cdp_hold_time, local_device_id, last_change = cdp_global[0]
except (ValueError, IndexError):
......@@ -213,11 +223,6 @@ def parse_inv_cdp_cache(string_table: List[StringByteTable]) -> Cdp | None:
neighbours = []
try:
interface_by_index = {if_index: if_name for if_index, if_name in if_info}
except ValueError:
interface_by_index = {}
for entry in cdp_info:
try:
oid_end, address_type, address, platform_details, device_id, device_port, platform, \
......@@ -225,48 +230,50 @@ def parse_inv_cdp_cache(string_table: List[StringByteTable]) -> Cdp | None:
except ValueError:
continue
if platform != '':
if_index = oid_end.split('.')[0]
local_port = interface_by_index.get(if_index, f'Index: {if_index}')
if address_type.isdigit():
address_type = int(address_type)
if address_type == 1: # ip address
address = _render_ip_address(address)
elif address_type == 65535: # HPE stack MAC address
address = _render_mac_address(address)
capabilities = _get_capabilities(capabilities)
if last_change.isdigit():
last_change = time.strftime(_TIME_FORMAT, time.localtime(time.time() - (int(last_change) / 100)))
if len(device_id) == 6:
# if device_id contains 'illegal' chars try to treat as mac address
# remove all chars from string, except allowedchars
allowed_chars = re.compile('[^a-zA-Z0-9_=\-\+\.\\\]')
clean_device_id = allowed_chars.sub('', device_id).strip()
if (clean_device_id != device_id) or (clean_device_id == ''):
device_id = _render_mac_address(device_id)
elif len(device_id) == 13 and device_id[6] == '-':
device_id = _sanitize_mac(device_id)
neighbours.append(CdpNeighbour(
address=address,
platform_details=platform_details,
neighbour_id=device_id,
neighbour_port=device_port,
local_port=local_port,
platform=platform,
capabilities=capabilities,
vtp_mgmt_domain=vtp_mgmt_domain,
native_vlan=native_vlan,
duplex=_get_cdp_duplex(duplex),
power_consumption=power_consumption,
last_change=last_change,
))
if platform == '':
continue
if_index = oid_end.split('.')[0]
local_port = interface_by_index.get(if_index, f'Index: {if_index}')
if address_type.isdigit():
address_type = int(address_type)
if address_type == 1: # ip address
address = _render_ip_address(address)
elif address_type == 65535: # HPE stack MAC address
address = _render_mac_address(address)
capabilities = _get_capabilities(capabilities)
if last_change.isdigit():
last_change = time.strftime(_TIME_FORMAT, time.localtime(time.time() - (int(last_change) / 100)))
if len(device_id) == 6:
# if device_id contains 'illegal' chars try to treat as mac address
# remove all chars from string, except allowedchars
allowed_chars = re.compile('[^a-zA-Z0-9_=\-\+\.\\\]')
clean_device_id = allowed_chars.sub('', device_id).strip()
if (clean_device_id != device_id) or (clean_device_id == ''):
device_id = _render_mac_address(device_id)
elif len(device_id) == 13 and device_id[6] == '-':
device_id = _sanitize_mac(device_id)
neighbours.append(CdpNeighbour(
address=address,
platform_details=platform_details,
neighbour_id=device_id,
neighbour_port=device_port,
local_port=local_port,
platform=platform,
capabilities=capabilities,
vtp_mgmt_domain=vtp_mgmt_domain,
native_vlan=native_vlan,
duplex=_get_cdp_duplex(duplex),
power_consumption=power_consumption,
last_change=last_change,
))
return Cdp(
cdp_global=global_info,
......@@ -303,7 +310,10 @@ def inventory_cdp_cache(params, section: Cdp) -> InventoryResult:
if params.get('domain_name'):
neighbour_id = neighbour_id.replace(params.get('domain_name', ''), '')
else:
neighbour_id = neighbour_id.split('.')[0]
try:
neighbour_id = neighbour_id.split('.')[0]
except AttributeError:
pass
neighbour_port = neighbour.neighbour_port
local_port = neighbour.local_port
......
......@@ -15,7 +15,7 @@
'web': ['plugins/views/inv_cdp_cache.py']},
'name': 'inv_cdp_cache',
'title': 'Inventory for Cisco CDP Cache',
'version': '0.7.3-20240407',
'version': '0.7.4-20240408',
'version.min_required': '2.2.0b1',
'version.packaged': '2.2.0p24',
'version.usable_until': None}
......@@ -13,9 +13,8 @@
# 2023-11-17: moved file back from local/lib/ structure to local/share/ structure to avoid errors in web.log
# 2023-12-21: streamlined LLDP and CDP view
from cmk.gui.views.inventory.registry import inventory_displayhints
from cmk.gui.i18n import _
from cmk.gui.views.inventory.registry import inventory_displayhints
inventory_displayhints.update({
'.networking.cdp_cache.': {
......
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