diff --git a/agent_based/bgp_peer.py b/agent_based/bgp_peer.py index fa8a2c9f9ec73aa3c30a8266012033d38c8f0c80..a36a35ff619a173e1ea04e05aa7e092b1052ca89 100644 --- a/agent_based/bgp_peer.py +++ b/agent_based/bgp_peer.py @@ -1,24 +1,13 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -############################################################################### -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -############################################################################### +# License: GNU General Public License v2 -############################################################################### -# Author: Thomas Wollner (tw@wollner-net.de) -############################################################################### +# Author: thl-cmk[at]outlook[dot]com +# URL : https://thl-cmk.hopto.org +# Date : 2021-10-25 + +# based on the BGP peer plugin by Thomas Wollner (tw@wollner-net.de) # # 2021-08-20: rewritten for CMK 2.0 by thl-cmk[at]outlook[dot]com # 2021-08-21: added more perfdata, added metrics file @@ -33,6 +22,7 @@ # 2022-05-09: made item name configurable (don't use address-family/routing-instance/VRF) # 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 # # Example Agent Output: @@ -49,7 +39,7 @@ # .1.3.6.1.2.1.15.3.1.11.192.168.254.2 = Counter32: 5 # .1.3.6.1.2.1.15.3.1.14.192.168.254.2 = Hex-STRING: 04 00 # .1.3.6.1.2.1.15.3.1.16.192.168.254.2 = Gauge32: 6586822 -############################################################################### +# import time from typing import Dict, Optional @@ -122,20 +112,8 @@ def discovery_bgp_peer(params, section: Dict[str, BgpPeer]) -> DiscoveryResult: def check_bgp_peer(item, params, section: Dict[str, BgpPeer]) -> CheckResult: - # default monitoring states for bgpPeerState - neighborstate = { - '1': 2, # idle - '2': 1, # connect - '3': 1, # active - '4': 1, # opensent - '5': 1, # openconfirm - '6': 0, # established - } - item = params.get('internal_item', item) - - neighborstate.update(params.get('neighborstate', neighborstate)) # update neighbor status with params - + neighborstate = params['neighborstate'] peer_not_found_state = params['peernotfound'] for bgp_connection, bgp_alias, not_found_state in params.get('peer_list', []): @@ -251,6 +229,17 @@ register.check_plugin( 'peernotfound': 2, 'admindown': 1, 'noprefixlimit': 1, + 'accepted_prefixes_upper_levels': (None, None), + 'accepted_prefixes_lower_levels': (None, None), + 'neighborstate': { + '1': 2, # idle + '2': 1, # connect + '3': 1, # active + '4': 1, # opensent + '5': 1, # openconfirm + '6': 0, # established + }, + 'internal_item': None, }, check_ruleset_name='bgp_peer', ) diff --git a/bgp_peer.mkp b/bgp_peer.mkp index 685389e92076764703ab453c17472d4fd0001ac6..6e2180eca3d94dd4e65d876df55c747e87108fe9 100644 Binary files a/bgp_peer.mkp and b/bgp_peer.mkp differ diff --git a/packages/bgp_peer b/packages/bgp_peer index fc7af17e58970a94c1c3abf90c7c3b785e4264c7..a8968459c9fce3d6ae40d5c4d74563a8583a74fb 100644 --- a/packages/bgp_peer +++ b/packages/bgp_peer @@ -20,7 +20,7 @@ 'name': 'bgp_peer', 'num_files': 8, 'title': 'BGP Peer State Check', - 'version': '20220512.v1.8', + 'version': '220905.v1.8a', '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/wato/bgp_peer.py b/web/plugins/wato/bgp_peer.py index 9f80635dbf9c874be52951b261447f9921bbacbd..8d5d1ba51c2426c8899410263f820669170c3af4 100644 --- a/web/plugins/wato/bgp_peer.py +++ b/web/plugins/wato/bgp_peer.py @@ -16,6 +16,7 @@ # 2022-04-29: added upper/lower prefix limit # 2022-05-09: added discovery rule set # 2022-05-11: added remote_as to build_item +# 2022-09-05: added internal_item to avoid warnings on cmk updates from cmk.gui.i18n import _ from cmk.gui.valuespec import ( @@ -39,157 +40,166 @@ from cmk.gui.plugins.wato import ( def _parameter_valuespec_bgp_peer(): - return Dictionary(elements=[ - ('minuptime', - Tuple( - title=_('Minimum uptime for peer'), - orientation='horizontal', - help=_('Set the time in seconds, a peer must be up before the peer is considered sable.'), - elements=[ - Integer(title=_('Warning below'), unit='seconds', default_value=7200, minvalue=0), - Integer(title=_('Critical below'), unit='seconds', default_value=3600, minvalue=0) - ], - )), - ('accepted_prefixes_upper_levels', - Tuple( - title=_('Accepted prefixes upper levels'), - help=_('The values from WATO are preferred to the values from the device.'), - orientation='horizontal', - elements=[ - Integer(title=_('Warning at'), minvalue=0, unit=_('prefixes'), size=5), - Integer(title=_('Critical at'), minvalue=0, unit=_('prefixes'), size=5), - ], - )), - ('accepted_prefixes_lower_levels', - Tuple( - title=_('Accepted prefixes lower levels'), - orientation='horizontal', - elements=[ - Integer(title=_('Warning below'), minvalue=0, unit=_('prefixes'), size=5), - Integer(title=_('Critical below'), minvalue=0, unit=_('prefixes'), size=5), - ], - )), - ('peernotfound', - MonitoringState( - default_value=2, - title=_('State if peer is no not found.'), - help=_('Default monitoring state if the peer is not found in the SNMP data') - )), - ('admindown', - MonitoringState( - default_value=1, - title=_('State if peer is admin shutdown.'), - help=_('Monitoring state if the peer is admin shutdown') - )), - ('neighborstate', - Dictionary( - title=_('State to report for BGP neighbor state'), - help=_('Map each BGP state to a CheckMK monitoring state'), - elements=[ - ('1', - MonitoringState( - title=_('1 - idle'), - help=_('This is the first stage of the BGP FSM. BGP detects a start event, tries to initiate a ' - 'TCP connection to the BGP peer, and also listens for a new connect from a peer router. ' - 'If an error causes BGP to go back to the Idle state for a second time, the ' - 'ConnectRetryTimer is set to 60 seconds and must decrement to zero before the connection ' - 'is initiated again. Further failures to leave the Idle state result in the ' - 'ConnectRetryTimer doubling in length from the previous time. ' - 'Default monitoring state is "CRIT"'), - default_value=2, - )), - ('2', - MonitoringState( - title=_('2 - connect'), - help=_('In this state, BGP initiates the TCP connection. If the 3-way TCP handshake completes, ' - 'the established BGP Session BGP process resets the ConnectRetryTimer and sends the Open ' - 'message to the neighbor, and then changes to the OpenSent State.' - 'Default monitoring state is "WARN"'), - default_value=1, - )), - ('3', - MonitoringState( - title=_('3 - active'), - help=_('In this state, BGP starts a new 3-way TCP handshake. If a connection is established, ' - 'an Open message is sent, the Hold Timer is set to 4 minutes, and the state moves to ' - 'OpenSent. If this attempt for TCP connection fails, the state moves back to the Connect ' - 'state and resets the ConnectRetryTimer. ' - 'Default monitoring state is "WARN"'), - default_value=1, - )), - ('4', - MonitoringState( - title=_('4 - opensent'), - help=_('In this state, an Open message has been sent from the originating router and is awaiting ' - 'an Open message from the other router. After the originating router receives the OPEN ' - 'message from the other router, both OPEN messages are checked for errors. If the Open ' - 'messages do not have any errors, the Hold Time is negotiated (using the lower value), ' - 'and a KEEPALIVE message is sent (assuming the value is not set to zero). The connection ' - 'state is then moved to OpenConfirm. If an error is found in the OPEN message, a ' - 'Notification message is sent, and the state is moved back to Idle.' - ' Default monitoring state is "WARN"'), - default_value=1, - )), - ('5', - MonitoringState( - title=_('5 - openconfirm'), - help=_('In this state, BGP waits for a Keepalive or Notification message. Upon receipt of a ' - 'neighbor’s Keepalive, the state is moved to Established. If the hold timer expires, a ' - 'stop event occurs, or a Notification message is received, and the state is moved to ' - 'Idle. ' - 'Default monitoring state is "WARN"'), - default_value=1, - )), - ('6', - MonitoringState( - title=_('6 - established'), - help=_('In this state, the BGP session is established. BGP neighbors exchange routes via Update ' - 'messages. As Update and Keepalive messages are received, the Hold Timer is reset. If the ' - 'Hold Timer expires, an error is detected and BGP moves the neighbor back to the Idle ' - 'state. ' - 'Default monitoring state is "OK"'), - default_value=0, - )), - ])), - ('noprefixlimit', - MonitoringState( - default_value=1, - title=_('State if no admin prefix limit/warn threshold is configured.'), - help=_('The admin prefix limit and warn threshold needs to be configured on the device. ' - 'For example: "neighbor 172.17.10.10 maximum-prefix 10000 80". The threshold is in percentage ' - 'of the prefix limit.') - )), - ('peer_list', - ListOf( + return Dictionary( + elements=[ + ('minuptime', Tuple( + title=_('Minimum uptime for peer'), orientation='horizontal', + help=_('Set the time in seconds, a peer must be up before the peer is considered sable.'), elements=[ - TextUnicode( - title=_('BGP Peer'), - help=_('The configured value must match a BGP item reported by the monitored ' - 'device. For example: "10.194.115.98" or "2A10:1CD0:1020:135::20 IPv6 Unicast"'), - allow_empty=False, - size=50, - ), - TextUnicode( - title=_('BGP Peer Alias'), - help=_('You can configure an individual alias here for the BGP peer matching ' - 'the text configured in the "BGP Peer IP-address" field. The alias will ' - 'be shown in the check info'), - size=50, - ), - MonitoringState( - default_value=2, - title=_('State if not found'), - help=_('You can configure an individual state if the BGP peer matching the text ' - 'configured in the "BGP Peer IP-address" field is not found') - ), - ]), - add_label=_('Add BGP peer'), - movable=False, - title=_('BGP Peers'), - )), - ]) + Integer(title=_('Warning below'), unit='seconds', default_value=7200, minvalue=0), + Integer(title=_('Critical below'), unit='seconds', default_value=3600, minvalue=0) + ], + )), + ('accepted_prefixes_upper_levels', + Tuple( + title=_('Accepted prefixes upper levels'), + help=_('The values from WATO are preferred to the values from the device.'), + orientation='horizontal', + elements=[ + Integer(title=_('Warning at'), minvalue=0, unit=_('prefixes'), size=5), + Integer(title=_('Critical at'), minvalue=0, unit=_('prefixes'), size=5), + ], + )), + ('accepted_prefixes_lower_levels', + Tuple( + title=_('Accepted prefixes lower levels'), + orientation='horizontal', + elements=[ + Integer(title=_('Warning below'), minvalue=0, unit=_('prefixes'), size=5), + Integer(title=_('Critical below'), minvalue=0, unit=_('prefixes'), size=5), + ], + )), + ('peernotfound', + MonitoringState( + default_value=2, + title=_('State if peer is no not found.'), + help=_('Default monitoring state if the peer is not found in the SNMP data') + )), + ('admindown', + MonitoringState( + default_value=1, + title=_('State if peer is admin shutdown.'), + help=_('Monitoring state if the peer is admin shutdown') + )), + ('neighborstate', + Dictionary( + title=_('State to report for BGP neighbor state'), + help=_('Map each BGP state to a CheckMK monitoring state'), + elements=[ + ('1', + MonitoringState( + title=_('1 - idle'), + help=_( + 'This is the first stage of the BGP FSM. BGP detects a start event, tries to initiate a ' + 'TCP connection to the BGP peer, and also listens for a new connect from a peer router. ' + 'If an error causes BGP to go back to the Idle state for a second time, the ' + 'ConnectRetryTimer is set to 60 seconds and must decrement to zero before the connection ' + 'is initiated again. Further failures to leave the Idle state result in the ' + 'ConnectRetryTimer doubling in length from the previous time. ' + 'Default monitoring state is "CRIT"'), + default_value=2, + )), + ('2', + MonitoringState( + title=_('2 - connect'), + help=_( + 'In this state, BGP initiates the TCP connection. If the 3-way TCP handshake completes, ' + 'the established BGP Session BGP process resets the ConnectRetryTimer and sends the Open ' + 'message to the neighbor, and then changes to the OpenSent State.' + 'Default monitoring state is "WARN"'), + default_value=1, + )), + ('3', + MonitoringState( + title=_('3 - active'), + help=_('In this state, BGP starts a new 3-way TCP handshake. If a connection is established, ' + 'an Open message is sent, the Hold Timer is set to 4 minutes, and the state moves to ' + 'OpenSent. If this attempt for TCP connection fails, the state moves back to the Connect ' + 'state and resets the ConnectRetryTimer. ' + 'Default monitoring state is "WARN"'), + default_value=1, + )), + ('4', + MonitoringState( + title=_('4 - opensent'), + help=_( + 'In this state, an Open message has been sent from the originating router and is awaiting ' + 'an Open message from the other router. After the originating router receives the OPEN ' + 'message from the other router, both OPEN messages are checked for errors. If the Open ' + 'messages do not have any errors, the Hold Time is negotiated (using the lower value), ' + 'and a KEEPALIVE message is sent (assuming the value is not set to zero). The connection ' + 'state is then moved to OpenConfirm. If an error is found in the OPEN message, a ' + 'Notification message is sent, and the state is moved back to Idle.' + ' Default monitoring state is "WARN"'), + default_value=1, + )), + ('5', + MonitoringState( + title=_('5 - openconfirm'), + help=_('In this state, BGP waits for a Keepalive or Notification message. Upon receipt of a ' + 'neighbor’s Keepalive, the state is moved to Established. If the hold timer expires, a ' + 'stop event occurs, or a Notification message is received, and the state is moved to ' + 'Idle. ' + 'Default monitoring state is "WARN"'), + default_value=1, + )), + ('6', + MonitoringState( + title=_('6 - established'), + help=_( + 'In this state, the BGP session is established. BGP neighbors exchange routes via Update ' + 'messages. As Update and Keepalive messages are received, the Hold Timer is reset. If the ' + 'Hold Timer expires, an error is detected and BGP moves the neighbor back to the Idle ' + 'state. ' + 'Default monitoring state is "OK"'), + default_value=0, + )), + ])), + ('noprefixlimit', + MonitoringState( + default_value=1, + title=_('State if no admin prefix limit/warn threshold is configured.'), + help=_('The admin prefix limit and warn threshold needs to be configured on the device. ' + 'For example: "neighbor 172.17.10.10 maximum-prefix 10000 80". The threshold is in percentage ' + 'of the prefix limit.') + )), + ('peer_list', + ListOf( + Tuple( + orientation='horizontal', + elements=[ + TextUnicode( + title=_('BGP Peer'), + help=_('The configured value must match a BGP item reported by the monitored ' + 'device. For example: "10.194.115.98" or "2A10:1CD0:1020:135::20 IPv6 Unicast"'), + allow_empty=False, + size=50, + ), + TextUnicode( + title=_('BGP Peer Alias'), + help=_('You can configure an individual alias here for the BGP peer matching ' + 'the text configured in the "BGP Peer IP-address" field. The alias will ' + 'be shown in the check info'), + size=50, + ), + MonitoringState( + default_value=2, + title=_('State if not found'), + help=_('You can configure an individual state if the BGP peer matching the text ' + 'configured in the "BGP Peer IP-address" field is not found') + ), + ]), + add_label=_('Add BGP peer'), + movable=False, + title=_('BGP Peers'), + )), + ('internal_item', # added by plugin discovery function + TextUnicode()), + ], + hidden_keys=['internal_item'], + ) rulespec_registry.register(