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

update project

parent 8d7615c4
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# 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)
#
# 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
from typing import List, Dict, Optional
from cmk.base.plugins.agent_based.agent_based_api.v1 import (
register,
SNMPTree,
OIDEnd,
startswith,
)
from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import (
StringTable,
)
from cmk.base.plugins.agent_based.utils.bgp_peer import (
bgp_get_peer,
BgpPeer,
bgp_get_peer_entry,
)
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_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)
def parse_huawei_bgp_peer(string_table: List[StringTable]) -> Dict[str, BgpPeer]:
hwbgpPeer2Entry, hwBgpPeerRouteEntry = string_table
peer_table = {}
for entry in hwbgpPeer2Entry:
oid_end, hwBgpPeerRemoteAddr, hwBgpPeerState, hwBgpPeerFsmEstablishedCounter, hwBgpPeerFsmEstablishedTime, \
hwBgpPeerUnAvaiReason = entry
bgp_peer = bgp_get_peer_entry([
hwBgpPeerRemoteAddr,
hwBgpPeerState,
'2', # admin_state not admin_down
None, # in_updates
None, # out_updates
None, # in_messages
None, # out_messages
hwBgpPeerFsmEstablishedCounter,
hwBgpPeerFsmEstablishedTime,
None, # in_update_elapsed_time
]
)
if bgp_peer:
adressfamily = _huawei_get_adress_family(oid_end)
remote_address = list(bgp_peer.keys())[0]
index = f'{remote_address} {adressfamily}'
bgp_peer[remote_address].peer_unavail_reason = int(hwBgpPeerUnAvaiReason)
bgp_peer[remote_address].peer_unavail_reason_str = _huawei_bgp_PeerUnAvaiReason(int(hwBgpPeerUnAvaiReason))
bgp_peer = {index: bgp_peer[remote_address]}
peer_table.update(bgp_peer)
# peer = {
# 'hwpeerunavireason': _huawei_bgp_PeerUnAvaiReason(hwBgpPeerUnAvaiReason),
# }
#
# add BGP route counter
for entry in hwBgpPeerRouteEntry:
oid_end, hwBgpPeerPrefixRcvCounter, hwBgpPeerPrefixActiveCounter, hwBgpPeerPrefixAdvCounter = entry
counter = []
for key, value in [
('prefixrcvcounter', hwBgpPeerPrefixRcvCounter),
('prefixactivecounter', hwBgpPeerPrefixActiveCounter),
('prefixadvcounter', hwBgpPeerPrefixAdvCounter),
]:
try:
counter.append((key, int(value)))
except TypeError:
pass
# adjust oid_end to match cisco oid_end
service = '%s %s' % (bgp_get_peer(f'{oid_end[6:]}.1.1'), _huawei_get_adress_family(oid_end))
if service in peer_table.keys():
peer_table[service].metric_count += counter
return peer_table
register.snmp_section(
name='huawei_bgp_peer',
parse_function=parse_huawei_bgp_peer,
parsed_section_name='bgp_peer',
supersedes=['bgp_peer'],
fetch=[
SNMPTree(
base='.1.3.6.1.4.1.2011.5.25.177.1.1.2.1', # HUAWEI-BGP-VPN-MIB::hwBgpPeerEntry
oids=[
OIDEnd(), # 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
]
),
SNMPTree(
base='.1.3.6.1.4.1.2011.5.25.177.1.1.3.1', # HUAWEI-BGP-VPN-MIB::hwBgpPeerRouteEntry
oids=[
OIDEnd(), # 0.ipv4/ipv6.adressFamily.ipv4/ipv6.RemotePeerIP
'1', # hwBgpPeerPrefixRcvCounter
'2', # hwBgpPeerPrefixActiveCounter
'3', # hwBgpPeerPrefixAdvCounter
]
),
],
detect=startswith('.1.3.6.1.2.1.1.2.0', '.1.3.6.1.4.1.2011')
)
No preview for this file type
{'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)',
{'author': 'Th.L. (thl-cmk[at]outlook[dot]com)',
'description': 'Monitors Huawei BGP Peers (HUAWEI-BGP-VPN-MIB). \n'
'\n'
'- creates one service for each peer/address family (IPv4 and '
'IPv6)\n'
'\n'
'needs the bgp_peer.mkp (minimum version 20220418.v1.7) '
'package to work \n'
'\n'
'see: '
'https://thl-cmk.hopto.org/gitlab/checkmk/vendor-independent/bgp_peer/-/raw/master/bgp_peer.mkp\n'
' \n',
'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']},
'files': {'agent_based': ['huawei_bgp_peer.py'],
'web': ['plugins/metrics/huawei_bgp_peer.py']},
'name': 'huawei_bgp_peers',
'num_files': 3,
'title': u'Huawei BGP Peer',
'version': '20200720.v.0.1a',
'num_files': 2,
'title': 'Huawei BGP Peer',
'version': '20220418.v.0.2',
'version.min_required': '1.2.8b8',
'version.packaged': '1.4.0p38'}
\ No newline at end of file
'version.packaged': '2021.09.20',
'version.usable_until': None}
\ No newline at end of file
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# 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
#
# 2020-07-20: added BGP prefix counter
#
#
from cmk.gui.i18n import _
from cmk.gui.plugins.metrics import (
metric_info,
graph_info,
perfometer_info
)
metric_info['bgp_peer_prefixrcvcounter'] = {
'title': _('Prefixes received'),
'unit': 'count',
'color': '11/a',
}
metric_info['bgp_peer_prefixactivecounter'] = {
'title': _('Prefixes active'),
'unit': 'count',
'color': '33/a',
}
metric_info['bgp_peer_prefixadvcounter'] = {
'title': _('Prefixes advertised'),
'unit': 'count',
'color': '43/a',
}
graph_info['huawei_bgp_peer_counter']= {
'title': _('BGP prefix counter'),
'metrics': [
('bgp_peer_prefixrcvcounter', 'line'),
('bgp_peer_prefixactivecounter', 'line'),
('bgp_peer_prefixadvcounter', 'line'),
]
}
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