[Mon-commit] mon-contrib/monitors/ospf ospf.monitor,1.1,1.2
Brought to you by:
trockij
From: Jim T. <tr...@us...> - 2011-05-04 23:10:49
|
Update of /cvsroot/mon/mon-contrib/monitors/ospf In directory vz-cvs-4.sog:/tmp/cvs-serv5600/monitors/ospf Modified Files: ospf.monitor Log Message: rbl.monitor - bug: rbl.monitor was incorrectly using the IP in the DNS response to announce which IP was blacklisted, but sometimes that response was different than the IP in the DNS request. rbl.monitor - added copyright/license info ospf.monitor - alarm if an OSPF-active interface has no neighbors ospf.monitor - new --neighbormin option alarms if less than N neighbors total -added some text to the contrib guidelines indicating that a "license" file should be submitted as well. Index: ospf.monitor =================================================================== RCS file: /cvsroot/mon/mon-contrib/monitors/ospf/ospf.monitor,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ospf.monitor 14 Feb 2006 19:26:29 -0000 1.1 --- ospf.monitor 4 May 2011 23:10:46 -0000 1.2 *************** *** 3,8 **** # Router ospf (Open Shortest Path First) monitor # Look at each router and get the status of all OSPF neighbors. # Issue alarm if any interfaces configured for neighbors do not ! # have a full adjacencies # Detail log shows status of all enabled OSPF interfaces. --- 3,12 ---- # Router ospf (Open Shortest Path First) monitor # Look at each router and get the status of all OSPF neighbors. + # Look at each router and get the status of all OSPF interfaces. # Issue alarm if any interfaces configured for neighbors do not ! # have a full adjacencies (but fails for point-to-point state) ! # Try to match OSPF neighbors to their interfaces ! # Issue alarm for any interface that does not have at least one neighbor ! # (i.e. kludge to catch point-to-point state problem) # Detail log shows status of all enabled OSPF interfaces. *************** *** 30,42 **** # # Loosely based on bgp.monitor which is: ! # Copyright 2002, by Marc Hauswirth, Safe Host SA <ma...@sa...> ! # ! # Some inspiration is taked from others mon monitors and from ! # routerinfo.pl by Ben Buxton (bb...@zi...), also under GPL, see http://www.zipworld.com.au/~bb/linux/ ! # and from routerint.monitor by P. Strauss (ph...@ph...) and me self (ma...@sa...). ! # # This script need the SNMP Session module from Simon Leinen <si...@sw...> ! # Wich you could found under http://www.switch.ch/misc/leinen/snmp/perl/ # It is also part of MRTG (http://people.ee.ethz.ch/~oetiker/webtools/mrtg/) --- 34,46 ---- # # Loosely based on bgp.monitor which is: ! ### Copyright 2002, by Marc Hauswirth, Safe Host SA <ma...@sa...> ! ### ! ### Some inspiration is taked from others mon monitors and from ! ### routerinfo.pl by Ben Buxton (bb...@zi...), also under GPL, see http://www.zipworld.com.au/~bb/linux/ ! ### and from routerint.monitor by P. Strauss (ph...@ph...) and me self (ma...@sa...). ! ### # This script need the SNMP Session module from Simon Leinen <si...@sw...> ! # Which you could found under http://www.switch.ch/misc/leinen/snmp/perl/ # It is also part of MRTG (http://people.ee.ethz.ch/~oetiker/webtools/mrtg/) *************** *** 51,56 **** $opt{'exclude'}= ""; $opt{'debug'}= undef; ! my $usage="Usage: [COMMUNITY=str] ospf.monitor [--exclude regexp] [--community str] [--timeout usecs] [--version N] [--retries nn] router [...]\n"; ! GetOptions(\%opt, "exclude=s", "community=s", "timeout=i", "version=i", "retries=i", "debug") or die $usage; # It's highly unlikely someone wants dots in an IP address to be treated --- 55,60 ---- $opt{'exclude'}= ""; $opt{'debug'}= undef; ! my $usage="Usage: [COMMUNITY=str] ospf.monitor [--exclude regexp] [--community str] [--timeout usecs] [--version N] [--retries nn] [--neighbormin N] router [...]\n"; ! GetOptions(\%opt, "exclude=s", "community=s", "timeout=i", "version=i", "retries=i", "debug", "neighbormin=i") or die $usage; # It's highly unlikely someone wants dots in an IP address to be treated *************** *** 68,71 **** --- 72,76 ---- my $retries= $opt{'retries'} || 3; my $version= $opt{'version'} || 1; + my $neighbormin= $opt{'neighbormin'} || 0; ## -- *************** *** 84,87 **** --- 89,93 ---- "SysUptime" => "1.3.6.1.2.1.1.3.0", "ifDescr" => "1.3.6.1.2.1.2.2.1.2", + "ipAdEntNetMask" => "1.3.6.1.2.1.4.20.1.3" , "ospfRouterId" => "1.3.6.1.2.1.14.1.1" , "ospfIfIpAddress" => "1.3.6.1.2.1.14.7.1.1" , *************** *** 89,92 **** --- 95,99 ---- "ospfIfAdminStat" => "1.3.6.1.2.1.14.7.1.5" , "ospfIfState" => "1.3.6.1.2.1.14.7.1.12" , + "ospfNbrState" => "1.3.6.1.2.1.14.10.1.6" , ); *************** *** 102,105 **** --- 109,124 ---- ); + my %ospfNbrStates = ( + 1 => "down", + 2 => "attempt", + 3 => "init", + 4 => "twoWay", + 5 => "exchangeStart", + 6 => "exchange", + 7 => "loading", + 8 => "full", + ); + + my %ospfAdminStatus = ( 1 => "enabled", *************** *** 120,130 **** { push @failures, $router; ! push @details, "$router: error on SNMP get of $oidstr.$instance: $session->{ErrorStr}"; return 0; } return $result; } foreach $router (@ARGV) { # Get some infos about this router my $sess = new SNMP::Session ( DestHost => $router, --- 139,169 ---- { push @failures, $router; ! push @details, "$router: error on SNMP get of $oidstr/$oids{$oidstr}.$instance: $session->{ErrorStr}"; return 0; } return $result; } + + sub ip2val # octet string + { + my @octets= split('\.', $_[0]); + pop @octets if @octets == 5; # dump the .0, if it exists + die "$0: ip2val: bad input, expected 4 octets got " . scalar @octets unless @octets == 4; + my $maskval= 0; + map {$maskval= ($maskval << 8) | $_} @octets; + return $maskval; + } + + sub i2ip # drop instance number from IP value + { + return substr($_[0], 0, -2); + } + + + # MAIN + foreach $router (@ARGV) { # Get some infos about this router + my $vars; my $sess = new SNMP::Session ( DestHost => $router, *************** *** 137,141 **** { push @failures, $router; - push @details, "$router: cannot create SNMP session"; next; } --- 176,179 ---- *************** *** 145,152 **** push @details, "$router (Router-ID $ospfRouterID)"; # Find the indexes of the interfaces with OSPF enabled my @ospfinterfaces; ! my $vars = new SNMP::VarList([$oids{ospfIfAdminStat}]); for (my @vals = $sess->getnext($vars); $vars->[0]->tag =~ /1\.3\.6\.1\.2\.1\.14\.7\.1\.5/ # still in table (Did you have a cleaner solutions ?) --- 183,206 ---- push @details, "$router (Router-ID $ospfRouterID)"; + my %ospfNeighbors; + + # Discover all active OSPF neighbors, and their states + $vars = new SNMP::VarList([$oids{ospfNbrState}]); + for (my @vals= $sess->getnext($vars); + $vars->[0]->tag =~ /1\.3\.6\.1\.2\.1\.14\.10\.1\.6/ # still in table (Did you have a cleaner solutions ?) + and + not $sess->{ErrorStr}; # and not end of mib or other error + @vals = $sess->getnext($vars)) + { + # trim down OID to keep just the interface part + my $neighbor= $vars->[0]->tag; + $neighbor =~ s/^\.$oids{ospfNbrState}\.//; + $ospfNeighbors{$neighbor}= $ospfNbrStates{$vals[0]}; + } + # Find the indexes of the interfaces with OSPF enabled my @ospfinterfaces; ! $vars = new SNMP::VarList([$oids{ospfIfAdminStat}]); for (my @vals = $sess->getnext($vars); $vars->[0]->tag =~ /1\.3\.6\.1\.2\.1\.14\.7\.1\.5/ # still in table (Did you have a cleaner solutions ?) *************** *** 168,176 **** my $ifstate = snmpget1($sess, "ospfIfState", "$int"); my $ifinfo= $int; if ($int =~ /0\.0\.0\.0\.(\d+)$/) { my $ifindex= $1; $ifinfo= snmpget1($sess, "ifDescr", $ifindex) . " (.$ifindex)"; } ! push @details, sprintf("$router: Interface %-23s %-15s",$ifinfo, $ospfIfStates{$ifstate}); # if ospfIfState not in [4..7] (OSPF full adjacency states) --- 222,231 ---- my $ifstate = snmpget1($sess, "ospfIfState", "$int"); my $ifinfo= $int; + if ($int =~ /0\.0\.0\.0\.(\d+)$/) { my $ifindex= $1; $ifinfo= snmpget1($sess, "ifDescr", $ifindex) . " (.$ifindex)"; } ! push @details, sprintf("$router: Interface %-15s %-15s", i2ip($ifinfo), $ospfIfStates{$ifstate}); # if ospfIfState not in [4..7] (OSPF full adjacency states) *************** *** 178,185 **** --- 233,265 ---- push @failures, $router unless $int =~ /$opt{exclude}\b/ or grep(/^$router$/, @failures); $details[$#details] .= " [NO ADJACENCY]"; + } else { + # try to find the active neighbors for this interface by + # using the interface's netmask. + my $ifip= $ifinfo; + $ifip =~ s/\.0$//; # drop that annoying .0 + my $ipmask= ip2val(snmpget1($sess, "ipAdEntNetMask", $ifip)); + my $neighborcount= 0; + foreach my $nabe (keys %ospfNeighbors) { + if ( (ip2val($nabe) & $ipmask) == (ip2val($ifip) & $ipmask) ) + { + push @details, sprintf("$router: Interface %-15s neighbor %-15s state %s", i2ip($ifinfo), i2ip($nabe), $ospfNeighbors{$nabe}); + $neighborcount++; + } + } + if ($neighborcount == 0) { + # no neighbor found for this interface, issue a warning + push @failures, $router unless $int =~ /$opt{exclude}\b/ or grep(/^$router$/, @failures); + push @details, sprintf("$router: Interface %-15s [NO NEIGHBOR]", i2ip($ifinfo)); + } } } + my $totalneighbors= scalar(keys %ospfNeighbors); + if ($totalneighbors < $neighbormin) { + push @failures, $router; + push @details, "$router: ALARM: Less than $neighbormin neighbors: only $totalneighbors found"; + } } + if (@failures) { print join(' ', @failures), "\n"; |