From 252339dd1c346fe8de63034bac0d40fdada667dc Mon Sep 17 00:00:00 2001 From: Thomas Bellman <bellman@nsc.liu.se> Date: Fri, 12 Feb 2021 14:09:43 +0100 Subject: [PATCH] Workaround for Junos 20.x OSPFv3 SNMP bug. Some recent Junos versions, at least 20.3 and 20.4, but not 19.3 and earlier, return a 9 in OSPFV3-MIB::ospfv3NbrRtrId when the neighbour state is full, instead of 8 as the MIB prescribes. Add a workaround for that, accepting 9 as an acceptable state in case the device is determined to be running Juniper Junos OS. (Properly, we would only do so if the Junos version is in a certain range, but as we don't know exactly which versions are, or will be, affected, we just do it for all versions of Junos.) We haven't reported this problem to Juniper yet, but we will do so. --- check_ospf_nbr.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/check_ospf_nbr.py b/check_ospf_nbr.py index 8ae37a6..0ec03de 100755 --- a/check_ospf_nbr.py +++ b/check_ospf_nbr.py @@ -274,7 +274,8 @@ def filter_ospf2_neighbours(nbrTable, snmpsession, def check_ospf2_neighbour(snmpsession, statuses, - ifindex, router_id, peer_addr): + ifindex, router_id, peer_addr, + vendor=None): """Verify that an OSPFv2 neighbour exists and is in state 'full'. The neighbour is identified by the IFINDEX, ROUTER_ID and PEER_ADDR @@ -372,7 +373,8 @@ def filter_ospf3_neighbours(nbrTable, snmpsession, def check_ospf3_neighbour(snmpsession, statuses, - ifindex, router_id): + ifindex, router_id, + vendor=None): """Verify that an OSPFv3 neighbour exists and is in state 'full'. The neighbour is identified by the IFINDEX and ROUTER_ID parameters, @@ -387,15 +389,21 @@ def check_ospf3_neighbour(snmpsession, statuses, The return value will be the STATUSES dictionary. Thus it is OK to call this function as - st = check_ospf2_neighbour(s, {}, <match-criteria...>) + st = check_ospf3_neighbour(s, {}, <match-criteria...>) """ + OK_STATES = ('full', '8',) + # Some versions of Junos (at least 20.3 and 20.4, but not 19.3 or earlier), + # return 9 instead of 8 ('full') when the neighbour is in state full. + if vendor == 'junos': + OK_STATES += ('9',) + all_nbrs = ospf3_neighbours(snmpsession) matching_nbrs = filter_ospf3_neighbours( all_nbrs, snmpsession, ifindex, router_id) for nbr in matching_nbrs.values(): message = "OSPFv3 neighbour %s state %s" % ( nbr.ospfv3NbrRtrId, nbr.ospfv3NbrState) - if nbr.ospfv3NbrState in ('full', '8',): + if nbr.ospfv3NbrState in OK_STATES: statuses.setdefault('OK', []).append(message) else: statuses.setdefault('CRITICAL', []).append(message) @@ -452,10 +460,12 @@ def main(argv): nbr_statuses = {} if OPTIONS.ospfv2: nbr_statuses = check_ospf2_neighbour( - s, nbr_statuses, ifindex, OPTIONS.neighbour_id, peer_address) + s, nbr_statuses, ifindex, OPTIONS.neighbour_id, peer_address, + vendor=OPTIONS.vendor) if OPTIONS.ospfv3: nbr_statuses = check_ospf3_neighbour( - s, nbr_statuses, ifindex, OPTIONS.neighbour_id) + s, nbr_statuses, ifindex, OPTIONS.neighbour_id, + vendor=OPTIONS.vendor) lvl,message = trh_nagioslib.nagios_report(nbr_statuses) sys.stdout.write(message) -- GitLab