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

update project

parent 92056943
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@
# inventory of lldp cache
#
# 2016-05-24: fix for empty capabilities
# 2017-07-03: fixed neighbor port id as MAC address (HPE)
# 2017-07-03: fixed neighbour 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
......@@ -19,7 +19,7 @@
# 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
#
# 2021-07-10: made use short interface names configurable via wato
import re
from typing import List
......@@ -40,6 +40,35 @@ from cmk.base.plugins.agent_based.agent_based_api.v1 import (
exists,
)
_interface_displayhints = {
'ethernet': 'eth',
'fastethernet': 'Fa',
'gigabitethernet': 'Gi',
'tengigabitethernet': 'Te',
'fortygigabitethernet': 'Fo',
'hundredgigabitethernet': 'Hu',
'port-channel': 'Po',
'tunnel': 'Tu',
'loopback': 'Lo',
'cellular': 'Cel',
'vlan': 'Vlan',
'management': 'Ma',
}
def _get_short_if_name(ifname: str) -> str:
"""
returns short interface name from long interface name
ifname: is the long interface name
:type ifname: str
"""
for ifname_prefix in _interface_displayhints.keys():
if ifname.lower().startswith(ifname_prefix.lower()):
ifname_short = _interface_displayhints[ifname_prefix]
return ifname.lower().replace(ifname_prefix.lower(), ifname_short, 1)
return ifname
def parse_inv_lldp_cache(string_table: List[StringTable]) -> list:
lldp_chassisidsubtype = {
......@@ -136,27 +165,9 @@ def parse_inv_lldp_cache(string_table: List[StringTable]) -> list:
# print (bytestring , '/' , capabilities)
return capabilities
def get_short_if_name(st):
names = {'ethernet': 'Eth',
'fastethernet': 'Fa',
'gigabitethernet': 'Gi',
'tengigabitethernet': 'Te',
'fortygigabitethernet': 'Fo',
'hundredgigabitethernet': 'Hu',
'port-channel': 'Po',
'tunnel': 'Tu',
'loopback': 'Lo',
}
for item in names.keys():
if st.lower().startswith(item):
st = st.lower().replace(item, names.get(item))
return st
lldp_info, if_info = string_table
# print(len(lldp_info))
neighbors = []
neighbours = []
for oid_end, lldpchassisidsubtype, lldpchassisid, lldpportidsubtype, lldpportid, lldpportdescription, \
lldpsystemname, lldpsystemdescription, ldpcapabilitiesmapsupported, lldpcachecapabilities in lldp_info:
......@@ -169,7 +180,7 @@ def parse_inv_lldp_cache(string_table: List[StringTable]) -> list:
local_port = 'N/A'
for ifIndex, ifName in if_info:
if local_ifindex == ifIndex:
local_port = get_short_if_name(ifName)
local_port = ifName
if lldpchassisidsubtype == '4': # mac address
lldpchassisid = render_mac_address(lldpchassisid)
......@@ -188,24 +199,25 @@ def parse_inv_lldp_cache(string_table: List[StringTable]) -> list:
if (cleanport_id != lldpportid) or (cleanport_id == ''):
lldpportid = render_mac_address(lldpportid)
neighbor = {
neighbour = {
'local_port_num': local_port,
'chassis_id': lldpchassisid,
'port_id': get_short_if_name(lldpportid),
'port_id': lldpportid,
'port_description': lldpportdescription,
'system_name': lldpsystemname,
'system_description': lldpsystemdescription,
'capabilities_map_supported': render_capabilities(ldpcapabilitiesmapsupported),
'cache_capabilities': render_capabilities(lldpcachecapabilities),
}
neighbors.append(neighbor)
return neighbors
neighbours.append(neighbour)
return neighbours
def inventory_lldp_cache(params, section: list) -> InventoryResult:
removecolumns = []
remove_domain = False
domain_name = ''
use_short_if_name = False
# get parameters from wato
if params:
......@@ -213,34 +225,40 @@ def inventory_lldp_cache(params, section: list) -> InventoryResult:
removecolumns = params.get('removecolumns', removecolumns)
remove_domain = params.get('remove_domain', remove_domain)
domain_name = params.get('domain_name', domain_name)
use_short_if_name = params.get('use_short_if_name', use_short_if_name)
path= ['networking', 'lldp_cache']
for neighbor in section:
for neighbour in section:
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, '')
neighbour['system_name'] = neighbour['system_name'].replace(domain_name, '')
# neighbour['chassis_id'] = neighbour['chassis_id'].replace(domain_name, '')
else:
neighbor['system_name'] = neighbor['system_name'].split('.')[0]
# neighbor['chassis_id'] = neighbor['chassis_id'].split('.')[0] # it is some times a ipv4 address
neighbour['system_name'] = neighbour['system_name'].split('.')[0]
# neighbour['chassis_id'] = neighbour['chassis_id'].split('.')[0] # it is some times a ipv4 address
if use_short_if_name:
neighbour['port_id'] = _get_short_if_name(neighbour['port_id'])
neighbour['local_port'] = _get_short_if_name(neighbour['local_port'])
key_columns = {
# 'system_name': neighbor['system_name'],
'chassis_id': neighbor['chassis_id'],
'port_id': neighbor['port_id'],
'local_port_num': neighbor['local_port_num'],
# 'system_name': neighbour['system_name'],
'chassis_id': neighbour['chassis_id'],
'port_id': neighbour['port_id'],
'local_port_num': neighbour['local_port_num'],
}
for key in key_columns.keys():
neighbor.pop(key)
neighbour.pop(key)
for entry in removecolumns:
neighbor.pop(entry)
neighbour.pop(entry)
yield TableRow(
path=path,
key_columns=key_columns,
inventory_columns=neighbor
inventory_columns=neighbour
)
......
No preview for this file type
......@@ -33,15 +33,6 @@ def _valuespec_inv_lldp_cache():
return Dictionary(
title=_('LLDP cache'),
elements=[
# not needed any more, you can disable the inventory plugin via:
# Setup -> Agents -> SNMP rules -> Disabled or enabled sections (SNMP)
# ('disable',
# FixedValue(
# True,
# title=_('Do not add LLDP cache to the inventory'),
# totext=_('LLDP cache will not be added to the inventory'),
# default_value=False,
# )),
('remove_domain',
FixedValue(
True,
......@@ -62,6 +53,13 @@ def _valuespec_inv_lldp_cache():
choices=removecolumns,
default_value=[],
)),
('use_short_if_name',
FixedValue(
True,
title=_('use short interface names (i.e. Gi0/0 for GigabitEthernet0/0)'),
totext=_('use short interface names enabled'),
default_value=False,
)),
],
)
......
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