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

update project

parent 44a45a85
No related branches found
No related tags found
No related merge requests found
......@@ -15,10 +15,11 @@
# 2022-05-09: added item to BgpPeer class, this is used in the discovery function
# 2022-05-11: changed bgp_get_peer_entry to get proper parameters instead of Nontransparent list
# added remote_as to BgpPeerItem
# 2022-05-12: merged bgp_get_ip_address_from_oid with bgp_render_ip_address
# changed IPv6 address format to lower case as required by rfc5952 section-4.3 (this affects IPv6 peers)
import requests
import json
import re
import ipaddress
from typing import List, Tuple, Optional, Dict, TypedDict
from dataclasses import dataclass
......@@ -162,23 +163,6 @@ def bgp_error_as_string(error_code: List[int]):
return names[main_code].get(sub_code)
def bgp_shorten_ipv6_address(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 bgp_render_ip_address(addr_type: str, addr: List[int]) -> str:
if addr_type == '1':
return '.'.join([str(m) for m in addr])
......@@ -204,11 +188,16 @@ def bgp_get_ip_address_from_oid(oid_end):
# u'2.16.42.5.87.192.0.0.255.255.0.0.0.0.0.0.0.17.2.1' --> 42.5.87.192.0.0.255.255.0.0.0.0.0.0.0.17
ip_address = ''
oid_end = oid_end.split('.')
if int(oid_end[1]) == 4: # length of ip address
addr_type = oid_end[0]
addr_length = oid_end[1]
if addr_type == '1' and addr_length == '4': # length of ip address
ip_address = '.'.join(oid_end[2:6]) # ipv4 address
elif int(oid_end[1]) == 16: # ipv6 address
ip_address = ':'.join('%02s' % hex(int(m))[2:] for m in oid_end[2:18]).replace(' ', '0').upper()
ip_address = bgp_shorten_ipv6_address(ip_address)
elif addr_type == '2' and addr_length == '16': # ipv6 address
ip_address = []
# change list of str to lis of int
ip_address += [int(m) for m in oid_end[2:18]]
ip_address = bgp_render_ip_address(addr_type, ip_address)
return ip_address
......
No preview for this file type
......@@ -20,7 +20,7 @@
'name': 'bgp_peer',
'num_files': 8,
'title': 'BGP Peer State Check',
'version': '20220511.v1.8',
'version': '20220512.v1.8',
'version.min_required': '2.0.0',
'version.packaged': '2021.09.20',
'version.usable_until': None}
\ No newline at end of file
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