[Mon-commit] mon-contrib/monitors/bgp/bgp bgp.monitor,1.1.1.1,1.2 bgp.monitor.README,1.1.1.1,1.2
Brought to you by:
trockij
From: Ed R. <er...@us...> - 2005-04-07 20:18:42
|
Update of /cvsroot/mon/mon-contrib/monitors/bgp/bgp In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2691/mon-contrib/monitors/bgp/bgp Modified Files: bgp.monitor bgp.monitor.README Log Message: Better community and error handling Index: bgp.monitor =================================================================== RCS file: /cvsroot/mon/mon-contrib/monitors/bgp/bgp/bgp.monitor,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** bgp.monitor 18 Feb 2005 17:52:23 -0000 1.1.1.1 --- bgp.monitor 7 Apr 2005 20:18:29 -0000 1.2 *************** *** 4,8 **** # look at each router and get the status of all is BGP neigbor # ! # Version 1.00 (5 april 2002) # # Copyright 2002, Marc Hauswirth, Safe Host SA <ma...@sa...> --- 4,8 ---- # look at each router and get the status of all is BGP neigbor # ! # Version 1.1 (7 april 2005) # # Copyright 2002, Marc Hauswirth, Safe Host SA <ma...@sa...> *************** *** 22,39 **** # It is also part of MRTG (http://people.ee.ethz.ch/~oetiker/webtools/mrtg/) use SNMP; use SNMP_Session; use strict; ! ## -- ! # The only things that should be changed : ! my $community = "public"; ## -- ! my @summary; ! my @warnings; ! my $details; ! my $summary; # OID's to the SNMP elements that I want to show... --- 22,44 ---- # It is also part of MRTG (http://people.ee.ethz.ch/~oetiker/webtools/mrtg/) + # updated 7 April 2005 by Ed Ravin, <er...@pa...> + # use normal Mon summary / detail reporting + # accept SNMP community via environment var COMMUNITY + # detect SNMP errors + use SNMP; use SNMP_Session; use strict; ! ## -- should be a command-line option, but this is sufficient (and safer, ! ## since the community won't be displayed in the Mon interface to users) ! my $community = $ENV{'COMMUNITY'} || "public"; ## -- ! my @failures; ! my @details; ! ! $ENV{'MIBS'}= ""; # all OIDs needed are specified in script # OID's to the SNMP elements that I want to show... *************** *** 110,113 **** --- 115,123 ---- ); + my %BgpAdminStatus = ( + 1 => "stop", + 2 => "start", + ); + my %state; *************** *** 116,126 **** # Get some infos about this router my $sess = new SNMP::Session ( DestHost => $router, Community => $community ); my $bgpLocalAs = $sess->get("\." . $oids{bgpLocalAs}); my $bgpIdentifier = $sess->get("\." . $oids{bgpIdentifier} . ".0"); ! $details .= "Router: $router (AS $bgpLocalAs) Id : $bgpIdentifier\n"; ! # Get trougnt the SNMP tree to fetch all peer infos ! my $vars = new SNMP::VarList([$oids{bgpPeerIdentifier}],[$oids{bgpPeerRemoteAs}],[$oids{bgpPeerState}],[$oids{bgpPeerFsmEstablishedTime}]); for (my @vals = $sess->getnext($vars); $vars->[0]->tag =~ /15\.3\.1\.1/ # still in table (Did you have a cleaner solutions ?) --- 126,155 ---- # Get some infos about this router my $sess = new SNMP::Session ( DestHost => $router, Community => $community ); + if (!defined($sess)) + { + push @failures, $router; + push @details, "$router: cannot create SNMP session"; + next; + } my $bgpLocalAs = $sess->get("\." . $oids{bgpLocalAs}); + if ($sess->{ErrorNum}) + { + push @failures, $router; + push @details, "$router: error on initial SNMP get: $sess->{ErrorStr}"; + next; + } + my $bgpIdentifier = $sess->get("\." . $oids{bgpIdentifier} . ".0"); + if ($sess->{ErrorNum}) + { + push @failures, $router; + push @details, "$router: error on subsequent SNMP get: $sess->{ErrorStr}"; + next; + } ! push @details, "$router (AS $bgpLocalAs) Id : $bgpIdentifier"; ! # Get through the SNMP tree to fetch all peer infos ! my $vars = new SNMP::VarList([$oids{bgpPeerIdentifier}],[$oids{bgpPeerRemoteAs}],[$oids{bgpPeerState}],[$oids{bgpPeerFsmEstablishedTime}],[$oids{bgpPeerAdminStatus}], [$oids{bgpPeerRemoteAddr}]); for (my @vals = $sess->getnext($vars); $vars->[0]->tag =~ /15\.3\.1\.1/ # still in table (Did you have a cleaner solutions ?) *************** *** 131,157 **** my $textState = $BgpPeerState{$vals[2]}; my $texttime = sectotime($vals[3]); ! $details .= sprintf(" Neighbor %-16s AS %-5u status : %-15s since : %-16s\n",$vals[0], $vals[1], $textState, $texttime); ! if ($vals[2] != 6) { ! $summary .= "Neighbor relation : $router - $vals[0] (AS $vals[1]) is in state $textState"; }; } - $details .= "\n"; } ! if ($summary) { ! print $summary . "\n"; ! print "--------------------------------------------------------------\n"; ! print "Summary : \n"; ! print " " . $summary . "\n"; ! } else { ! print "\n"; }; ! print "--------------------------------------------------------------\n"; ! print "Details \n"; ! print "--------------------------------------------------------------\n"; ! print $details ; ! if ($summary) { # Error state exit exit 1; --- 160,182 ---- my $textState = $BgpPeerState{$vals[2]}; my $texttime = sectotime($vals[3]); ! push @details, sprintf("$router: Neighbor %-16s AS %-5u status : %-15s since : %-16s",$vals[5], $vals[1], $textState, $texttime); ! # if bgpPeerState != established and bgpPeerAdminStatus == start ! if ($vals[2] != 6 and $vals[4] == 2) { ! push @failures, $router; ! push @details, "$router: Neighbor relation: $vals[5] (AS $vals[1]) is in state $textState "; }; } } ! if (@failures) { ! print join(' ', @failures), "\n"; }; ! if (@details) { ! print "\n"; ! print join("\n", @details), "\n"; ! } ! if (@failures) { # Error state exit exit 1; *************** *** 179,181 **** $texttime .= int($sec/60) . "min"; return ($texttime); ! }; \ No newline at end of file --- 204,206 ---- $texttime .= int($sec/60) . "min"; return ($texttime); ! }; Index: bgp.monitor.README =================================================================== RCS file: /cvsroot/mon/mon-contrib/monitors/bgp/bgp/bgp.monitor.README,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** bgp.monitor.README 18 Feb 2005 17:52:23 -0000 1.1.1.1 --- bgp.monitor.README 7 Apr 2005 20:18:30 -0000 1.2 *************** *** 21,34 **** # # EXAMPLES ! # ./bgp.monitor routerIP or name # # OUTPUT ! # I like to have some details, if the result is OK or not. So this ! # script send a list of all peer sessions and is status. # # OPTIONS ! # The SNMP community is hard coded in the script, to avoid that a mon user see ! # this sensible data. ! # you just have to change the variable $community. # # COPYRIGHT --- 21,36 ---- # # EXAMPLES ! # ./bgp.monitor routerIP_or_name [...] # # OUTPUT ! # Displays a list of all peer sessions and status. Exit status will be ! # non-zero if a router cannot be contacted or if a BGP session that should ! # be established isn't. # # OPTIONS ! # To use an SNMP community other than "public", set the COMMUNITY environment ! # variable in mon.cf in the stanza that invokes bgp.monitor. The same ! # community name will be tried for all the routers specified on the command ! # line. # # COPYRIGHT *************** *** 45,47 **** # Fell free to send me your comments to ma...@sa... # ! # Version 1.00 -- 5 april 2002 \ No newline at end of file --- 47,50 ---- # Fell free to send me your comments to ma...@sa... # ! # Version 1.00 -- 5 april 2002 ! # Version 1.1 -- 7 april 2005 |