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

cleanup

parents
No related branches found
No related tags found
No related merge requests found
# LLDP inventory plugin
Adds the LLDP information from networkd evices to the inventory
* *wato*:
* you can disable the inventory plugin
* you can remove not needed columns from the inventory
* you can remove the domain name from the neighbour device name
**Testetd with**: Cisco and HP
**Note**: starting with CheckMK 1.5.x you need to remove *Capabilities map supported* and *Cache Capabilities* from the inventory (see WATO)
Sample output
![sample output](/doc/sample.png?raw=true "sample [SHORT TITLE]")
doc/sample.png

84.7 KiB

File added
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
#
# inventory of lldp cache
#
# Author: Th.L. thl-cmk[at]outlook[dot]com
# Date : 2016-04-16
#
# 24.05.2016 : fix for empty capabilities
# 03.07.2017 : fixed neighbor port id as MAC address (HPE)
# 24.01.2018 : added local interface, removed 'useless' oid's
# 04.09.2018 : changes for CMK 1.5.x (inv_tree --> inv_tree_list)
# 04.03.2019 : changes for CMK 1.5.x --> if CMK1.5.x capability information is changed to string
def inv_lldp_cache(info, params):
removecolumns = []
remove_domain = False
domain_name = ''
# get parameters from wato
if params:
# do nothing if disabled via vato
if params.get('disable', False) is True:
return
# get list of columns to remove from inventory
removecolumns = params.get('removecolumns', removecolumns)
remove_domain = params.get('remove_domain', remove_domain)
domain_name = params.get('domain_name', domain_name)
lldp_chassisidsubtype = {
0: 'n/a',
1: 'chassiscomponent',
2: 'interfacealias',
3: 'portcomponent',
4: 'macaddress',
5: 'networkaddress',
6: 'interfacename',
7: 'local',
}
lldp_portidsubtype = {
0: 'n/a',
1: 'interfacealias',
2: 'portcomponent',
3: 'macaddress',
4: 'networkaddress',
5: 'interfacename',
6: 'agentcircuitid',
7: 'local',
}
lldp_manaddrifsubtype = {
0: 'n/a',
1: 'unknown',
2: 'ifindex',
3: 'systemportnumber',
}
lldp_capabilities = {
0: '',
1: 'other',
2: 'Repeater',
4: 'Bridge',
8: 'WLAN AP',
16: 'Router',
32: 'Phone',
64: 'DOCSIS',
128: 'Station',
}
def render_mac_address(bytestring):
return ':'.join(['%02s' % hex(ord(m))[2:] for m in bytestring]).replace(' ', '0').upper()
def render_ip_address(bytestring):
return '.'.join(['%s' % ord(m) for m in bytestring])
def render_time(uptime_sec):
uptime_sec = int(uptime_sec)
hunsdertstelsec = uptime_sec % 100
rem = uptime_sec / 100
seconds = rem % 60
rem = rem / 60
minutes = rem % 60
hours = (rem % 1440) / 60
days = rem / 1440
since = time.strftime('%c', time.localtime(time.time() - (uptime_sec / 100)))
# return ('%dd %02d:%02d:%02d.%02d' % (days, hours, minutes, seconds, hunsdertstelsec))
return since
def render_capabilities(bytestring):
if len(bytestring) == 0:
return []
cpapabilites = []
for x in lldp_capabilities:
tempcap = lldp_capabilities.get(saveint(ord(bytestring[0])) & x)
if tempcap != '':
cpapabilites.append(tempcap)
# in CMK v1.5.x global variable g_hostname was replaced by API call host_name()
# used to fin out if we run on cmk 1.4.x or 1.5.x, there should be someting like get_version()
try:
hostname = host_name()
capabilities = str(', '.join(capabilities))
except NameError:
pass
return cpapabilites
node = inv_tree_list('networking.lldp_cache:')
lldp_info, if_info = info
for oid_end, lldpchassisidsubtype, lldpchassisid, lldpportidsubtype, lldpportid, lldpportdescription, \
lldpsystemname, lldpsystemdescription, ldpcapabilitiesmapsupported, lldpcachecapabilities in lldp_info:
local_ifindex = oid_end.split('.')[1]
local_port = 'unknown'
for ifIndex, ifDescr in if_info:
if local_ifindex == ifIndex:
local_port = ifDescr
if lldp_chassisidsubtype.get(saveint(lldpchassisidsubtype)) == 'macaddress':
lldpchassisid = render_mac_address(lldpchassisid)
if saveint(lldpportidsubtype) == lldp_portidsubtype.get('macaddress'):
lldpportid = render_mac_address(lldpportid)
if len(lldpportid) == 6:
# if lldpportid contains 'illegal' signs try to treat as mac address
# remove all chars from string, except allowedchars
allowedchars = re.compile('[^a-zA-Z0-9_=\-\+\.\\\/]')
cleanport_id = allowedchars.sub('', lldpportid).strip()
if (cleanport_id != lldpportid) or (cleanport_id == ''):
lldpportid = render_mac_address(lldpportid)
if remove_domain:
if not domain_name == '':
lldpsystemname = lldpsystemname.replace(domain_name, '')
lldpchassisid = lldpchassisid.replace(domain_name, '')
else:
lldpsystemname = lldpsystemname.split('.')[0]
lldpchassisid = lldpchassisid.split('.')[0]
node.append({
'local_port_num' : local_port,
'chassis_id' : lldpchassisid,
'port_id' : lldpportid,
'port_description' : lldpportdescription,
'system_name' : lldpsystemname,
'system_description' : lldpsystemdescription,
'capabilities_map_supported': render_capabilities(ldpcapabilitiesmapsupported),
'cache_capabilities' : render_capabilities(lldpcachecapabilities),
})
# remove disabled columns
if removecolumns is not None:
for i in node:
for column in removecolumns:
if i.get(column) is not None:
i.pop(column)
return node
inv_info['inv_lldp_cache'] = {
'inv_function' : inv_lldp_cache,
'snmp_info' : [('.1.0.8802.1.1.2.1.4.1.1', [ # LLDP-MIB
OID_END, # 0.interfaceindex.deviceindex(?)
'4', # lldpChassisIdSubtype
'5', # lldpChassisId
'6', # lldpPortIdSubtype
'7', # lldpPortId
'8', # lldpPortDescription
'9', # lldpSystemName
'10', # lldpSystemDescription
'11', # ldpCapabilitiesMapSupported
'12', # lldpCacheCapabilities
]),
('.1.0.8802.1.1.2.1.3.7.1', [ # lldpRemEntry
OID_END, # interface index
'3' # interface short name/description
]),
],
'snmp_scan_function': lambda oid: oid('.1.0.8802.1.1.2.1.4.1.1.*'),
}
{'author': u'Th.L. (thl-cmk[at]outlook[dot]com)',
'description': u'Via WATO you can:\n - enable/disable this inventory\n - can add/remove some fields\nChangelog:\n - 2018-01-24: added local interface\n - 2018-01-25: added option to remove domain name form neighbor name\n - 2019-03-04: added support for cmk1.5.x\n',
'download_url': 'https://thl-cmk.hopto.org',
'files': {'inventory': ['snmp_lldp_cache'],
'web': ['plugins/views/inv_lldp_cache.py',
'plugins/wato/inv_lldp_cache.py']},
'name': 'inv_lldp_cache',
'num_files': 3,
'title': u'inventory for LLDP cache',
'version': '20190304.v04a',
'version.min_required': '1.4.0p1',
'version.packaged': '1.4.0p35'}
\ No newline at end of file
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
inventory_displayhints.update({
'.networking.lldp_cache:': {'title': _('LLDP Cache'), 'render': render_inv_dicttable,
'keyorder': ['system_name', 'chassis_id', 'port_id', 'local_port_num'],
'view': 'invlldpcache_of_host',
},
'.networking.lldp_cache:*.chassis_id' : {'title': _('Neighbour Chassis ID'), },
'.networking.lldp_cache:*.port_id' : {'title': _('Neighbour port ID'), },
'.networking.lldp_cache:*.port_description' : {'title': _('Neighbour port description'), },
'.networking.lldp_cache:*.system_name' : {'title': _('Neighbour name'), },
'.networking.lldp_cache:*.system_description' : {'title': _('Neighbour description'), },
'.networking.lldp_cache:*.local_port_num' : {'title': _('Local port ID'), },
'.networking.lldp_cache:*.capabilities_map_supported': {'title': _('Capabilities map supported'), },
'.networking.lldp_cache:*.cache_capabilities' : {'title': _('Cache Capabilities'), },
})
declare_invtable_view('invlldpcache', '.networking.lldp_cache:', _('LLDP cache'), _('LLDP Cache'))
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
removecolumns = [
('port_description', 'Neighbour port description'),
('system_description', 'Neighbour description'),
('capabilities_map_supported', 'Capabilities map supported'),
('cache_capabilities', 'Cache Capabilities'),
]
register_rule('inventory', 'inv_parameters:inv_lldp_cache',
Dictionary(
title=_('LLDP cache inventory'),
elements=[
('disable',
FixedValue(
True,
title=_('disable inventory'),
)),
('remove_domain',
FixedValue(
True,
title=_('remove domain name from neighbour device name'),
)),
('domain_name',
TextAscii(
title=_('Specific domain name to remove from neighbour device name')
)),
('removecolumns',
ListChoice(
title=_('list of columns to remove'),
label=_('list of columns to remove'),
help=_('information to remove from inventory'),
choices=removecolumns,
default_value=[],
)),
],
),
match='dict',
)
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