3 # check_bgpstate.pl - nagios plugin
5 # Copyright (C) 2000 Christoph Kron
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 # Report bugs to: ck@zet.net
24 # 11.01.2000 Version 1.0
32 &Getopt
::Long
::config
('auto_abbrev');
35 # whois programm for RIPE database queries
36 my $whois = '/usr/bin/whois';
40 # critical bgp sessions
41 my %uplinks = ( 1273, 'Uplink ECRC',
46 my %ERRORS = ('UNKNOWN' , '-1',
60 my $state = "UNKNOWN";
65 my $community = "public";
68 my $snmpbgpPeerState = '1.3.6.1.2.1.15.3.1.2';
69 my $snmpbgpPeerLocalAddr = '1.3.6.1.2.1.15.3.1.5';
70 my $snmpbgpPeerRemoteAddr = '1.3.6.1.2.1.15.3.1.7';
71 my $snmpbgpPeerRemoteAs = '1.3.6.1.2.1.15.3.1.9';
77 my $bgpestablished =0 ;
87 printf "\nMissing arguments!\n";
89 printf "Perl bgpstate plugin for Nagios\n";
90 printf "monitors all BGP sessions\n";
92 printf "check_bgpstate.pl -c <READCOMMUNITY> -p <PORT> <HOSTNAME>\n";
93 printf "Copyright (C) 2000 Christoph Kron\n";
94 printf "check_bgpstate.pl comes with ABSOLUTELY NO WARRANTY\n";
95 printf "This programm is licensed under the terms of the ";
96 printf "GNU General Public License\n(check source code for details)\n";
98 exit $ERRORS{"UNKNOWN"};
101 # Just in case of problems, let's not hang Nagios
103 print ("ERROR: No snmp response from $hostname (alarm)\n");
104 exit $ERRORS{"UNKNOWN"};
109 $status = GetOptions
("community=s",\
$community,
117 $hostname = shift || &usage
;
120 push(@snmpoids, $snmpbgpPeerState);
121 push(@snmpoids, $snmpbgpPeerLocalAddr);
122 push(@snmpoids, $snmpbgpPeerRemoteAddr);
123 push(@snmpoids, $snmpbgpPeerRemoteAs);
125 foreach $snmpoid (@snmpoids) {
127 ($session, $error) = Net
::SNMP
->session(
128 -hostname
=> $hostname,
129 -community
=> $community,
133 if (!defined($session)) {
136 print ("$state: $answer");
137 exit $ERRORS{$state};
140 if (!defined($response = $session->get_table($snmpoid))) {
141 $answer=$session->error;
144 print ("$state: $answer,$snmpkey");
145 exit $ERRORS{$state};
148 foreach $snmpkey (keys %{$response}) {
149 $snmpkey =~ m/.*\.(\d+\.\d+\.\d+\.\d+$)/;
151 # printf "debug: $snmpkey: $key -> $response->{$snmpkey}\n";
152 $bgpStatus{$key}{$snmpoid} = $response->{$snmpkey};
157 foreach $key (keys %bgpStatus) {
158 if ($bgpStatus{$key}{$snmpbgpPeerState} == 6 ) {
161 elsif ($bgpStatus{$key}{$snmpbgpPeerState} == 1 ) {
166 if (exists($uplinks{$bgpStatus{$key}{$snmpbgpPeerRemoteAs}}) ) {
169 @output = `$whois -T aut-num AS$bgpStatus{$key}{$snmpbgpPeerRemoteAs}`;
175 $asname =~ s/as-name://;
178 if ( $asname =~ "" && m/descr/ ) {
180 $asname =~ s/descr://;
185 $bgpmessage .= sprintf("Peering with AS%s not established -> %s<BR>",
186 $bgpStatus{$key}{$snmpbgpPeerRemoteAs},
193 if ($bgpcritical > 0) {
199 $answer = sprintf("host '%s', sessions up: %d, down: %d, shutdown: %d<BR>",
203 $answer = $answer . $bgpmessage . "\n";
207 $answer = sprintf("host '%s', sessions up: %d, down: %d, shutdown: %d\n",
213 print ("$state: $answer");
214 exit $ERRORS{$state};