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

Delete huawei_bgp_peers

parent 4f08437d
No related branches found
No related tags found
No related merge requests found
#!/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 "cisco_bgp_peers" by thl-cmk[at]outlook[dot]com
#
#
# 2020-07-20: added BGP prefix counter
#
# 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 shorten_ipv6_adress(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 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_get_ip_address(OID_END):
ip_address = ''
OID_END = OID_END.split('.')
if OID_END[4] == '4': # IPv4 Address
ip_address = '.'.join(OID_END[5:])
elif OID_END[4] == '16': ## IPv6 Address
ip_address = ':'.join('%02s' % hex(int(m))[2:] for m in OID_END[5:]).replace(' ', '0').upper()
ip_address = shorten_ipv6_adress(ip_address)
return ip_address
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, hwBgpPeerRouteEntry = 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 TypeError:
pass
peer_table.update({'%s %s' % (hwBgpPeerRemoteAddr, adressfamily): peer})
# add BGP route counter
for entry in hwBgpPeerRouteEntry:
oid_end, hwBgpPeerPrefixRcvCounter, hwBgpPeerPrefixActiveCounter, hwBgpPeerPrefixAdvCounter = entry
peer = {}
for key, value in [
('prefixrcvcounter', hwBgpPeerPrefixRcvCounter),
('prefixactivecounter',hwBgpPeerPrefixActiveCounter),
('prefixadvcounter',hwBgpPeerPrefixAdvCounter),
]:
try:
peer[key]= int(value)
except TypeError:
pass
service = '%s %s' % (huawei_get_ip_address(oid_end), huawei_get_adress_family(oid_end))
if service in peer_table.keys():
peer_table[service].update(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',
'prefixrcvcounter',
'prefixactivecounter',
'prefixadvcounter',
]:
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.1.1.3.1', # HUAWEI-BGP-VPN-MIB::hwBgpPeerRouteEntry
[OID_END, # 0.ipv4/ipv6.adressFamily.ipv4/ipv6.RemotePeerIP
'1', # hwBgpPeerPrefixRcvCounter
'2', # hwBgpPeerPrefixActiveCounter
'3', # hwBgpPeerPrefixAdvCounter
]),
]
}
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