summaryrefslogtreecommitdiffstats
path: root/contrib/check_bgpstate.pl
diff options
context:
space:
mode:
authorEthan Galstad <egalstad@users.sourceforge.net>2002-02-28 06:42:51 (GMT)
committerEthan Galstad <egalstad@users.sourceforge.net>2002-02-28 06:42:51 (GMT)
commit44a321cb8a42d6c0ea2d96a1086a17f2134c89cc (patch)
treea1a4d9f7b92412a17ab08f34f04eec45433048b7 /contrib/check_bgpstate.pl
parent54fd5d7022ff2d6a59bc52b8869182f3fc77a058 (diff)
downloadmonitoring-plugins-44a321cb8a42d6c0ea2d96a1086a17f2134c89cc.tar.gz
Initial revision
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'contrib/check_bgpstate.pl')
-rw-r--r--contrib/check_bgpstate.pl215
1 files changed, 215 insertions, 0 deletions
diff --git a/contrib/check_bgpstate.pl b/contrib/check_bgpstate.pl
new file mode 100644
index 0000000..6658a0b
--- /dev/null
+++ b/contrib/check_bgpstate.pl
@@ -0,0 +1,215 @@
1#!/usr/bin/perl -w
2#
3# check_bgpstate.pl - nagios plugin
4#
5# Copyright (C) 2000 Christoph Kron
6#
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.
11#
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.
16#
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.
20#
21#
22# Report bugs to: ck@zet.net
23#
24# 11.01.2000 Version 1.0
25
26
27
28use strict;
29
30use Net::SNMP;
31use Getopt::Long;
32&Getopt::Long::config('auto_abbrev');
33
34
35# whois programm for RIPE database queries
36my $whois = '/usr/bin/whois';
37my $status;
38my $TIMEOUT = 30;
39
40# critical bgp sessions
41my %uplinks = ( 1273, 'Uplink ECRC',
42 1755, 'Uplink EBONE',
43 3300, 'Uplink AUCS'
44 );
45
46my %ERRORS = ('UNKNOWN' , '-1',
47 'OK' , '0',
48 'WARNING', '1',
49 'CRITICAL', '2');
50
51
52my %bgpPeerState = (
53 '1',"idle",
54 '2',"connect",
55 '3',"active",
56 '4',"opensent",
57 '5',"openconfirm",
58 '6',"established"
59 );
60my $state = "UNKNOWN";
61my $answer = "";
62my $snmpkey;
63my $snmpoid;
64my $key;
65my $community = "public";
66my $port = 161;
67my @snmpoids;
68my $snmpbgpPeerState = '1.3.6.1.2.1.15.3.1.2';
69my $snmpbgpPeerLocalAddr = '1.3.6.1.2.1.15.3.1.5';
70my $snmpbgpPeerRemoteAddr = '1.3.6.1.2.1.15.3.1.7';
71my $snmpbgpPeerRemoteAs = '1.3.6.1.2.1.15.3.1.9';
72my $hostname;
73my $session;
74my $error;
75my $response;
76my %bgpStatus;
77my $bgpestablished =0 ;
78my $bgpcritical =0;
79my $bgpdown =0;
80my $bgpidle =0;
81my $bgpmessage;
82my $asname;
83my $remoteas;
84my @output;
85
86sub usage {
87 printf "\nMissing arguments!\n";
88 printf "\n";
89 printf "Perl bgpstate plugin for Nagios\n";
90 printf "monitors all BGP sessions\n";
91 printf "usage: \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";
97 printf "\n\n";
98 exit $ERRORS{"UNKNOWN"};
99}
100
101# Just in case of problems, let's not hang Nagios
102$SIG{'ALRM'} = sub {
103 print ("ERROR: No snmp response from $hostname (alarm)\n");
104 exit $ERRORS{"UNKNOWN"};
105};
106alarm($TIMEOUT);
107
108
109$status = GetOptions("community=s",\$community,
110 "port=i",\$port);
111if ($status == 0)
112{
113 &usage;
114}
115
116 #shift;
117 $hostname = shift || &usage;
118
119
120push(@snmpoids, $snmpbgpPeerState);
121push(@snmpoids, $snmpbgpPeerLocalAddr);
122push(@snmpoids, $snmpbgpPeerRemoteAddr);
123push(@snmpoids, $snmpbgpPeerRemoteAs);
124
125foreach $snmpoid (@snmpoids) {
126
127 ($session, $error) = Net::SNMP->session(
128 -hostname => $hostname,
129 -community => $community,
130 -port => $port
131 );
132
133 if (!defined($session)) {
134 $state='UNKNOWN';
135 $answer=$error;
136 print ("$state: $answer");
137 exit $ERRORS{$state};
138 }
139
140 if (!defined($response = $session->get_table($snmpoid))) {
141 $answer=$session->error;
142 $session->close;
143 $state = 'CRITICAL';
144 print ("$state: $answer,$community,$snmpkey");
145 exit $ERRORS{$state};
146 }
147
148 foreach $snmpkey (keys %{$response}) {
149 $snmpkey =~ m/.*\.(\d+\.\d+\.\d+\.\d+$)/;
150 $key = $1;
151# printf "debug: $snmpkey: $key -> $response->{$snmpkey}\n";
152 $bgpStatus{$key}{$snmpoid} = $response->{$snmpkey};
153 }
154 $session->close;
155}
156
157foreach $key (keys %bgpStatus) {
158 if ($bgpStatus{$key}{$snmpbgpPeerState} == 6 ) {
159 $bgpestablished++;
160 }
161 elsif ($bgpStatus{$key}{$snmpbgpPeerState} == 1 ) {
162 $bgpidle++;
163 }
164 else {
165 $bgpdown++ ;
166 if (exists($uplinks{$bgpStatus{$key}{$snmpbgpPeerRemoteAs}}) ) {
167 $bgpcritical++;
168 }
169 @output = `$whois -T aut-num AS$bgpStatus{$key}{$snmpbgpPeerRemoteAs}`;
170
171 $asname = "";
172 foreach (@output) {
173 if (m/as-name/) {
174 $asname = $_;
175 $asname =~ s/as-name://;
176 last;
177 }
178 if ( $asname =~ "" && m/descr/ ) {
179 $asname = $_;
180 $asname =~ s/descr://;
181 }
182 }
183 $asname =~ s/^\s*//;
184 $asname =~ s/\s*$//;
185 $bgpmessage .= sprintf("Peering with AS%s not established -> %s<BR>",
186 $bgpStatus{$key}{$snmpbgpPeerRemoteAs},
187 $asname);
188 }
189}
190
191
192 if ($bgpdown > 0) {
193 if ($bgpcritical > 0) {
194 $state = 'CRITICAL';
195 }
196 else {
197 $state = 'WARNING';
198 }
199 $answer = sprintf("host '%s', sessions up: %d, down: %d, shutdown: %d<BR>",
200 $hostname,
201 $bgpestablished,
202 $bgpdown, $bgpidle);
203 $answer = $answer . $bgpmessage . "\n";
204 }
205 else {
206 $state = 'OK';
207 $answer = sprintf("host '%s', sessions up: %d, down: %d, shutdown: %d\n",
208 $hostname,
209 $bgpestablished,
210 $bgpdown,$bgpidle);
211 }
212
213print ("$state: $answer");
214exit $ERRORS{$state};
215