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

fixed non working whois retrieval

parent 2c5d0c2e
No related branches found
No related tags found
No related merge requests found
[PACKAGE]: ../../raw/master/mkp/bgp_peer-2.2.7-20241220.mkp "bgp_peer-2.2.7-20241220.mkp"
[PACKAGE]: ../../raw/master/mkp/bgp_peer-2.2.8-20250117.mkp "bgp_peer-2.2.8-20250117.mkp"
# BGP Peer
Check plugin to monitor the status of BGP peers and inventory plugin for static BGP peer data.
......
File added
......@@ -11,28 +11,30 @@
#
# 2022-04-30: code cleanup/streamlining
# 2023-01-17: always remove fsm_established_time
#
# 2025-01-17: fixed non working whois retrieval (param check was incorrect, no default rir is also not True)
# fixed crash on missing remote_as
# fixed missing "/" in whois query (ThX to nick[at]fisk[dot]me[dot]uk)
import time
from typing import List
from cmk.base.plugins.agent_based.agent_based_api.v1 import (
register,
OIDBytes,
SNMPTree,
TableRow,
exists,
OIDBytes
register,
)
from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import (
StringByteTable,
InventoryResult,
StringByteTable,
)
from cmk.base.plugins.agent_based.utils.bgp_peer import (
bgp_error_code_as_hex,
bgp_error_as_string,
BgpWhois,
InvBgpPeer,
bgp_error_as_string,
bgp_error_code_as_hex,
get_bgp_type,
BgpWhois,
)
......@@ -76,10 +78,10 @@ def parse_inv_bgp_peer(string_table: List[StringByteTable]):
def inventory_bgp_peers(params, section) -> InventoryResult:
path = ['networking', 'bgp_peers']
whois = None
if params.get('whois_enable'):
if (whois := params.get('whois_enable')) is not None:
whois = BgpWhois(
default_rir=params['whois_enable'].get('whois_rir', 'https://rdap.db.ripe.net'),
default_rir=params['whois_enable'].get('whois_rir', 'https://rdap.db.ripe.net/'),
timeout=params['whois_enable'].get('whois_timeout', 5)
)
......@@ -92,7 +94,7 @@ def inventory_bgp_peers(params, section) -> InventoryResult:
status_columns = bgp_peer['status_columns']
bgp_peer.pop('status_columns')
if whois:
if whois and bgp_peer.get('remote_as', '').isdigit():
as_info = whois.get_whois_data_by_asn(int(bgp_peer.get('remote_as')))
bgp_peer.update(as_info)
......
......@@ -18,6 +18,7 @@
# 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 items)
# 2023-01-20: add description to BgpPeerItem (for Arista)
# 2025-01-25: fixed missing "/" in rir URL (ThX to nick[at]fisk[dot]me[dot]uk)
#
# https://ftp.ripe.net/ripe/asnames/asn.txt AS Name List
......@@ -492,11 +493,11 @@ class BgpWhois:
'version': '1.0'
}
__rirs = {
'ripe': 'https://rdap.db.ripe.net',
'arin': 'https://rdap.arin.net/registry',
'afrinic': 'https://rdap.afrinic.net/rdap',
'lacnic': 'https://rdap.lacnic.net/rdap',
'apnic': 'https://rdap.apnic.net',
'ripe': 'https://rdap.db.ripe.net/',
'arin': 'https://rdap.arin.net/registry/',
'afrinic': 'https://rdap.afrinic.net/rdap/',
'lacnic': 'https://rdap.lacnic.net/rdap/',
'apnic': 'https://rdap.apnic.net/',
}
def __find_rir_by_asn(self, asn: int) -> str:
......@@ -512,7 +513,7 @@ class BgpWhois:
def __init__(self, default_rir: str, timeout: int):
self.__timeout = timeout
self.__rir = self.__rirs.get(default_rir, 'https://rdap.db.ripe.net')
self.__rir = self.__rirs.get(default_rir, 'https://rdap.db.ripe.net/')
self.__known_asns = {}
def get_whois_data_by_asn(self, asn: int) -> Dict[str, str]:
......@@ -521,7 +522,9 @@ class BgpWhois:
if asn < 64512 or (65536 < asn < 4200000000):
rir = self.__find_rir_by_asn(asn)
query = 'autnum'
data = _fetch_data(f'{rir}{query}/{asn}', self.__timeout)
url = f'{rir}{query}/{asn}'
data = _fetch_data(url, self.__timeout)
if data:
asn_info['as_name'] = data.get('name')
vcard_array = data.get('entities')[0].get('vcardArray')
......
......@@ -37,7 +37,7 @@
'web': ['plugins/views/inv_bgp_peer.py']},
'name': 'bgp_peer',
'title': 'BGP Peer',
'version': '2.2.7-20241220',
'version': '2.2.8-20250117',
'version.min_required': '2.3.0b1',
'version.packaged': 'cmk-mkp-tool 0.2.0',
'version.usable_until': '2.4.0b1'}
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