summaryrefslogtreecommitdiffstats
path: root/contrib/check_maxchannels.pl
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/check_maxchannels.pl')
-rw-r--r--contrib/check_maxchannels.pl231
1 files changed, 231 insertions, 0 deletions
diff --git a/contrib/check_maxchannels.pl b/contrib/check_maxchannels.pl
new file mode 100644
index 0000000..a3ce525
--- /dev/null
+++ b/contrib/check_maxchannels.pl
@@ -0,0 +1,231 @@
1#!/usr/bin/perl -w
2#
3# check_maxchannels.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 = 15;
36
37my %ERRORS = ('UNKNOWN' , '-1',
38 'OK' , '0',
39 'WARNING', '1',
40 'CRITICAL', '2');
41
42
43my $state = "UNKNOWN";
44my $answer = "";
45my $snmpkey;
46my $snmpoid;
47my $key;
48my $community = "public";
49my $port = 161;
50my @snmpoids;
51# free channels
52my $snmpWanAvailableChannels = '1.3.6.1.4.1.529.4.23.0';
53# maximum channels
54my $snmpWanSwitchedChannels = '1.3.6.1.4.1.529.4.24.0';
55my $snmpWanDisabledChannels = '1.3.6.1.4.1.529.4.25.0';
56my $snmpWanActiveChannels = '1.3.6.1.4.1.529.4.26.0';
57my $snmpWanNailedChannels = '1.3.6.1.4.1.529.4.27.0';
58my $snmpWanOutOfServiceChannels = '1.3.6.1.4.1.529.4.28.0';
59my $snmpEventCurrentActiveSessions = '1.3.6.1.4.1.529.10.6.0';
60# since startup
61my $snmpEventTotalNoModems = '1.3.6.1.4.1.529.10.15.0';
62# lan modem
63my $snmpDeadLanModem = '1.3.6.1.4.1.529.15.7.0';
64my $snmpDisabledLanModem = '1.3.6.1.4.1.529.15.5.0';
65my $snmpSuspectLanModem = '1.3.6.1.4.1.529.15.3.0';
66my $snmpAvailLanModem = '1.3.6.1.4.1.529.15.1.0';
67my $snmpBusyLanModem = '1.3.6.1.4.1.529.15.9.0';
68# max modems
69my $snmpMdmNumber = '1.3.6.1.2.1.38.1.1.0';
70my $hostname;
71my $session;
72my $error;
73my $response;
74my %wanStatus;
75
76
77my $WanAvailableChannels;
78my $WanSwitchedChannels;
79my $WanDisabledChannels;
80my $WanActiveChannels;
81my $WanNailedChannels;
82my $WanOutOfServiceChannels;
83my $EventCurrentActiveSessions;
84my $EventTotalNoModems;
85my $DeadLanModem;
86my $DisabledLanModem;
87my $SuspectLanModem;
88my $AvailLanModem;
89my $BusyLanModem;
90my $MdmNumber;
91
92
93sub usage {
94 printf "\nMissing arguments!\n";
95 printf "\n";
96 printf "Perl Check maxchannels plugin for Nagios\n";
97 printf "monitors ISDN lines and modems on Ascend MAX 2000/4000/6000/TNT\n";
98 printf "usage: \n";
99 printf "check_maxchannel.pl -c <READCOMMUNITY> -p <PORT> <HOSTNAME>\n";
100 printf "Copyright (C) 2000 Christoph Kron\n";
101 printf "check_maxchannels.pl comes with ABSOLUTELY NO WARRANTY\n";
102 printf "This programm is licensed under the terms of the ";
103 printf "GNU General Public License\n(check source code for details)\n";
104 printf "\n\n";
105 exit $ERRORS{"UNKNOWN"};
106}
107
108# Just in case of problems, let's not hang Nagios
109$SIG{'ALRM'} = sub {
110 print ("ERROR: No snmp response from $hostname (alarm)\n");
111 exit $ERRORS{"UNKNOWN"};
112};
113alarm($TIMEOUT);
114
115
116$status = GetOptions("community=s",\$community,
117 "port=i",\$port);
118if ($status == 0)
119{
120 &usage;
121}
122
123 #shift;
124 $hostname = shift || &usage;
125
126
127
128push(@snmpoids,$snmpWanAvailableChannels);
129push(@snmpoids,$snmpWanSwitchedChannels);
130push(@snmpoids,$snmpWanDisabledChannels);
131push(@snmpoids,$snmpWanActiveChannels);
132push(@snmpoids,$snmpWanNailedChannels);
133push(@snmpoids,$snmpWanOutOfServiceChannels);
134
135push(@snmpoids,$snmpEventCurrentActiveSessions);
136
137push(@snmpoids,$snmpEventTotalNoModems);
138push(@snmpoids,$snmpDeadLanModem);
139push(@snmpoids,$snmpDisabledLanModem);
140push(@snmpoids,$snmpSuspectLanModem);
141push(@snmpoids,$snmpAvailLanModem);
142push(@snmpoids,$snmpBusyLanModem);
143push(@snmpoids,$snmpMdmNumber);
144
145 ($session, $error) = Net::SNMP->session(
146 -hostname => $hostname,
147 -community => $community,
148 -port => $port
149 );
150
151 if (!defined($session)) {
152 $state='UNKNOWN';
153 $answer=$error;
154 print ("$state: $answer");
155 exit $ERRORS{$state};
156 }
157
158 if (!defined($response = $session->get_request(@snmpoids))) {
159 $answer=$session->error;
160 $session->close;
161 $state = 'CRITICAL';
162 print ("$state: $answer,$community");
163 exit $ERRORS{$state};
164 }
165
166
167$WanAvailableChannels = $response->{$snmpWanAvailableChannels};
168$WanSwitchedChannels = $response->{$snmpWanSwitchedChannels};
169$WanDisabledChannels = $response->{$snmpWanDisabledChannels};
170$WanActiveChannels = $response->{$snmpWanActiveChannels};
171$WanNailedChannels = $response->{$snmpWanNailedChannels};
172$WanOutOfServiceChannels = $response->{$snmpWanOutOfServiceChannels};
173$EventCurrentActiveSessions = $response->{$snmpEventCurrentActiveSessions};
174$EventTotalNoModems = $response->{$snmpEventTotalNoModems};
175$DeadLanModem = $response->{$snmpDeadLanModem};
176$DisabledLanModem = $response->{$snmpDisabledLanModem};
177$SuspectLanModem = $response->{$snmpSuspectLanModem};
178$AvailLanModem = $response->{$snmpAvailLanModem};
179$BusyLanModem = $response->{$snmpBusyLanModem};
180$MdmNumber = $response->{$snmpMdmNumber};
181
182# less than 50% -> WARNING
183if ( 0 < $WanOutOfServiceChannels
184 && $WanOutOfServiceChannels < ($snmpWanSwitchedChannels * 0.5) ) {
185 $state = 'WARNING';
186}
187elsif ($WanOutOfServiceChannels > 0) {
188 $state = 'CRITICAL';
189}
190elsif ($DeadLanModem > 0) {
191 $state = 'CRITICAL';
192}
193elsif ($SuspectLanModem > 0) {
194 $state = 'WARNING';
195}
196elsif ($AvailLanModem == 0) {
197 $state = 'WARNING';
198}
199else {
200 $state = 'OK';
201}
202
203
204$answer = sprintf("active sessions: %d (%d), active modems: %d (%d)<BR>",
205 $EventCurrentActiveSessions,
206 $WanSwitchedChannels,
207 $BusyLanModem,
208 $MdmNumber);
209
210$answer .= sprintf("channels available: %d, disabled: %d",
211 $WanAvailableChannels,
212 $WanDisabledChannels);
213
214$answer .= sprintf(", out of service: %d, nailed: %d<BR>",
215 $WanOutOfServiceChannels,
216 $WanNailedChannels);
217
218$answer .= sprintf("modems avail.: %d, disabled: %d, suspect: %d, dead: %d<BR>",
219 $AvailLanModem,
220 $DisabledLanModem,
221 $SuspectLanModem,
222 $DeadLanModem);
223
224$answer .= sprintf("unserviced modem calls: %d (since startup)\n",
225 $EventTotalNoModems);
226
227$session->close;
228
229print ("$state: $answer");
230exit $ERRORS{$state};
231