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

update project

parent ddbd5718
No related branches found
No related tags found
No related merge requests found
......@@ -9,28 +9,31 @@
#
# inventory of lldp cache
#
# 2016-05-24 : fix for empty capabilities
# 2017-07-03 : fixed neighbor port id as MAC address (HPE)
# 2018-01-24 : added local interface, removed 'useless' oid's
# 2018-09-04 : changes for CMK 1.5.x (inv_tree --> inv_tree_list)
# 2019-03-04 : changes for CMK 1.5.x --> if CMK1.5.x capability information is changed to string
# 2020-07-31 : added short interface name, code cleanup
# 2021-03-17 : rewrite for CMK 2.0
# 2001-03-18 : removed disable oprion from WATO
# 2016-05-24: fix for empty capabilities
# 2017-07-03: fixed neighbor port id as MAC address (HPE)
# 2018-01-24: added local interface, removed 'useless' oid's
# 2018-09-04: changes for CMK 1.5.x (inv_tree --> inv_tree_list)
# 2019-03-04: changes for CMK 1.5.x --> if CMK1.5.x capability information is changed to string
# 2020-07-31: added short interface name, code cleanup
# 2021-03-17: rewrite for CMK 2.0
# 2001-03-18: removed disable option from WATO
# 2021-03-22: workaround for oid_end != x.ifIndex.y (for Cisco UCS FIs / lbarbier[at]arkane-studios[dot]com)
# 2021-03-22: added handling of lldpchassisidsubtype 5 -> network address ipv4/ipv6
#
import re
from typing import List
from .agent_based_api.v1.type_defs import (
from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import (
StringTable,
InventoryResult,
)
from .agent_based_api.v1 import (
from cmk.base.plugins.agent_based.agent_based_api.v1 import (
OIDEnd,
)
from .agent_based_api.v1 import (
from cmk.base.plugins.agent_based.agent_based_api.v1 import (
register,
SNMPTree,
TableRow,
......@@ -81,11 +84,43 @@ def parse_inv_lldp_cache(string_table: List[StringTable]) -> list:
}
def render_mac_address(bytestring):
return ':'.join(['%02s' % hex(ord(m))[2:] for m in bytestring]).replace(' ', '0').upper()
def render_ip_address(bytestring):
if len(bytestring) == 17:
return bytestring
else:
return ':'.join(['%02s' % hex(ord(m))[2:] for m in bytestring]).replace(' ', '0').upper()
def render_networkaddress(bytestring):
if ord(bytestring[0]) == 1: # ipv4 address
return render_ipv4_address(bytestring[1:])
elif ord(bytestring[0]) == 2:
return render_ipv6_address(bytestring[1:])
else:
return bytestring
def render_ipv4_address(bytestring):
return '.'.join(['%s' % ord(m) for m in bytestring])
def shorten_ipv6_address(address):
address = address.split(':')
span = 2
address = [''.join(address[i:i + span]) for i in range(0, len(address), span)]
for m in range(0, len(address)):
address[m] = re.sub(r'^0{1,3}', r'', address[m])
address = ':'.join(address)
zeros = ':0:0:0:0:0:0:'
while not zeros == '':
if zeros in address:
address = re.sub(r'%s' % zeros, r'::', address)
zeros = ''
else:
zeros = zeros[:-2]
return address
def render_ipv6_address(bytestring):
address = ":".join(["%02s" % hex(ord(m))[2:] for m in bytestring]).replace(' ', '0').upper()
address = shorten_ipv6_address(address)
return address
def render_capabilities(bytestring):
if len(bytestring) == 0:
return []
......@@ -126,14 +161,20 @@ def parse_inv_lldp_cache(string_table: List[StringTable]) -> list:
for oid_end, lldpchassisidsubtype, lldpchassisid, lldpportidsubtype, lldpportid, lldpportdescription, \
lldpsystemname, lldpsystemdescription, ldpcapabilitiesmapsupported, lldpcachecapabilities in lldp_info:
local_ifindex = oid_end.split('.')[1]
local_port = 'unknown'
try:
local_ifindex = oid_end.split('.')[1]
except IndexError:
local_ifindex = oid_end.split('.')[0]
local_port = 'N/A'
for ifIndex, ifName in if_info:
if local_ifindex == ifIndex:
local_port = get_short_if_name(ifName)
if lldpchassisidsubtype == '4': # mac address
lldpchassisid = render_mac_address(lldpchassisid)
elif lldpchassisidsubtype == '5': # network address
lldpchassisid = render_networkaddress(lldpchassisid)
if lldpportidsubtype == '3': # macaddress
lldpportid = render_mac_address(lldpportid)
......@@ -157,9 +198,7 @@ def parse_inv_lldp_cache(string_table: List[StringTable]) -> list:
'capabilities_map_supported': render_capabilities(ldpcapabilitiesmapsupported),
'cache_capabilities': render_capabilities(lldpcachecapabilities),
}
neighbors.append(neighbor)
return neighbors
......@@ -186,10 +225,10 @@ def inventory_lldp_cache(params, section: list) -> InventoryResult:
if remove_domain:
if not domain_name == '':
neighbor['system_name'] = neighbor['system_name'].replace(domain_name, '')
neighbor['chassis_id'] = neighbor['chassis_id'].replace(domain_name, '')
# neighbor['chassis_id'] = neighbor['chassis_id'].replace(domain_name, '')
else:
neighbor['system_name'] = neighbor['system_name'].split('.')[0]
neighbor['chassis_id'] = neighbor['chassis_id'].split('.')[0]
# neighbor['chassis_id'] = neighbor['chassis_id'].split('.')[0] # it is some times a ipv4 address
key_columns = {
# 'system_name': neighbor['system_name'],
......
No preview for this file type
......@@ -18,5 +18,5 @@
'title': 'inventory for LLDP cache',
'version': '20210318.v05a',
'version.min_required': '2.0.0',
'version.packaged': '2.0.0',
'version.packaged': '2.0.0p1',
'version.usable_until': None}
\ No newline at end of file
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