3 # check_maxwanstate.pl - nagios plugin
6 # Copyright (C) 2000 Christoph Kron
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 # Report bugs to: ck@zet.net
25 # 11.01.2000 Version 1.0
31 &Getopt
::Long
::config
('auto_abbrev');
37 my %ERRORS = ('UNKNOWN' , '-1',
44 2,'ls-does-not-exist',
48 6,'ls-point-to-point',
59 '1.3.6.1.4.1.529.4.1','Any',
60 '1.3.6.1.4.1.529.4.2','T1',
61 '1.3.6.1.4.1.529.4.3','E1',
62 '1.3.6.1.4.1.529.4.4','Dpnss',
63 '1.3.6.1.4.1.529.4.5','Bri',
64 '1.3.6.1.4.1.529.4.6','S562',
65 '1.3.6.1.4.1.529.4.7','S564',
66 '1.3.6.1.4.1.529.4.8','Sdsl',
67 '1.3.6.1.4.1.529.4.9','AdslCap');
69 my $state = "UNKNOWN";
74 my $community = "public";
77 my $snmpWanLineName = '1.3.6.1.4.1.529.4.21.1.2';
78 my $snmpWanLineType = '1.3.6.1.4.1.529.4.21.1.3';
79 my $snmpWanLineState = '1.3.6.1.4.1.529.4.21.1.5';
80 my $snmpWanLineUsage = '1.3.6.1.4.1.529.4.21.1.8';
93 printf "\nMissing arguments!\n";
95 printf "Perl Check maxwanstate plugin for Nagios\n";
96 printf "monitors E1/T1 interface status\n";
98 printf "check_maxwanstate.pl -c <READCOMMUNITY> -p <PORT> <HOSTNAME>";
99 printf "Copyright (C) 2000 Christoph Kron\n";
100 printf "check_maxwanstate.pl comes with ABSOLUTELY NO WARRANTY\n";
101 printf "This programm is licensed under the terms of the ";
102 printf "GNU General Public License\n(check source code for details)\n";
104 exit $ERRORS{"UNKNOWN"};
107 # Just in case of problems, let's not hang Nagios
109 print ("ERROR: No snmp response from $hostname (alarm)\n");
110 exit $ERRORS{"UNKNOWN"};
115 $status = GetOptions
("community=s",\
$community,
123 $hostname = shift || &usage
;
127 push(@snmpoids,$snmpWanLineUsage);
128 push(@snmpoids,$snmpWanLineState);
129 push(@snmpoids,$snmpWanLineName);
130 push(@snmpoids,$snmpWanLineType);
132 foreach $snmpoid (@snmpoids) {
134 ($session, $error) = Net
::SNMP
->session(
135 -hostname
=> $hostname,
136 -community
=> $community,
140 if (!defined($session)) {
143 print ("$state: $answer");
144 exit $ERRORS{$state};
147 if (!defined($response = $session->get_table($snmpoid))) {
148 $answer=$session->error;
151 print ("$state: $answer,$community,$snmpkey");
152 exit $ERRORS{$state};
155 foreach $snmpkey (keys %{$response}) {
156 $snmpkey =~ /.*\.(\d+)$/;
158 $wanStatus{$key}{$snmpoid} = $response->{$snmpkey};
163 foreach $key (keys %wanStatus) {
164 # look only at active Interfaces lu-trunk(5)
165 if ($wanStatus{$key}{$snmpWanLineUsage} == 5 ) {
168 if ($wanStatus{$key}{$snmpWanLineState} == 13 ) {
173 $ifmessage .= sprintf("%s interface status : %s (%s)<BR>",
174 $wanLineType{$wanStatus{$key}{$snmpWanLineType}},
175 $wanLineState{$wanStatus{$key}{$snmpWanLineState}},
176 $wanStatus{$key}{$snmpWanLineName});
185 $answer = sprintf("host '%s', interfaces up: %d, down: %d<BR>",
189 $answer = $answer . $ifmessage . "\n";
193 $answer = sprintf("host '%s', interfaces up: %d, down: %d\n",
199 print ("$state: $answer");
200 exit $ERRORS{$state};