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 64408bb3 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
2020-06-22: initial release
\ No newline at end of file
This diff is collapsed.
# Huawei BGP Peers
Monitors status of Huawei BGP peers (HUAWEI-BGP-VPN-MIB)
Check Info:
* *service*: this check creates one service for each peer/address family (IPv4 and IPv6)
* *state*: \
**critical**: if Peer state is idle or if *hwBgpPeerUnAvaiReason* not 0\
**warning**: if Peer state is not idle and not established, if Peer uptime < min. uptime
* *wato*:
* **min uptime**: minimum time before a bgp peer connection is consinderd as stable, default 86400 seconds (1 day)
* **Infotext values**: select which information is shown in the check output
* **BGP Peer item name**: The configured value must match a BGP peer reported by the monitored device. For example: "10.194.115.98 IPv4 Unicast"
* **BGP Peer Alias**: You can configure an individual alias here for the BGP peer matching the text configured in the "BGP Peer item name" field. This alias will be shown in the infotext
* **MonitoringState**: You can configure an individual state if the BGP peer matching the text configured in the "BGP Peer item name" field is not found (default is critical).
* *perfdata*:
* FMS transitions (count)
* FMS last change (s)
Sample output
![sample output](/doc/sample.png?raw=true "sample [SHORT TITLE]")
title: Dummy check man page - used as template for new check manuals
agents: linux, windows, aix, solaris, hpux, vms, freebsd, snmp
catalog: see modules/catalog.py for possible values
license: GPL
distribution: check_mk
description:
Describe here: (1) what the check actually does, (2) under which
circumstances it goes warning/critical, (3) which devices are supported
by the check, (4) if the check requires a separated plugin or
tool or separate configuration on the target host.
item:
Describe the syntax and meaning of the check's item here. Provide all
information one needs if coding a manual check with {checks +=} in {main.mk}.
Give an example. If the check uses {None} as sole item,
then leave out this section.
examples:
# Give examples for configuration in {main.mk} here. If the check has
# configuration variable, then give example for them here.
# set default levels to 40 and 60 percent:
foo_default_values = (40, 60)
# another configuration variable here:
inventory_foo_filter = [ "superfoo", "superfoo2" ]
perfdata:
Describe precisely the number and meaning of performance variables
the check sends. If it outputs no performance data, then leave out this
section.
inventory:
Describe how the inventory for the check works. Which items
will it find? Describe the influence of check specific
configuration parameters to the inventory.
[parameters]
foofirst(int): describe the first parameter here (if parameters are grouped
as tuple)
fooother(string): describe another parameter here.
[configuration]
foo_default_levels(int, int): Describe global configuration variable of
foo here. Important: also tell the user how they are preset.
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
#
# License: GNU General Public License v2
#
# Author: thl-cmk[at]outlook[dot]com
# URL : https://thl-cmk.hopto.org
# Date : 2020-06-22
#
# Huawei BGP Peer
#
# Monitor status of Huawei BGP Peers (IPv4 and IPv6)
#
# this check is based on "huawei_bgp_peers" by thl-cmk[at]outlook[dot]com
#
#
# snmpwalk sample
# .1.3.6.1.4.1.2011.5.25.177.1.1.2.1.1.0.2.1.2.16.32.32.9.200.0.2.0.1.0.0.0.0.31.100.0.7 = Gauge32: 4
# .1.3.6.1.4.1.2011.5.25.177.1.1.2.1.2.0.2.1.2.16.32.32.9.200.0.2.0.1.0.0.0.0.31.100.0.7 = Gauge32: 16374
# .1.3.6.1.4.1.2011.5.25.177.1.1.2.1.4.0.2.1.2.16.32.32.9.200.0.2.0.1.0.0.0.0.31.100.0.7 = STRING: "2020:9F8:19:1::14F6:7"
# .1.3.6.1.4.1.2011.5.25.177.1.1.2.1.5.0.2.1.2.16.32.32.9.200.0.2.0.1.0.0.0.0.31.100.0.7 = INTEGER: 6
# .1.3.6.1.4.1.2011.5.25.177.1.1.2.1.6.0.2.1.2.16.32.32.9.200.0.2.0.1.0.0.0.0.31.100.0.7 = Gauge32: 1
# .1.3.6.1.4.1.2011.5.25.177.1.1.2.1.7.0.2.1.2.16.32.32.9.200.0.2.0.1.0.0.0.0.31.100.0.7 = Gauge32: 3456508
# .1.3.6.1.4.1.2011.5.25.177.1.1.2.1.9.0.2.1.2.16.32.32.9.200.0.2.0.1.0.0.0.0.31.100.0.7 = Hex-STRING: 00 00
# .1.3.6.1.4.1.2011.5.25.177.1.1.2.1.10.0.2.1.2.16.32.32.9.200.0.2.0.1.0.0.0.0.31.100.0.7 = Gauge32: 0
# .1.3.6.1.4.1.2011.5.25.177.1.1.2.1.11.0.2.1.2.16.32.32.9.200.0.2.0.1.0.0.0.0.31.100.0.7 = INTEGER: 2
#
# .1.3.6.1.4.1.2011.5.25.177.1.1.2.1.1.0.1.1.1.4.79.200.120.2 = Gauge32: 4
# .1.3.6.1.4.1.2011.5.25.177.1.1.2.1.2.0.1.1.1.4.79.200.120.2 = Gauge32: 20676
# .1.3.6.1.4.1.2011.5.25.177.1.1.2.1.4.0.1.1.1.4.79.200.120.2 = STRING: "79.200.120.2"
# .1.3.6.1.4.1.2011.5.25.177.1.1.2.1.5.0.1.1.1.4.79.200.120.2 = INTEGER: 6
# .1.3.6.1.4.1.2011.5.25.177.1.1.2.1.6.0.1.1.1.4.79.200.120.2 = Gauge32: 16
# .1.3.6.1.4.1.2011.5.25.177.1.1.2.1.7.0.1.1.1.4.79.200.120.2 = Gauge32: 2293069
# .1.3.6.1.4.1.2011.5.25.177.1.1.2.1.9.0.1.1.1.4.79.200.120.2 = Hex-STRING: 06 05
# .1.3.6.1.4.1.2011.5.25.177.1.1.2.1.10.0.1.1.1.4.79.200.120.2 = Gauge32: 0
# .1.3.6.1.4.1.2011.5.25.177.1.1.2.1.11.0.1.1.1.4.79.200.120.2 = INTEGER: 2
#
# HUAWEI-BGP-VPN-MIB::hwBgpPeerNegotiatedVersion.0.ipv6.unicast.ipv6."20:20:09:f8:00:19:00:01:00:00:00:00:14:f6:00:07" = Gauge32: 4
# HUAWEI-BGP-VPN-MIB::hwBgpPeerRemoteAs.0.ipv6.unicast.ipv6."20:20:09:f8:00:19:00:01:00:00:00:00:14:f6:00:07" = Gauge32: 16374
# HUAWEI-BGP-VPN-MIB::hwBgpPeerRemoteAddr.0.ipv6.unicast.ipv6."20:20:09:f8:00:19:00:01:00:00:00:00:14:f6:00:07" = STRING: "2020:9F8:19:1::14F6:7"
# HUAWEI-BGP-VPN-MIB::hwBgpPeerState.0.ipv6.unicast.ipv6."20:20:09:f8:00:19:00:01:00:00:00:00:14:f6:00:07" = INTEGER: established(6)
# HUAWEI-BGP-VPN-MIB::hwBgpPeerFsmEstablishedCounter.0.ipv6.unicast.ipv6."20:20:09:f8:00:19:00:01:00:00:00:00:14:f6:00:07" = Gauge32: 1
# HUAWEI-BGP-VPN-MIB::hwBgpPeerFsmEstablishedTime.0.ipv6.unicast.ipv6."20:20:09:f8:00:19:00:01:00:00:00:00:14:f6:00:07" = Gauge32: 3456883
# HUAWEI-BGP-VPN-MIB::hwBgpPeerLastError.0.ipv6.unicast.ipv6."20:20:09:f8:00:19:00:01:00:00:00:00:14:f6:00:07" = Hex-STRING: 00 00
# HUAWEI-BGP-VPN-MIB::hwBgpPeerUnAvaiReason.0.ipv6.unicast.ipv6."20:20:09:f8:00:19:00:01:00:00:00:00:14:f6:00:07" = Gauge32: 0
# HUAWEI-BGP-VPN-MIB::hwBgpPeerEntry.11.0.ipv6.unicast.ipv6."20:20:09:f8:00:19:00:01:00:00:00:00:14:f6:00:07" = INTEGER: 2
#
# HUAWEI-BGP-VPN-MIB::hwBgpPeerNegotiatedVersion.0.ipv4.unicast.ipv4."79.200.120.2" = Gauge32: 4
# HUAWEI-BGP-VPN-MIB::hwBgpPeerRemoteAs.0.ipv4.unicast.ipv4."79.200.120.2" = Gauge32: 20676
# HUAWEI-BGP-VPN-MIB::hwBgpPeerRemoteAddr.0.ipv4.unicast.ipv4."79.200.120.2" = STRING: "79.200.120.2"
# HUAWEI-BGP-VPN-MIB::hwBgpPeerState.0.ipv4.unicast.ipv4."79.200.120.2" = INTEGER: established(6)
# HUAWEI-BGP-VPN-MIB::hwBgpPeerFsmEstablishedCounter.0.ipv4.unicast.ipv4."79.200.120.2" = Gauge32: 16
# HUAWEI-BGP-VPN-MIB::hwBgpPeerFsmEstablishedTime.0.ipv4.unicast.ipv4."79.200.120.2" = Gauge32: 2293069
# HUAWEI-BGP-VPN-MIB::hwBgpPeerLastError.0.ipv4.unicast.ipv4."79.200.120.2" = Hex-STRING: 06 05
# HUAWEI-BGP-VPN-MIB::hwBgpPeerUnAvaiReason.0.ipv4.unicast.ipv4."79.200.120.2" = Gauge32: 0
# HUAWEI-BGP-VPN-MIB::hwBgpPeerEntry.11.0.ipv4.unicast.ipv4."79.200.120.2" = INTEGER: 2
#
# sample info
#
#
#
#
factory_settings['huawei_bgp_peers_defaults'] = {
'minuptime': 86400,
'peer_list': [],
}
###########################################################################
#
# DATA Parser function
#
###########################################################################
def parse_huawei_bgp_peers(info):
def huawei_get_adress_family(OID_END):
# HWBgpAfi ::= TEXTUAL-CONVENTION
# STATUS current
# DESCRIPTION
# "Address Family Identifier(AFI) for BGP peer."
HWBgpAfi = {
1: 'IPv4',
2: 'IPv6',
25: 'VPLS',
196:'L2VPN',
}
# HWBgpSafi ::= TEXTUAL-CONVENTION
# STATUS current
# DESCRIPTION
# "Subsequent Address Family Identifier(SAFI) for BGP peer."
HWBgpSafi = {
1: 'Unicast',
2: 'Multicast',
4: 'MPL',
5: 'mcast-vpn',
65: 'VPL',
66: 'MDT',
128: 'VPN',
132: 'route-target',
}
OID_END = OID_END.split('.')
adress_family = HWBgpAfi.get(int(OID_END[1]), OID_END[1])
sub_family = HWBgpSafi.get(int(OID_END[2]), OID_END[2])
return '%s %s' % (adress_family, sub_family)
def huawei_bgp_errors(bytestring):
lasterrorhex = ''.join(["%02X " % ord(x) for x in bytestring]).strip()
byte1, byte2 = lasterrorhex.split()
names = {}
names[0] = {0: 'NO ERROR'}
names[1] = {0: 'Message',
2: 'Connection Not Synchronized',
3: 'Bad Message Length',
4: 'Bad Message Type',
}
names[2] = {0: 'OPEN',
1: 'Unsupported Version Number',
2: 'Bad Peer AS',
3: 'Bad BGP Identifier',
4: 'Unsupported Optional Parameter',
5: 'Authentication Failure',
6: 'Unacceptable Hold',
}
names[3] = {0: 'UPDATE',
1: 'Malformed Attribute List',
2: 'Unrecognized Well-known Attribute',
3: 'Missing Well-known Attribute',
4: 'Attribute Flags Error',
5: 'Attribute Length Error',
6: 'Invalid ORIGIN Attribute',
7: 'AS Routing Loop',
8: 'Invalid NEXT_HOP Attribute',
9: 'Optional Attribute Error',
10: 'Invalid Network Field',
11: 'Malformed AS_PATH',
}
names[4] = {0: 'Hold Timer Expired', }
names[5] = {0: 'Finite State Machine Error', }
names[6] = {0: 'Administratively Shutdown',
1: 'Max Prefix Reached',
2: 'Peer Unconfigured',
3: 'Administratively Reset',
4: 'Connection Rejected',
5: 'Other Configuration Change',
}
return names[int(byte1, 16)].get(int(byte2, 16))
def huawei_bgp_PeerUnAvaiReason(st):
reason = {
'1': 'Configuration lead peer down',
'2': 'Receive notification',
'3': 'Receive error packet',
'4': 'Hold timer expire',
'5': 'Remote peer not reachable',
'6': 'Direct connect-interface down',
'7': 'Route limit',
}
return reason.get(st, st)
# bgp not active
if info == [[], []]:
return None
hwbgpPeer2Entry, hwBgpPeer = info
peer_table = {}
for entry in hwbgpPeer2Entry:
oid_end, hwBgpPeerNegotiatedVersion, hwBgpPeerRemoteAs, hwBgpPeerRemoteAddr, hwBgpPeerState, \
hwBgpPeerFsmEstablishedCounter, hwBgpPeerFsmEstablishedTime, hwBgpPeerLastError, hwBgpPeerUnAvaiReason, \
hwBgpPeerEntry = entry
adressfamily = huawei_get_adress_family(oid_end)
peer = {
'remoteaddr': hwBgpPeerRemoteAddr,
'lasterror': huawei_bgp_errors(hwBgpPeerLastError),
'adressfamily': adressfamily,
'hwpeerunavireason': huawei_bgp_PeerUnAvaiReason(hwBgpPeerUnAvaiReason),
}
for key, value in [
('state', hwBgpPeerState),
('remoteas', hwBgpPeerRemoteAs),
('fsmestablishedtransitions', hwBgpPeerFsmEstablishedCounter),
('fsmestablishedtime', hwBgpPeerFsmEstablishedTime),
('hwBgpPeerEntry', hwBgpPeerEntry),
('negotiatedversion', hwBgpPeerNegotiatedVersion),
]:
try:
peer[key] = int(value)
except ValueError:
pass
peer_table.update({'%s %s' % (hwBgpPeerRemoteAddr, adressfamily): peer})
return peer_table
###########################################################################
#
# INVENTORY function
#
###########################################################################
def inventory_huawei_bgp_peers(parsed):
if parsed:
for key in parsed.keys():
yield key, {}
###########################################################################
#
# CHECK function
#
###########################################################################
def check_huawei_bgp_peers(item, params, parsed):
def bgp_render_uptime(uptime): # expects time in seconds
m, s = divmod(uptime, 60) # break in seconds / minutes
h, m = divmod(m, 60) # break in mintes / hours
if h >= 24: # more then one day
d, h = divmod(h, 24) # break in hours / days
else:
return '%02d:%02d:%02d' % (h, m, s)
if d >= 365: # more the one year
y, d = divmod(d, 365) # break in days / years
return '%dy %dd %02d:%02d:%02d' % (y, d, h, m, s)
else:
return '%dd %02d:%02d:%02d' % (d, h, m, s)
def bgp_peer_state(state):
names = {0: 'none',
1: 'idle',
2: 'connect',
3: 'active',
4: 'opensend',
5: 'openconfirm',
6: 'established'}
return names.get(state, 'unknown (%s)' % state)
peer_table = parsed
alias = ''
peer_not_found_state = 3
for bgp_connection, bgp_alias, not_found_state in params.get('peer_list', []):
if item == bgp_connection:
alias = bgp_alias
peer_not_found_state = not_found_state
if item in peer_table.keys():
peer = peer_table[item]
if not alias == '':
infotext = ', Alias: %s' % alias
else:
infotext = ''
longoutput = ''
perfdata = []
infotext_values = params.get('infotext_values', [])
minuptime = params.get('minuptime', 86400)
for key, value in [
('remoteas', ', Remote AS: %d'),
('negotiatedversion', ', Negotiated version: %d'),
('lasterror', ', Last error: %s'),
]:
try:
if key not in infotext_values:
infotext += value % peer[key]
except KeyError:
pass
peerstate = peer['state']
establishedtime = peer['fsmestablishedtime']
if peerstate == 1: # idle
yield 2, 'Peer state: %s' % bgp_peer_state(peerstate)
elif peerstate == 6: # established
if establishedtime >= minuptime:
yield 0, 'Uptime: %s' % bgp_render_uptime(establishedtime)
else:
yield 1, 'Uptime: %s is less then min. uptime (%s)' % (bgp_render_uptime(establishedtime), bgp_render_uptime(minuptime))
else: # everything else
yield 1, 'Peer state: %s' % bgp_peer_state(peerstate)
if peer['hwpeerunavireason'] != '0':
yield 2, peer['hwpeerunavireason']
# for key, value in peer.items():
# longoutput += '\n%s: %s' % (key, value)
for key in [
'fsmestablishedtransitions',
'fsmestablishedtime',
]:
try:
perfdata.append((key, peer[key]))
except KeyError:
pass
if infotext.startswith(', '):
infotext = infotext[2:]
yield 0, infotext + longoutput, perfdata
else:
infotext = 'Item not found in SNMP data'
if alias != '':
infotext += ', Alias: %s' % alias
yield peer_not_found_state, infotext
###########################################################################
#
# CHECK info
#
###########################################################################
check_info['huawei_bgp_peers'] = {
'check_function' : check_huawei_bgp_peers,
'inventory_function' : inventory_huawei_bgp_peers,
'service_description' : 'Huawei BGP peer %s',
'has_perfdata' : True,
'group' : 'huawei_bgp_peers',
'default_levels_variable' : 'huawei_bgp_peers_defaults',
'parse_function' : parse_huawei_bgp_peers,
'snmp_scan_function' : lambda oid: oid('.1.3.6.1.2.1.1.2.0').startswith('.1.3.6.1.4.1.2011'),
'snmp_info' : [
('.1.3.6.1.4.1.2011.5.25.177.1.1.2.1', # HUAWEI-BGP-VPN-MIB::hwBgpPeerEntry
[OID_END, # 0.ipv4/ipv6.adressFamily.ipv4/ipv6.RemotePeerIP
'1', # hwBgpPeerNegotiatedVersion
'2', # hwBgpPeerRemoteAs
'4', # hwBgpPeerRemoteAddr
'5', # hwBgpPeerState
'6', # hwBgpPeerFsmEstablishedCounter
'7', # hwBgpPeerFsmEstablishedTime
'9', # hwBgpPeerLastError
'10', # hwBgpPeerUnAvaiReason
'11', # hwBgpPeerEntry
]),
('.1.3.6.1.4.1.2011.5.25.177.3.2.2', # HUAWEI-BGP-VPN-MIB::hwBgpPeer
[OID_END, #
]),
]
}
doc/sample.png

20.8 KiB

File added
{'author': u'Th.L. (thl-cmk[at]outlook[dot]com)',
'description': u'Monitors Huawei BGP Peers (HUAWEI-BGP-VPN-MIB). \n\n- creates one service for each peer/address family (IPv4 and IPv6)',
'download_url': 'https://thl-cmk.hopto.org',
'files': {'checks': ['huawei_bgp_peers'],
'web': ['plugins/wato/huawei_bgp_peers.py',
'plugins/metrics/huawei_bgp_peers.py']},
'name': 'huawei_bgp_peers',
'num_files': 3,
'title': u'Huawei BGP Peer',
'version': '20200622.v.0.1',
'version.min_required': '1.2.8b8',
'version.packaged': '1.4.0p38'}
\ No newline at end of file
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
#
# License: GNU General Public License v2
#
# Author: thl-cmk[at]outlook[dot]com
# URL : https://thl-cmk.hopto.org
# Date : 2020-06-22
#
# Huawei BGP Peer
#
try:
from cmk.gui.i18n import _
from cmk.gui.plugins.metrics import (
metric_info,
graph_info,
check_metrics,
)
except:
pass
###############################################################################
#
# define units
#
###############################################################################
###############################################################################
#
# define metrics
#
###############################################################################
metric_info['huawei_bgp_peers_fsmestablishedtransitions'] = {
'title': _('FMS transitions'),
'unit': 'count',
'color': '23/a',
}
metric_info['huawei_bgp_peers_fsmestablishedtime'] = {
'title': _('FMS last change'),
'unit': 's',
'color': '26/a',
}
###############################################################################
#
# map perfdata to metric
#
###############################################################################
check_metrics['check_mk-huawei_bgp_peers'] = {
'fsmestablishedtransitions': {'name': 'huawei_bgp_peers_fsmestablishedtransitions', },
'fsmestablishedtime': {'name': 'huawei_bgp_peers_fsmestablishedtime', },
}
###############################################################################
#
# how to graph
#
###############################################################################
graph_info.append({
'title': _('FMS transitions from/to established'),
'metrics': [
('huawei_bgp_peers_fsmestablishedtransitions', 'line'),
],
})
graph_info.append({
'title': _('FMS established last change'),
'metrics': [
('huawei_bgp_peers_fsmestablishedtime', 'line'),
]
})
###############################################################################
#
# define perf-o-meter
#
###############################################################################
perfometer_info.append({
'type': 'logarithmic',
'metric': 'huawei_bgp_peers_fsmestablishedtime',
'half_value': 2592000.0,
'exponent': 2,
})
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
#
# License: GNU General Public License v2
#
# Author: thl-cmk[at]outlook[dot]com
# URL : https://thl-cmk.hopto.org
# Date : 2020-06-22
#
# Huawei BGP Peer
#
#
huawei_bgp_peers_infotext_values = [
('remoteas', 'Remote autonomous system'),
('negotiatedversion', 'Negotiated version'),
('lasterror', 'Last error')
]
register_check_parameters(
subgroup_networking,
'huawei_bgp_peers',
_('Huawei BGP peer'),
Dictionary(
help=_(''),
elements=[
('minuptime',
Integer(
help=_('Set the time in seconds, a peer must be up before the peer is considered sable.'
'If the peer uptime less then X, the check outcome is set to warning.'),
title=_('Minimum uptime for peer. If uptime less, set check outcome to warning. Default is 1 day.'),
default_value=86400,
allow_empty=False,
unit='seconds',
minvalue=1,
),
),
('infotext_values',
ListChoice(
title=_('Remove values from Infotext'),
label=_('Remove values from infotext'),
help=_('Select values to remove from check output.'),
choices=huawei_bgp_peers_infotext_values,
default_value=[],
)),
('peer_list',
ListOf(
Tuple(
title=('BGP Peers'),
elements=[
TextUnicode(
title=_('BGP Peer item name (without "Huawei BGP peer")'),
help=_('The configured value must match a BGP item reported by the monitored '
'device. For example: "10.194.115.98 IPv4 Unicast"'),
allow_empty=False,
),
TextUnicode(
title=_('BGP Peer Alias'),
help=_('You can configure an individual alias here for the BGP peer matching '
'the text configured in the "BGP Peer item name" field. The alias will '
'be shown in the infotext'),
),
MonitoringState(
default_value=2,
title=_('State if not found'),
help=_('You can configure an individual state if the BGP peer matching the text '
'configured in the "BGP Peer item name" field is not found')
)]),
add_label=_('Add BGP peer'),
movable=False,
title=_('BGP peer specific configuration'),
)),
],
),
TextAscii(title=_('Huawei BGP peer')),
match_type='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