summaryrefslogtreecommitdiffstats
path: root/plugins-scripts
diff options
context:
space:
mode:
authorSubhendu Ghosh <sghosh@users.sourceforge.net>2002-05-09 19:03:51 (GMT)
committerSubhendu Ghosh <sghosh@users.sourceforge.net>2002-05-09 19:03:51 (GMT)
commitde814d1a37f23c8eb341a22bb2870c0979a6ca08 (patch)
tree66f217df5a7bf7c7f7ffd0619466c554de67d3fa /plugins-scripts
parent94a0d099c2e2b1e27fbcae5f2d18f5c4297da03b (diff)
downloadmonitoring-plugins-de814d1a37f23c8eb341a22bb2870c0979a6ca08.tar.gz
migrated check_ifoperstatus to standard plugin
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@28 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins-scripts')
-rw-r--r--plugins-scripts/Makefile.am4
-rw-r--r--plugins-scripts/check_ifoperstatus.pl255
2 files changed, 257 insertions, 2 deletions
diff --git a/plugins-scripts/Makefile.am b/plugins-scripts/Makefile.am
index e753a8b..1ca1549 100644
--- a/plugins-scripts/Makefile.am
+++ b/plugins-scripts/Makefile.am
@@ -6,11 +6,11 @@ VPATH=$(top_srcdir) $(top_srcdir)/plugins-scripts $(top_srcdir)/plugins-scripts/
6 6
7libexec_SCRIPTS = check_breeze check_disk_smb check_flexlm check_ircd \ 7libexec_SCRIPTS = check_breeze check_disk_smb check_flexlm check_ircd \
8 check_log check_ntp check_oracle check_rpc check_sensors check_wave \ 8 check_log check_ntp check_oracle check_rpc check_sensors check_wave \
9 check_ifstatus utils.sh utils.pm 9 check_ifstatus check_ifoperstatus utils.sh utils.pm
10 10
11EXTRA_DIST=check_breeze.pl check_disk_smb.pl check_flexlm.pl check_ircd.pl \ 11EXTRA_DIST=check_breeze.pl check_disk_smb.pl check_flexlm.pl check_ircd.pl \
12 check_log.sh check_ntp.pl check_oracle.sh check_rpc.pl check_sensors.sh \ 12 check_log.sh check_ntp.pl check_oracle.sh check_rpc.pl check_sensors.sh \
13 check_ifstatus.pl check_wave.pl utils.sh.in utils.pm.in t 13 check_ifstatus.pl check_ifoperstatus.pl check_wave.pl utils.sh.in utils.pm.in t
14 14
15TESTS_ENVIRONMENT=perl -I $(top_builddir) -I $(top_srcdir) 15TESTS_ENVIRONMENT=perl -I $(top_builddir) -I $(top_srcdir)
16 16
diff --git a/plugins-scripts/check_ifoperstatus.pl b/plugins-scripts/check_ifoperstatus.pl
new file mode 100644
index 0000000..4696467
--- /dev/null
+++ b/plugins-scripts/check_ifoperstatus.pl
@@ -0,0 +1,255 @@
1#!/usr/local/bin/perl -w
2#
3# check_ifoperstatus.pl - nagios plugin
4#
5# Copyright (C) 2000 Christoph Kron
6# Modified 5/2002 to conform to updated Nagios Plugin Guidelines
7# Added support for named interfaces per Valdimir Ivaschenko (S. Ghosh)
8#
9# This program is free software; you can redistribute it and/or
10# modify it under the terms of the GNU General Public License
11# as published by the Free Software Foundation; either version 2
12# of the License, or (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22#
23#
24# Report bugs to: ck@zet.net, nagiosplug-help@lists.sf.net
25#
26# 11.01.2000 Version 1.0
27# $Id$
28
29use POSIX;
30use strict;
31use lib utils.pm ;
32use utils qw($TIMEOUT %ERRORS &print_revision &support);
33
34use Net::SNMP;
35use Getopt::Long;
36&Getopt::Long::config('bundling');
37
38my $PROGNAME = "check_ifoperstatus";
39my $status;
40my %ifOperStatus = ('1','up',
41 '2','down',
42 '3','testing',
43 '4','unknown',
44 '5','dormant',
45 '6','notPresent');
46
47my $state = "UNKNOWN";
48my $answer = "";
49my $snmpkey = 0;
50my $community = "public";
51my $port = 161;
52my @snmpoids;
53my $snmpIfDescr = '1.3.6.1.2.1.2.2.1.2';
54my $snmpIfOperStatus = '1.3.6.1.2.1.2.2.1.8';
55my $snmpIfName = '1.3.6.1.2.1.31.1.1.1.1';
56my $snmpIfAlias = '1.3.6.1.2.1.31.1.1.1.18';
57my $snmpLocIfDescr = '1.3.6.1.4.1.9.2.2.1.1.28';
58my $hostname;
59my $session;
60my $error;
61my $response;
62my $snmp_version = 1 ;
63my $ifXTable;
64my $opt_h ;
65my $opt_V ;
66my $ifdescr;
67my $key;
68
69
70
71# Just in case of problems, let's not hang Nagios
72$SIG{'ALRM'} = sub {
73 print ("ERROR: No snmp response from $hostname (alarm)\n");
74 exit $ERRORS{"UNKNOWN"};
75};
76#alarm($TIMEOUT);
77
78
79$status = GetOptions(
80 "V" => \$opt_V, "version" => \$opt_V,
81 "h" => \$opt_h, "help" => \$opt_h,
82 "v=i" => \$snmp_version, "snmp_version=i" => \$snmp_version,
83 "C=s" =>\$community, "community=s" => \$community,
84 "k=i" =>\$snmpkey, "key=i",\$snmpkey,
85 "d=s" =>\$ifdescr, "descr=s" => \$ifdescr,
86 "p=i" =>\$port, "port=i",\$port,
87 "H=s" => \$hostname, "hostname=s" => \$hostname,
88 "I" => \$ifXTable, "ifmib" => \$ifXTable);
89
90
91
92if ($status == 0)
93{
94 print_help();
95 exit $ERRORS{'OK'};
96}
97
98if ($opt_V) {
99 print_revision($PROGNAME,'$Revision$ ');
100 exit $ERRORS{'OK'};
101}
102
103if ($opt_h) {
104 print_help();
105 exit $ERRORS{'OK'};
106}
107
108if (! utils::is_hostname($hostname)){
109 usage();
110 exit $ERRORS{"UNKNOWN"};
111}
112
113
114if ( $snmp_version =~ /[12]/ ) {
115 ($session, $error) = Net::SNMP->session(
116 -hostname => $hostname,
117 -community => $community,
118 -port => $port,
119 -version => $snmp_version
120 );
121
122 if (!defined($session)) {
123 $state='UNKNOWN';
124 $answer=$error;
125 print ("$state: $answer");
126 exit $ERRORS{$state};
127 }
128}elsif ( $snmp_version =~ /3/ ) {
129 $state='UNKNOWN';
130 print ("$state: No support for SNMP v3 yet\n");
131 exit $ERRORS{$state};
132}else{
133 $state='UNKNOWN';
134 print ("$state: No support for SNMP v$snmp_version yet\n");
135 exit $ERRORS{$state};
136}
137
138if (defined $ifdescr) {
139 # escape "/" in ifdescr - very common in the Cisco world
140 $ifdescr =~ s/\//\\\//g;
141
142 $status=fetch_ifdescr(); # if using on device with large number of interfaces
143 # recommend use of SNMP v2 (get-bulk)
144 if ($status==0) {
145 $state = "UNKNOWN";
146 printf "$state: could not retrive ifIndex - $status-$snmpkey\n";
147 $session->close;
148 exit $ERRORS{$state};
149 }
150}
151if ( $snmpkey == 0 ) {
152 printf "ifIndex key cannot be 0\n";
153 usage();
154 exit $ERRORS{'UNKNOWN'};
155}
156
157 $snmpIfOperStatus = '1.3.6.1.2.1.2.2.1.8' . "." . $snmpkey;
158 $snmpIfDescr = '1.3.6.1.2.1.2.2.1.2' . "." . $snmpkey;
159 $snmpIfAlias = '1.3.6.1.2.1.31.1.1.1.18' . "." . $snmpkey ;
160
161
162push(@snmpoids,$snmpIfOperStatus);
163push(@snmpoids,$snmpIfDescr);
164push(@snmpoids,$snmpIfAlias) if (defined $ifXTable) ;
165
166 if (!defined($response = $session->get_request(@snmpoids))) {
167 $answer=$session->error;
168 $session->close;
169 $state = 'CRITICAL';
170 print ("$state: $answer for ifIndex $snmpkey\n");
171 exit $ERRORS{$state};
172 }
173
174 $answer = sprintf("host '%s', %s(%s) is %s\n",
175 $hostname,
176 $response->{$snmpIfDescr},
177 $snmpkey,
178 $ifOperStatus{$response->{$snmpIfOperStatus}}
179 );
180
181 $session->close;
182
183 if ( $response->{$snmpIfOperStatus} == 1 ) {
184 $state = 'OK';
185 }
186 else {
187 $state = 'CRITICAL';
188 }
189
190print ("$state: $answer");
191exit $ERRORS{$state};
192
193
194sub fetch_ifdescr {
195 if (!defined ($response = $session->get_table($snmpIfDescr))) {
196 $answer=$session->error;
197 $session->close;
198 $state = 'CRITICAL';
199 printf ("$state: $answer for $snmpIfDescr with snmp version $snmp_version\n");
200 $session->close;
201 exit $ERRORS{$state};
202 }
203
204 foreach $key ( keys %{$response}) {
205 if ($response->{$key} =~ /$ifdescr/) {
206 $key =~ /.*\.(\d+)$/;
207 $snmpkey = $1;
208 #print "$ifdescr = $key / $snmpkey \n"; #debug
209 }
210 }
211 unless (defined $snmpkey) {
212 $session->close;
213 $state = 'CRITICAL';
214 printf "$state: Could not match $ifdescr on $hostname\n";
215 exit $ERRORS{$state};
216 }
217
218 return $snmpkey;
219}
220
221sub usage {
222 printf "\nMissing arguments!\n";
223 printf "\n";
224 printf "usage: \n";
225 printf "check_ifoperstatus -k <IF_KEY> -H <HOSTNAME> [-C <community>]\n";
226 printf "Copyright (C) 2000 Christoph Kron\n";
227 printf "check_ifoperstatus.pl comes with ABSOLUTELY NO WARRANTY\n";
228 printf "This programm is licensed under the terms of the ";
229 printf "GNU General Public License\n(check source code for details)\n";
230 printf "\n\n";
231 exit $ERRORS{"UNKNOWN"};
232}
233
234sub print_help {
235 printf "check_ifoperstatus plugin for Nagios monitors operational \n";
236 printf "status of a particular network interface on the target host\n";
237 printf "\nUsage:\n";
238 printf " -H (--hostname) Hostname to query - (required)\n";
239 printf " -C (--community) SNMP read community (defaults to public,\n";
240 printf " used with SNMP v1 and v2c\n";
241 printf " -v (--snmp_version) 1 for SNMP v1 (default)\n";
242 printf " 2 for SNMP v2c\n";
243 printf " SNMP v2c will use get_bulk for less overhead\n";
244 printf " if monitoring with -d\n";
245 printf " -k (--key) SNMP ifIndex value\n";
246 printf " -d (--descr) SNMP ifDescr value\n";
247 printf " -p (--port) SNMP port (default 161)\n";
248 printf " -I (--ifmib) Agent supports IFMIB ifXTable. Do not use if\n";
249 printf " you don't know what this is.\n";
250 printf " -V (--version) Plugin version\n";
251 printf " -h (--help) usage help \n\n";
252 printf " -k or -d must be specified\n\n";
253 print_revision($PROGNAME, '$Revision$');
254
255}