Module: check_mk
Branch: master
Commit: 1cd7274e1e532a9834ecb5897ceaedda0e643714
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1cd7274e1e532a…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Tue Dec 4 14:23:36 2018 +0100
6943 FIX juniper_bgp_state: Fix item generation for IPv6 addresses
The check now extracts the proper remote IP address in case of
IPv6 addresses as item, instead of a part of the OID end.
This change requires a rediscovery.
CMK-1334
Change-Id: Ib3275f88dcca9ed1bb23bff92c6551c91796b3b7
---
.werks/6943 | 12 +++++++
checks/juniper_bgp_state | 42 ++++++++++++++++++----
.../datasets/juniper_bgp_state_1_regression.py | 14 ++++----
.../datasets/juniper_bgp_state_ip_addresses.py | 37 +++++++++++++++++++
4 files changed, 92 insertions(+), 13 deletions(-)
diff --git a/.werks/6943 b/.werks/6943
new file mode 100644
index 0000000..cb160b9
--- /dev/null
+++ b/.werks/6943
@@ -0,0 +1,12 @@
+Title: juniper_bgp_state: Fix item generation for IPv6 addresses
+Level: 1
+Component: checks
+Compatible: incomp
+Edition: cre
+Version: 1.6.0i1
+Date: 1543929566
+Class: fix
+
+The check now extracts the proper remote IP address in case of
+IPv6 addresses as item, instead of a part of the OID end.
+This change requires a rediscovery.
diff --git a/checks/juniper_bgp_state b/checks/juniper_bgp_state
index 4bbcb60..04e26dc 100644
--- a/checks/juniper_bgp_state
+++ b/checks/juniper_bgp_state
@@ -25,8 +25,39 @@
# Boston, MA 02110-1301 USA.
-def juniper_bgp_state_create_item(oid_end):
- return re.sub(r"[0-9]+\.1\.[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\.1\.",
"", oid_end)
+def _clean_v4_address(chunks):
+ return "%d.%d.%d.%d" % tuple(int(c, 16) for c in chunks)
+
+
+def _clean_v6_address(chunks):
+ ichunks = iter(chunks)
+ blocks = ("%s%s" % pair for pair in zip(ichunks, ichunks))
+ stripped_blocks = ('0' if b == '0000' else b.lstrip('0') for
b in blocks)
+ v6_string = ':'.join(b.lower() for b in stripped_blocks)
+
+ # replace longest series of zeros
+ for length in range(8, 0, -1):
+ subs = ':'.join('0' * length)
+ if subs in v6_string:
+ shortened = v6_string.replace(subs, '', 1)
+ if not shortened or shortened.startswith(':'):
+ shortened = ':' + shortened
+ if shortened.endswith(':'):
+ shortened += ':'
+ return '[%s]' % shortened
+ return v6_string
+
+
+def juniper_bgp_state_create_item(peering_entry):
+ chunks = peering_entry.split()
+ try:
+ if len(chunks) == 4:
+ return _clean_v4_address(chunks)
+ elif len(chunks) == 16:
+ return _clean_v6_address(chunks)
+ except (ValueError, IndexError):
+ pass
+ return "'%s'" % peering_entry.strip()
def parse_juniper_bgp_state(info):
@@ -45,8 +76,8 @@ def parse_juniper_bgp_state(info):
"2": "running" # 2
}
parsed = {}
- for oid_end, state, operational_state in info:
- item = juniper_bgp_state_create_item(oid_end)
+ for state, operational_state, peering_entry in info:
+ item = juniper_bgp_state_create_item(peering_entry)
state_txt = bgp_state_map.get(state.strip(), "undefined")
operational_txt = bgp_operational_state_map.get(operational_state.strip(),
"undefined")
@@ -59,7 +90,6 @@ def parse_juniper_bgp_state(info):
@get_parsed_item_data
def check_juniper_bgp_state(item, _no_params, data):
-
state = data.get('state', "undefined")
operational_state = data.get('operational_state', "undefined")
@@ -86,9 +116,9 @@ check_info["juniper_bgp_state"] = {
"snmp_info": (
'.1.3.6.1.4.1.2636.5.1.1.2.1.1.1',
[
- OID_END, # take peering partner IP from this
2, # jnxBgpM2PeerState
3, # jnxBgpM2PeerStatus (like operational status)
+ 11, # jnxBgpM2PeerRemoteAddr
]),
"snmp_scan_function":
lambda oid:
oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.2636.1.1.1"),
diff --git a/tests/unit/checks/generictests/datasets/juniper_bgp_state_1_regression.py
b/tests/unit/checks/generictests/datasets/juniper_bgp_state_1_regression.py
index 90ff830..83064b9 100644
--- a/tests/unit/checks/generictests/datasets/juniper_bgp_state_1_regression.py
+++ b/tests/unit/checks/generictests/datasets/juniper_bgp_state_1_regression.py
@@ -1,22 +1,22 @@
checkname = 'juniper_bgp_state'
info = [
- [u'6.1.80.81.193.134.1.80.81.192.3', u'6', u'2'],
- [u'6.1.80.81.193.134.1.80.81.192.24', u'3', u'2'],
+ [u'6', u'2', '64 60 01 22'],
+ [u'3', u'2', '64 60 01 26'],
]
discovery = {
- '': [(u'80.81.192.24', {}), (u'80.81.192.3', {}),
+ '': [(u'100.96.1.34', {}), (u'100.96.1.38', {}),
]
}
checks = {
'': [
- (u'80.81.192.24', 'default',
- [(2, u'Status with peer 80.81.192.24 is active', []),
+ (u'100.96.1.34', 'default',
+ [(0, u'Status with peer 100.96.1.34 is established', []),
(0, 'operational status: running', [])]),
- (u'80.81.192.3', 'default',
- [(0, u'Status with peer 80.81.192.3 is established', []),
+ (u'100.96.1.38', 'default',
+ [(2, u'Status with peer 100.96.1.38 is active', []),
(0, 'operational status: running', [])]),
]
}
diff --git a/tests/unit/checks/generictests/datasets/juniper_bgp_state_ip_addresses.py
b/tests/unit/checks/generictests/datasets/juniper_bgp_state_ip_addresses.py
new file mode 100644
index 0000000..1d8c10c
--- /dev/null
+++ b/tests/unit/checks/generictests/datasets/juniper_bgp_state_ip_addresses.py
@@ -0,0 +1,37 @@
+checkname = 'juniper_bgp_state'
+
+info = [
+ [u'4', u'1', 'DE AD BE EF 00 40 01 11 00 00 00 00 00 00 00
01'],
+ [u'4', u'2', '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00'],
+ [u'4', u'2', 'DE AD BE EF 00 40 01 11 00 00 00 00 00 00 00
00'],
+ [u'4', u'1', '00 00 00 00 00 40 01 11 00 00 10 0A 00 00 00
00'],
+ [u'5', u'2', 'this is not a valid IP'],
+]
+
+discovery = {
+ '': [
+ (u'[dead:beef:40:111::1]', {}), (u'[::]', {}),
+ (u'[dead:beef:40:111::]', {}), (u'[::40:111:0:100a:0:0]', {}),
+ (u"'this is not a valid IP'", {}),
+ ]
+}
+
+checks = {
+ '': [
+ (u'[dead:beef:40:111::1]', 'default',
+ [(0, u'Status with peer [dead:beef:40:111::1] is opensent', []),
+ (1, 'operational status: halted', [])]),
+ (u'[::]', 'default',
+ [(2, u'Status with peer [::] is opensent', []),
+ (0, 'operational status: running', [])]),
+ (u'[dead:beef:40:111::]', 'default',
+ [(2, u'Status with peer [dead:beef:40:111::] is opensent', []),
+ (0, 'operational status: running', [])]),
+ (u'[::40:111:0:100a:0:0]', 'default',
+ [(0, u'Status with peer [::40:111:0:100a:0:0] is opensent', []),
+ (1, 'operational status: halted', [])]),
+ (u"'this is not a valid IP'", 'default',
+ [(2, u"Status with peer 'this is not a valid IP' is
openconfirm", []),
+ (0, 'operational status: running', [])]),
+ ]
+}