summaryrefslogtreecommitdiffstats
path: root/contrib/check_dlswcircuit.pl
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/check_dlswcircuit.pl')
-rwxr-xr-xcontrib/check_dlswcircuit.pl221
1 files changed, 221 insertions, 0 deletions
diff --git a/contrib/check_dlswcircuit.pl b/contrib/check_dlswcircuit.pl
new file mode 100755
index 0000000..f6ef931
--- /dev/null
+++ b/contrib/check_dlswcircuit.pl
@@ -0,0 +1,221 @@
1#!/usr/bin/perl -w
2#
3# check_dlswcircuit.pl - nagios plugin
4#
5# Checks if a Cisco Dlsw circuit is connected.
6#
7#
8# Copyright (C) 2000 Carsten Foss & Christoph Kron
9#
10# Basically this is an adapted version of Christoph Kron's (ck@zet.net) check_ifoperstatus.pl plugin.
11# most of the thanks should go to him.
12#
13# This program is free software; you can redistribute it and/or
14# modify it under the terms of the GNU General Public License
15# as published by the Free Software Foundation; either version 2
16# of the License, or (at your option) any later version.
17#
18# This program is distributed in the hope that it will be useful,
19# but WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21# GNU General Public License for more details.
22#
23# You should have received a copy of the GNU General Public License
24# along with this program; if not, write to the Free Software
25# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26#
27# Arguments : -s <SourceMac> -d <DestMac> -c <READCOMMUNITY> -p <PORT> <HOSTNAME or IP-Addr>
28# -
29# Source & Dest Mac/Sap arguments must be given in Hex as this example : 40.00.01.37.45.01.ss (Where ss is the sap)
30#
31# Sample command line : check_dlswcircuit.pl -s 40.00.01.37.45.01.04 -d 40.00.02.37.45.02.04 -c secret 1.2.3.4
32#
33# Sample host.cfg entry :
34#service[Dlsw-xx]=NCP1-NCP2;0;24x7;3;5;1;router-admins;240;24x7;1;1;0;;check_dlswcircuit!-s 40.00.01.37.45.01.04!-d 40.00..01.37.45.02.04!-c secret!1.2.3.4
35# remember to add the service to commands.cfg , something like this:
36# command[check_dlswcircuit]=$USER1$/check_dlswcircuit.pl $ARG1$ $ARG2$ $ARG3$ $ARG4$ $ARG5$
37#
38# Report bugs to: cfo@dmdata.dk
39#
40# 11.03.2000 Version 1.0
41
42use strict;
43
44use Net::SNMP;
45use Getopt::Long;
46&Getopt::Long::config('auto_abbrev');
47
48
49my $status;
50my $TIMEOUT = 15;
51
52my %ERRORS = ('UNKNOWN' , '-1',
53 'OK' , '0',
54 'WARNING', '1',
55 'CRITICAL', '2');
56
57my %dlswCircuitStatus = (
58 '1','disconnected',
59 '2','circuitStart',
60 '3','resolvePending',
61 '4','circuitPending',
62 '5','circuitEstablished',
63 '6','connectPending',
64 '7','contactPending',
65 '8','connected',
66 '9','disconnectPending',
67 '10','haltPending',
68 '11','haltPendingNoack',
69 '13','circuitRestart',
70 '14','restartPending');
71
72my $state = "UNKNOWN";
73my $answer = "";
74my $smac = "";
75my $dmac = "";
76my $community = "public";
77my $port = 161;
78#Dlsw Circuit Oid enterprises.9.10.9.1.5.2.1.17.6.0.96.148.47.230.166.4.6.64.0.1.55.69.2.4 = 8
79my $enterpriseOid = "1.3.6.1.4.1";
80my $ciscoDlswCircuitOid = ".9.10.9.1.5.2.1.17.";
81my $unknownOid = "6.";
82my $smacOid = "";
83my $dmacOid = "";
84my $tmpOid = "";
85my @tmparg;
86my $snmpoid;
87my @snmpoids;
88my $hostname;
89my $session;
90my $error;
91my $response;
92my $p = "";
93my $q = "";
94
95sub usage {
96 printf "\nMissing arguments!\n";
97 printf "\n";
98 printf "Perl Check Cisco Dlsw Circuit State plugin for Nagios\n";
99 printf "checks operational status of specified DLSW Circuit\n";
100 printf "usage: \n";
101 printf "check_dlswcircuit.pl -s <SourceMac> -d <DestMac> -c <READCOMMUNITY> -p <PORT> <HOSTNAME>";
102 printf "\nCopyright (C) 2000 Carsten Foss\n";
103 printf "check_dlswcircuit.pl comes with ABSOLUTELY NO WARRANTY\n";
104 printf "This programm is licensed under the terms of the ";
105 printf "GNU General Public License\n(check source code for details)\n";
106 printf "\n\n";
107 exit $ERRORS{"UNKNOWN"};
108}
109
110# Just in case of problems, let's not hang Nagios
111$SIG{'ALRM'} = sub {
112 print ("ERROR: No snmp response from $hostname (alarm)\n");
113 exit $ERRORS{"UNKNOWN"};
114};
115alarm($TIMEOUT);
116
117
118$status = GetOptions("sourcemac=s",\$smac,"destmac=s",\$dmac,
119 "community=s",\$community,
120 "port=i",\$port);
121if ($status == 0)
122{
123 &usage;
124}
125
126#
127#Convert Source Mac & Sap
128#
129 @tmparg = split(/\./,$smac);
130 #print "-$smac-\n";
131 #print "@tmparg\n";
132 #print "$#tmparg\n";
133 if($#tmparg != 6)
134 {
135 print "SourceMac/Sap format $smac not valid\n";
136 &usage;
137 }
138 while($p = shift @tmparg)
139 {
140 $q = hex($p);
141 $smacOid = $smacOid.$q;
142 $smacOid = $smacOid.'.';
143 }
144
145 #print "@tmparg1\n";
146 #print "$smacOid\n";
147
148#
149#Convert Dest Mac & Sap
150#
151 @tmparg = split(/\./,$dmac);
152 #print "-$dmac-\n";
153 #print "@tmparg\n";
154 #print "$#tmparg\n";
155 if($#tmparg != 6)
156 {
157 print "DestMac/Sap format $dmac not valid\n";
158 &usage;
159 }
160
161 while($p = shift @tmparg)
162 {
163 $q = hex($p);
164 $dmacOid = $dmacOid.$q;
165 $dmacOid = $dmacOid.'.';
166 }
167# Remove Trailing Dot
168 $dmacOid = substr($dmacOid,0,length($dmacOid)-1);
169
170
171 #print "@tmparg1\n";
172 #print "$dmacOid\n";
173#Build the Dlsw Oic to use
174 $snmpoid = $enterpriseOid.$ciscoDlswCircuitOid.$unknownOid.$smacOid.$unknownOid.$dmacOid ;
175 #print "$snmpoid\n";
176
177 #shift;
178 $hostname = shift || &usage;
179
180 ($session, $error) = Net::SNMP->session(
181 -hostname => $hostname,
182 -community => $community,
183 -port => $port
184 );
185
186 if (!defined($session)) {
187 $state='UNKNOWN';
188 $answer=$error;
189 print ("$state: $answer");
190 exit $ERRORS{$state};
191 }
192
193 push(@snmpoids,$snmpoid);
194 #push(@snmpoids,$snmpLocIfDescr);
195
196 if (!defined($response = $session->get_request(@snmpoids))) {
197 $answer=$session->error;
198 $session->close;
199 $state = 'CRITICAL';
200 print ("$state: $answer,$community,$smac - $dmac");
201 exit $ERRORS{$state};
202 }
203
204 $answer = sprintf("dlsw circuit %s - %s at host '%s',is %s\n",
205 $smac,
206 $dmac,
207 $hostname,
208 $dlswCircuitStatus{$response->{$snmpoid}}
209 );
210
211 $session->close;
212
213 if ( $response->{$snmpoid} == 8 ) {
214 $state = 'OK';
215 }
216 else {
217 $state = 'CRITICAL';
218 }
219
220print ("$state: $answer");
221exit $ERRORS{$state};