diff --git a/check_ospf_nbr.py b/check_ospf_nbr.py index 8ae37a66c32e422c242b571a3d2822b27ce4e8f6..0ec03de7bffc08def63b16e90911cfeb88b79873 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)