diff --git a/CHANGELOG b/CHANGELOG index b76f66a104475663441b46366e72298556d5a8ed..c64446375afdf052f8fa3f3f403f3919550540aa 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -25,3 +25,7 @@ changed IPv6 address format to lower case as required by rfc5952 section-4.3 (this affects IPv6 items) 2022-09-05: added missing wato parameters to register.check_plugin check_default_parameters 2022-09-05: added internal_item to WATO as hidden_key to avoid warnings on cmk updates (THX to Jay2k1 for reporting the issue) +2022-09-11: optimized internal flow: > alias > not found > admin down > peer state > ... +2023-01-21: changed to always yield fsm_established_time (not only if beep connects, but also on all other states) +2023-01-20: add description to BgpPeerItem (for Arista) +2023-01-22: fix output for admin_state diff --git a/agent_based/bgp_peer.py b/agent_based/bgp_peer.py index 58c4bbec6137a7f30f214a351d0573a69523a3c8..0427531a4b1e2b6a45c72447df8b0b203efcdc82 100644 --- a/agent_based/bgp_peer.py +++ b/agent_based/bgp_peer.py @@ -23,8 +23,12 @@ # 2022-05-11: changed bgp_get_peer_entry to get proper parameters instead of Nontransparent list # added remote_as to BgpPeerItem # 2022-09-05: added missing wato parameters to register.check_plugin check_default_parameters -# 2022-09-10: made more reliable on limited data (fsm_established_time and admin_state) (THX to martin[dot]pechstein[at]posteo[dot]de) +# 2022-09-10: made more reliable on limited data (fsm_established_time and admin_state) +# (THX to martin[dot]pechstein[at]posteo[dot]de) # 2022-09-11: optimized internal flow: > alias > not found > admin down > peer state > ... +# 2023-01-21: changed to always yield fsm_established_time (not only if beep connects, but also on all other states) +# 2023-01-22: fix output for admin_state +# # Example Agent Output: # BGP4-MIB @@ -68,6 +72,8 @@ from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import ( from cmk.base.plugins.agent_based.utils.bgp_peer import ( BgpPeer, bgp_get_peer_entry, + bgp_adminstate, + bgp_peerstate, ) @@ -130,16 +136,29 @@ def check_bgp_peer(item, params, section: Dict[str, BgpPeer]) -> CheckResult: yield Result(state=State(peer_not_found_state), summary='Item not found in SNMP data') return + if peer.description: + yield Result(state=State.OK, summary=f'[{peer.description}]', details=' ') + if peer.admin_state == 1: # shutdown - yield Result(state=State(params['admindown']), summary=f'Admin state: {peer.peer_statestr}') + yield Result(state=State(params['admindown']), summary=f'Admin state: {bgp_adminstate(peer.admin_state)}') return - yield Result(state=State(neighborstate.get(str(peer.peer_state))), notice=f'Peer state: {peer.peer_statestr}') + yield Result( + state=State(neighborstate.get(str(peer.peer_state))), + notice=f'Peer state: {bgp_peerstate(peer.peer_state)}' + ) + + if peer.fsm_established_time: # always yield fsm_established time + yield Metric( + name=f'bgp_peer_fsmestablishedtime', + value=peer.fsm_established_time, + boundaries=(0, None) + ) if not peer.peer_state == 6: # not established return - if peer.fsm_established_time: # fms_time not None + if peer.fsm_established_time: # if peer is established use fsm_established_time as uptime yield from check_levels( value=peer.fsm_established_time, label='Uptime', diff --git a/agent_based/inv_bgp_peer.py b/agent_based/inv_bgp_peer.py index 0262c145f9bc9c4bfbe53b14ef7a9127cde91a05..9ed2db7da05fdaf040c99f03bebe5f6aaaae2102 100644 --- a/agent_based/inv_bgp_peer.py +++ b/agent_based/inv_bgp_peer.py @@ -10,6 +10,7 @@ # inventory of bgp peers # # 2022-04-30: code cleanup/streamlining +# 2023-01-17: always remove fsm_established_time # import time @@ -102,8 +103,12 @@ def inventory_bgp_peers(params, section) -> InventoryResult: pass fsm_established_time = bgp_peer.get('fsm_established_time') - if fsm_established_time: + try: bgp_peer.pop('fsm_established_time') + except KeyError: + pass + + if fsm_established_time: peer_state = bgp_peer.get('peer_state') in_service = True not_in_service_time = params.get('not_in_service_time', 2592000) diff --git a/agent_based/utils/bgp_peer.py b/agent_based/utils/bgp_peer.py index 803d1c2a884914018de60c639ccf58646b22556c..c3123f24126adcbcfdbb374b5c94c80cba3c6a03 100644 --- a/agent_based/utils/bgp_peer.py +++ b/agent_based/utils/bgp_peer.py @@ -17,6 +17,7 @@ # 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 items) +# 2023-01-20: add description to BgpPeerItem (for Arista) # # https://ftp.ripe.net/ripe/asnames/asn.txt AS Name List @@ -39,7 +40,7 @@ class BgpPeerItem(TypedDict): @dataclass class BgpPeer: peer_state: int - peer_statestr: str + # peer_statestr: str admin_statestr: str metric_rate: List[Tuple[str, int]] metric_count: List[Tuple[str, int]] @@ -53,6 +54,7 @@ class BgpPeer: accepted_prefixes: Optional[int] peer_unavail_reason: Optional[int] peer_unavail_reason_str: Optional[str] + description: Optional[str] class InvBgpPeer(TypedDict): @@ -215,18 +217,19 @@ def bgp_get_peer_entry( remote_as: str, peer_state: str, fsm_established_transitions: str, - fsm_established_time: Optional[str], - admin_state: Optional[str], - in_updates: Optional[str], - out_updates: Optional[str], - in_messages: Optional[str], - out_messages: Optional[str], - in_update_elapsed_time: Optional[str], + fsm_established_time: Optional[str] = None, + admin_state: Optional[str] = None, + in_updates: Optional[str] = None, + out_updates: Optional[str] = None, + in_messages: Optional[str] = None, + out_messages: Optional[str] = None, + in_update_elapsed_time: Optional[str] = None, + description: Optional[str] = None, ) -> Optional[Dict[str, BgpPeer]]: bgp_peer = BgpPeer( peer_state=int(peer_state), - peer_statestr=bgp_peerstate(int(peer_state)), + # peer_statestr=bgp_peerstate(int(peer_state)), admin_state=int(admin_state) if admin_state.isdigit() else None, admin_statestr=bgp_adminstate(int(admin_state) if admin_state.isdigit() else None), fsm_established_time=int(fsm_established_time) if fsm_established_time.isdigit() else None, @@ -245,6 +248,7 @@ def bgp_get_peer_entry( accepted_prefixes=None, peer_unavail_reason=0, peer_unavail_reason_str='', + description=description if description else '' ) for key, value in [ @@ -260,7 +264,7 @@ def bgp_get_peer_entry( for key, value in [ ('fsmestablishedtransitions', fsm_established_transitions), - ('inupdateelapsedtime', in_update_elapsed_time), + # ('inupdateelapsedtime', in_update_elapsed_time), ]: try: bgp_peer.metric_count.append((key, int(value))) diff --git a/bgp_peer.mkp b/bgp_peer.mkp index d0b078c448371845ebd4ce3f5c2e79fd972788c5..f0effdd8dae4f037d446f186132bc65c83270bfc 100644 Binary files a/bgp_peer.mkp and b/bgp_peer.mkp differ diff --git a/packages/bgp_peer b/packages/bgp_peer index 1bb1006e6df22d5f720bcc980fb76e922498b94a..ab8d2689320df911d7f4d800f682fa7e32f1739e 100644 --- a/packages/bgp_peer +++ b/packages/bgp_peer @@ -1,4 +1,5 @@ -{'author': 'Th.L. (thl-cmk[at]outlook[dot]com)', +{'2023-01-23: added support for Arista Networks\ndownload_url': 'https://thl-cmk.hopto.org', + 'author': 'Th.L. (thl-cmk[at]outlook[dot]com)', 'description': 'based on BGP Peer State Check by Thomas Wollner\n' '\n' 'Rewritten for CMK 2.0 by thl-cmk[at]outlook[dot]com\n' @@ -8,7 +9,6 @@ '2021-11-08: added helper functions from cisco_bgp_peer\n' '2021-11-14: merged with cisco_bgp_peer\n' '2022-04-18: merged with huawei_bgp_peer\n', - 'download_url': 'https://thl-cmk.hopto.org', 'files': {'agent_based': ['bgp_peer.py', 'inv_bgp_peer.py', 'utils/bgp_peer.py'], @@ -20,7 +20,7 @@ 'name': 'bgp_peer', 'num_files': 8, 'title': 'BGP Peer State Check', - 'version': '20220911.v1.8b', + 'version': '20230123.v1.9', 'version.min_required': '2.0.0', 'version.packaged': '2021.09.20', 'version.usable_until': None} \ No newline at end of file diff --git a/web/plugins/metrics/bgp_peer.py b/web/plugins/metrics/bgp_peer.py index 21c2c7f18a66cafdfbb5385b986965d5a15d1553..57b58ff041134f8e9d4330f8de9dec966ebec20d 100644 --- a/web/plugins/metrics/bgp_peer.py +++ b/web/plugins/metrics/bgp_peer.py @@ -222,4 +222,4 @@ perfometer_info.append({ 'metric': 'bgp_peer_fsmestablishedtime', 'half_value': 2592000.0, # ome month 'exponent': 2, -}) \ No newline at end of file +})