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

update project

parent f8f9011c
No related branches found
No related tags found
No related merge requests found
......@@ -15,23 +15,29 @@
# 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
import time, re
from typing import List
def inv_lldp_cache(info, params):
removecolumns = []
remove_domain = False
domain_name = ''
from .agent_based_api.v1.type_defs import (
StringTable,
InventoryResult,
)
from .agent_based_api.v1 import (
OIDEnd,
)
from .agent_based_api.v1 import (
register,
SNMPTree,
TableRow,
exists,
)
# 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)
def parse_inv_lldp_cache(string_table: List[StringTable]) -> list:
lldp_chassisidsubtype = {
0: 'n/a',
1: 'chassiscomponent',
......@@ -60,28 +66,28 @@ def inv_lldp_cache(info, params):
2: 'ifindex',
3: 'systemportnumber',
}
lldp_capabilities = {
0: '',
1: 'other',
2: 'Repeater',
4: 'Bridge',
8: 'WLAN AP',
16: 'Router',
32: 'Phone',
64: 'DOCSIS',
128: 'Station',
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])
return '.'.join(['%s' % ord(m) for m in bytestring])
def render_time(uptime_sec):
uptime_sec = int(uptime_sec)
since = time.strftime('%c', time.localtime(time.time() - (uptime_sec / 100)))
since = time.strftime('%c', time.localtime(time.time() - (uptime_sec / 100)))
return since
def render_capabilities(bytestring):
......@@ -89,7 +95,7 @@ def inv_lldp_cache(info, params):
return []
cpapabilites = []
for x in lldp_capabilities:
tempcap = lldp_capabilities.get(saveint(ord(bytestring[0])) & x)
tempcap = lldp_capabilities.get(int(ord(bytestring[0])) & x)
if tempcap != '':
cpapabilites.append(tempcap)
......@@ -112,23 +118,23 @@ def inv_lldp_cache(info, params):
st = st.lower().replace(item, names.get(item))
return st
node = inv_tree_list('networking.lldp_cache:')
lldp_info, if_info = string_table
lldp_info, if_info = info
neighbors = []
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:
for ifIndex, ifName in if_info:
if local_ifindex == ifIndex:
local_port = get_short_if_name(ifDescr)
local_port = get_short_if_name(ifName)
if lldp_chassisidsubtype.get(saveint(lldpchassisidsubtype)) == 'macaddress':
if lldp_chassisidsubtype == '3': # mac address
lldpchassisid = render_mac_address(lldpchassisid)
if saveint(lldpportidsubtype) == lldp_portidsubtype.get('macaddress'):
if lldpportidsubtype == '3': # macaddress
lldpportid = render_mac_address(lldpportid)
if len(lldpportid) == 6:
......@@ -140,51 +146,104 @@ def inv_lldp_cache(info, params):
if (cleanport_id != lldpportid) or (cleanport_id == ''):
lldpportid = render_mac_address(lldpportid)
neighbor = {
'local_port_num': get_short_if_name(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),
}
neighbors.append(neighbor)
return neighbors
def inventory_lldp_cache(params, section: list) -> InventoryResult:
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)
path= ['networking', 'lldp_cache']
for neighbor in section:
# print(neighbor)
if remove_domain:
if not domain_name == '':
lldpsystemname = lldpsystemname.replace(domain_name, '')
lldpchassisid = lldpchassisid.replace(domain_name, '')
neighbor['lldpsystemname'] = neighbor['lldpsystemname'].replace(domain_name, '')
neighbor['lldpchassisid'] = neighbor['lldpchassisid'].replace(domain_name, '')
else:
lldpsystemname = lldpsystemname.split('.')[0]
lldpchassisid = lldpchassisid.split('.')[0]
neighbor = {}
for key, value in [
('local_port_num', get_short_if_name(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)),
]:
if key not in removecolumns:
neighbor[key] = value
node.append(neighbor)
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.*'),
}
neighbor['lldpsystemname'] = neighbor['lldpsystemname'].split('.')[0]
neighbor['lldpchassisid'] = neighbor['lldpchassisid'].split('.')[0]
key_columns = {'local_port_num': neighbor['local_port_num']}
for key in key_columns.keys():
neighbor.pop(key)
for entry in removecolumns:
neighbor.pop(entry)
yield TableRow(
path=path,
key_columns=key_columns,
inventory_columns=neighbor
)
register.snmp_section(
name='inv_lldp_cache',
parse_function=parse_inv_lldp_cache,
fetch=[
SNMPTree(
base='.1.0.8802.1.1.2.1.4.1.1', # LLDP-MIB
oids=[
OIDEnd(), # ifIndex
'4', # lldpChassisIdSubtype
'5', # lldpChassisId
'6', # lldpPortIdSubtype
'7', # lldpPortId
'8', # lldpPortDescription
'9', # lldpSystemName
'10', # lldpSystemDescription
'11', # ldpCapabilitiesMapSupported
'12', # lldpCacheCapabilities
]
),
SNMPTree(
base='.1.3.6.1.2.1.31.1.1.1', #
oids=[
OIDEnd(), # ifIndex
'1', # ifName
]
),
# SNMPTree(
# base='.1.0.8802.1.1.2.1.3.7.1', # lldpRemEntry
# oids=[
# OIDEnd(), # interface index
# '3', # interface short name/description
# ]
# ),
],
detect=exists('.1.0.8802.1.1.2.1.4.1.1.*'), #
)
register.inventory_plugin(
name='inv_lldp_cache',
inventory_function=inventory_lldp_cache,
inventory_default_parameters={},
inventory_ruleset_name='inv_lldp_cache',
)
No preview for this file type
{'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 - 2020-05-13: added support for CMK1.6x\n',
{'author': 'Th.L. (thl-cmk[at]outlook[dot]com)',
'description': 'Via WATO you can:\n'
' - enable/disable this inventory\n'
' - can add/remove some fields\n'
'Changelog:\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'
' - 2020-05-13: added support for CMK1.6x\n'
' - 2021-03-17: rewritten for CMK 2.x\n',
'download_url': 'https://thl-cmk.hopto.org',
'files': {'inventory': ['snmp_lldp_cache'],
'files': {'agent_based': ['inv_lldp_cache.py'],
'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': '20200731.v04c',
'version.min_required': '1.4.0p1',
'version.packaged': '1.4.0p38',
'title': 'inventory for LLDP cache',
'version': '20210317.v05',
'version.min_required': '2.0.0',
'version.packaged': '2.0.0',
'version.usable_until': None}
\ No newline at end of file
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
try:
from cmk.gui.plugins.views.inventory import (
declare_invtable_view,
render_inv_dicttable,
)
except:
pass
import cmk.gui.utils
from cmk.gui.plugins.views import (
inventory_displayhints,)
from cmk.gui.i18n import _
inventory_displayhints.update({
'.networking.lldp_cache:': {'title': _('LLDP Cache'), 'render' : render_inv_dicttable,
'.networking.lldp_cache:': {'title': _('LLDP Cache'),
'keyorder': ['system_name', 'chassis_id', 'port_id', 'local_port_num'],
'view': 'invlldpcache_of_host',
},
......@@ -25,5 +22,7 @@ inventory_displayhints.update({
'.networking.lldp_cache:*.cache_capabilities' : {'title': _('Cache Capabilities'), },
})
from cmk.gui.plugins.views.inventory import declare_invtable_view
declare_invtable_view('invlldpcache', '.networking.lldp_cache:', _('LLDP cache'), _('LLDP Cache'))
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
#
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',
)
from cmk.gui.i18n import _
from cmk.gui.plugins.wato import (
HostRulespec,
rulespec_registry,
RulespecGroup,
)
from cmk.gui.valuespec import (
Dictionary,
FixedValue,
TextAscii,
ListChoice,
)
from cmk.gui.plugins.wato.inventory import (
RulespecGroupInventory,
)
def _valuespec_inv_lldp_cache():
removecolumns = [
('port_description', 'Neighbour port description'),
('system_description', 'Neighbour description'),
('capabilities_map_supported', 'Capabilities map supported'),
('cache_capabilities', 'Cache Capabilities'),
]
return Dictionary(
title=_('LLDP cache'),
elements=[
('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,
title=_('Remove domain name from neighbour device name'),
totext=_('Remove the domain name from the neighbour device name'),
default_value=False,
)),
('domain_name',
TextAscii(
title=_('Specific domain name to remove from neighbour device name'),
allow_empty=False,
default_value='',
)),
('removecolumns',
ListChoice(
title=_('List of columns to remove'),
help=_('information to remove from inventory'),
choices=removecolumns,
default_value=[],
)),
],
)
rulespec_registry.register(
HostRulespec(
group=RulespecGroupInventory,
match_type="dict",
name="inv_parameters:inv_lldp_cache",
valuespec=_valuespec_inv_lldp_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