diff --git a/agent_based/bgp_peer.py b/agent_based/bgp_peer.py index 36d776fea88b7f0d17669973fa2373b9cdc52fc8..a4bf779fd7bdf0650af54b4c759dda738f12e301 100644 --- a/agent_based/bgp_peer.py +++ b/agent_based/bgp_peer.py @@ -132,6 +132,9 @@ def check_bgp_peer(item, params, section: Dict[str, BgpPeer]) -> CheckResult: yield Result(state=State(neighborstate.get(str(peer.peer_state))), notice=f'Peer state: {peer.peer_statestr}') + if peer.peer_unavail_reason != 0: # huawei peer unavailable state + yield Result(state=State.CRIT, notice=F'Peer unavailable reason: {peer.peer_unavail_reason_str}') + acceptedprefixes = peer.accepted_prefixes prefixadminlimit = peer.prefix_admin_limit prefixthreshold = peer.prefix_threshold diff --git a/agent_based/utils/bgp_peer.py b/agent_based/utils/bgp_peer.py index 751acbfd1b2fc4ab4667a8f7797f648601bb9f20..f48d76448f996fd123a517aa727d72555e91c340 100644 --- a/agent_based/utils/bgp_peer.py +++ b/agent_based/utils/bgp_peer.py @@ -9,8 +9,11 @@ # # include file, will be used with bgp_peer, inv_bgp_peer, cisco_bgp_peer, inv_cisco_bgp_peer # +# 2022-04-17: added peer_unavail_reason/peer_unavail_reason_str for huawei bgp peers +# + import re -from typing import List, Tuple, Optional,Dict +from typing import List, Tuple, Optional, Dict from dataclasses import dataclass @@ -27,6 +30,8 @@ class BgpPeer: prefix_threshold: Optional[int] prefix_clear_threshold: Optional[int] accepted_prefixes: Optional[int] + peer_unavail_reason: Optional[int] + peer_unavail_reason_str: Optional[str] def sec2hr(seconds): @@ -184,6 +189,8 @@ def bgp_get_peer_entry(peer: List) -> Optional[Dict[str, BgpPeer]]: prefix_threshold=None, prefix_clear_threshold=None, accepted_prefixes=None, + peer_unavail_reason=0, + peer_unavail_reason_str='', ) for key, value in [ @@ -194,7 +201,7 @@ def bgp_get_peer_entry(peer: List) -> Optional[Dict[str, BgpPeer]]: ]: try: bgp_peer.metric_rate.append((key, int(value))) - except ValueError: + except (ValueError, TypeError): pass for key, value in [ @@ -203,7 +210,7 @@ def bgp_get_peer_entry(peer: List) -> Optional[Dict[str, BgpPeer]]: ]: try: bgp_peer.metric_count.append((key, int(value))) - except ValueError: + except (ValueError, TypeError): pass return {remote_addr: bgp_peer} diff --git a/bgp_peer.mkp b/bgp_peer.mkp index 60157fe0307a7c1b816c097bd33c8256351fab56..c86dfbe013fcdbc381fe5fed85a3c79c87c4e48f 100644 Binary files a/bgp_peer.mkp and b/bgp_peer.mkp differ diff --git a/web/plugins/metrics/bgp_peer.py b/web/plugins/metrics/bgp_peer.py index 60648cec7fa4a13f7cdb5a9bb7d685b59d912df1..d6cee6e915c4185a8275e51796040ddc4d879ecd 100644 --- a/web/plugins/metrics/bgp_peer.py +++ b/web/plugins/metrics/bgp_peer.py @@ -88,6 +88,8 @@ metric_info['bgp_peer_suppressedprefixes'] = { } + + ###################################################################################################################### # # how to graph perdata for bgp peer