3 # check_dlswcircuit.pl - nagios plugin
5 # Checks if a Cisco Dlsw circuit is connected.
8 # Copyright (C) 2000 Carsten Foss & Christoph Kron
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.
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.
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.
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.
27 # Arguments : -s <SourceMac> -d <DestMac> -c <READCOMMUNITY> -p <PORT> <HOSTNAME or IP-Addr>
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)
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
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$
38 # Report bugs to: cfo@dmdata.dk
40 # 11.03.2000 Version 1.0
46 &Getopt
::Long
::config
('auto_abbrev');
52 my %ERRORS = ('UNKNOWN' , '-1',
57 my %dlswCircuitStatus = (
62 '5','circuitEstablished',
66 '9','disconnectPending',
68 '11','haltPendingNoack',
69 '13','circuitRestart',
70 '14','restartPending');
72 my $state = "UNKNOWN";
76 my $community = "public";
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
79 my $enterpriseOid = "1.3.6.1.4.1";
80 my $ciscoDlswCircuitOid = ".9.10.9.1.5.2.1.17.";
81 my $unknownOid = "6.";
96 printf "\nMissing arguments!\n";
98 printf "Perl Check Cisco Dlsw Circuit State plugin for Nagios\n";
99 printf "checks operational status of specified DLSW Circuit\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";
107 exit $ERRORS{"UNKNOWN"};
110 # Just in case of problems, let's not hang Nagios
112 print ("ERROR: No snmp response from $hostname (alarm)\n");
113 exit $ERRORS{"UNKNOWN"};
118 $status = GetOptions
("sourcemac=s",\
$smac,"destmac=s",\
$dmac,
119 "community=s",\
$community,
127 #Convert Source Mac & Sap
129 @tmparg = split(/\./,$smac);
135 print "SourceMac/Sap format $smac not valid\n";
138 while($p = shift @tmparg)
141 $smacOid = $smacOid.$q;
142 $smacOid = $smacOid.'.';
149 #Convert Dest Mac & Sap
151 @tmparg = split(/\./,$dmac);
157 print "DestMac/Sap format $dmac not valid\n";
161 while($p = shift @tmparg)
164 $dmacOid = $dmacOid.$q;
165 $dmacOid = $dmacOid.'.';
167 # Remove Trailing Dot
168 $dmacOid = substr($dmacOid,0,length($dmacOid)-1);
173 #Build the Dlsw Oic to use
174 $snmpoid = $enterpriseOid.$ciscoDlswCircuitOid.$unknownOid.$smacOid.$unknownOid.$dmacOid ;
178 $hostname = shift || &usage
;
180 ($session, $error) = Net
::SNMP
->session(
181 -hostname
=> $hostname,
182 -community
=> $community,
186 if (!defined($session)) {
189 print ("$state: $answer");
190 exit $ERRORS{$state};
193 push(@snmpoids,$snmpoid);
194 #push(@snmpoids,$snmpLocIfDescr);
196 if (!defined($response = $session->get_request(@snmpoids))) {
197 $answer=$session->error;
200 print ("$state: $answer,$community,$smac - $dmac");
201 exit $ERRORS{$state};
204 $answer = sprintf("dlsw circuit %s - %s at host '%s',is %s\n",
208 $dlswCircuitStatus{$response->{$snmpoid}}
213 if ( $response->{$snmpoid} == 8 ) {
220 print ("$state: $answer");
221 exit $ERRORS{$state};