summaryrefslogtreecommitdiffstats
path: root/contrib/check_maxwanstate.pl
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/check_maxwanstate.pl')
-rw-r--r--contrib/check_maxwanstate.pl201
1 files changed, 0 insertions, 201 deletions
diff --git a/contrib/check_maxwanstate.pl b/contrib/check_maxwanstate.pl
deleted file mode 100644
index 4fbb9da2..00000000
--- a/contrib/check_maxwanstate.pl
+++ /dev/null
@@ -1,201 +0,0 @@
1#!/usr/bin/perl -w
2#
3# check_maxwanstate.pl - nagios plugin
4#
5#
6# Copyright (C) 2000 Christoph Kron
7#
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.
12#
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.
17#
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.
21#
22#
23# Report bugs to: ck@zet.net
24#
25# 11.01.2000 Version 1.0
26
27use strict;
28
29use Net::SNMP;
30use Getopt::Long;
31&Getopt::Long::config('auto_abbrev');
32
33
34my $status;
35my $TIMEOUT = 1500;
36
37my %ERRORS = ('UNKNOWN' , '-1',
38 'OK' , '0',
39 'WARNING', '1',
40 'CRITICAL', '2');
41
42my %wanLineState = (
43 1,'ls-unknown',
44 2,'ls-does-not-exist',
45 3,'ls-disabled',
46 4,'ls-no-physical',
47 5,'ls-no-logical',
48 6,'ls-point-to-point',
49 7,'ls-multipoint-1',
50 8,'ls-multipoint-2',
51 9,'ls-loss-of-sync',
52 10,'ls-yellow-alarm',
53 11,'ls-ais-receive',
54 12,'ls-no-d-channel',
55 13,'ls-active',
56 14,'ls-maintenance');
57
58my %wanLineType = (
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');
68
69my $state = "UNKNOWN";
70my $answer = "";
71my $snmpkey;
72my $snmpoid;
73my $key;
74my $community = "public";
75my $port = 161;
76my @snmpoids;
77my $snmpWanLineName = '1.3.6.1.4.1.529.4.21.1.2';
78my $snmpWanLineType = '1.3.6.1.4.1.529.4.21.1.3';
79my $snmpWanLineState = '1.3.6.1.4.1.529.4.21.1.5';
80my $snmpWanLineUsage = '1.3.6.1.4.1.529.4.21.1.8';
81
82my $hostname;
83my $session;
84my $error;
85my $response;
86my %wanStatus;
87my $ifup =0 ;
88my $ifdown =0;
89my $ifdormant = 0;
90my $ifmessage;
91
92sub usage {
93 printf "\nMissing arguments!\n";
94 printf "\n";
95 printf "Perl Check maxwanstate plugin for Nagios\n";
96 printf "monitors E1/T1 interface status\n";
97 printf "usage: \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";
103 printf "\n\n";
104 exit $ERRORS{"UNKNOWN"};
105}
106
107# Just in case of problems, let's not hang Nagios
108$SIG{'ALRM'} = sub {
109 print ("ERROR: No snmp response from $hostname (alarm)\n");
110 exit $ERRORS{"UNKNOWN"};
111};
112alarm($TIMEOUT);
113
114
115$status = GetOptions("community=s",\$community,
116 "port=i",\$port);
117if ($status == 0)
118{
119 &usage;
120}
121
122 #shift;
123 $hostname = shift || &usage;
124
125
126
127push(@snmpoids,$snmpWanLineUsage);
128push(@snmpoids,$snmpWanLineState);
129push(@snmpoids,$snmpWanLineName);
130push(@snmpoids,$snmpWanLineType);
131
132foreach $snmpoid (@snmpoids) {
133
134 ($session, $error) = Net::SNMP->session(
135 -hostname => $hostname,
136 -community => $community,
137 -port => $port
138 );
139
140 if (!defined($session)) {
141 $state='UNKNOWN';
142 $answer=$error;
143 print ("$state: $answer");
144 exit $ERRORS{$state};
145 }
146
147 if (!defined($response = $session->get_table($snmpoid))) {
148 $answer=$session->error;
149 $session->close;
150 $state = 'CRITICAL';
151 print ("$state: $answer,$community,$snmpkey");
152 exit $ERRORS{$state};
153 }
154
155 foreach $snmpkey (keys %{$response}) {
156 $snmpkey =~ /.*\.(\d+)$/;
157 $key = $1;
158 $wanStatus{$key}{$snmpoid} = $response->{$snmpkey};
159 }
160 $session->close;
161}
162
163 foreach $key (keys %wanStatus) {
164 # look only at active Interfaces lu-trunk(5)
165 if ($wanStatus{$key}{$snmpWanLineUsage} == 5 ) {
166
167 # 13 -> active
168 if ($wanStatus{$key}{$snmpWanLineState} == 13 ) {
169 $ifup++;
170 }
171 else {
172 $ifdown++ ;
173 $ifmessage .= sprintf("%s interface status : %s (%s)<BR>",
174 $wanLineType{$wanStatus{$key}{$snmpWanLineType}},
175 $wanLineState{$wanStatus{$key}{$snmpWanLineState}},
176 $wanStatus{$key}{$snmpWanLineName});
177
178 }
179 }
180 }
181
182
183 if ($ifdown > 0) {
184 $state = 'CRITICAL';
185 $answer = sprintf("host '%s', interfaces up: %d, down: %d<BR>",
186 $hostname,
187 $ifup,
188 $ifdown);
189 $answer = $answer . $ifmessage . "\n";
190 }
191 else {
192 $state = 'OK';
193 $answer = sprintf("host '%s', interfaces up: %d, down: %d\n",
194 $hostname,
195 $ifup,
196 $ifdown);
197 }
198
199print ("$state: $answer");
200exit $ERRORS{$state};
201