summaryrefslogtreecommitdiffstats
path: root/web/attachments/44653-check_ifstatus_errors.txt
diff options
context:
space:
mode:
Diffstat (limited to 'web/attachments/44653-check_ifstatus_errors.txt')
-rw-r--r--web/attachments/44653-check_ifstatus_errors.txt231
1 files changed, 231 insertions, 0 deletions
diff --git a/web/attachments/44653-check_ifstatus_errors.txt b/web/attachments/44653-check_ifstatus_errors.txt
new file mode 100644
index 0000000..3116fd7
--- /dev/null
+++ b/web/attachments/44653-check_ifstatus_errors.txt
@@ -0,0 +1,231 @@
1#! /usr/bin/perl -w
2#
3# check_ifstatus.pl - nagios plugin
4#
5#
6# Copyright (C) 2000 Christoph Kron
7# Modified 5/2002 to conform to updated Nagios Plugin Guidelines (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#
28# $Id: check_ifstatus.pl,v 1.3 2003/02/03 05:29:54 sghosh Exp $
29
30use POSIX;
31use strict;
32use lib "/usr/lib/nagios/plugins" ;
33use utils qw($TIMEOUT %ERRORS &print_revision &support);
34
35use Net::SNMP;
36use Getopt::Long;
37Getopt::Long::Configure('bundling');
38
39my $PROGNAME = "check_ifstatus";
40
41
42my $status;
43my %ifOperStatus = ('1','up',
44 '2','down',
45 '3','testing',
46 '4','unknown',
47 '5','dormant',
48 '6','notPresent');
49
50my $state = "UNKNOWN";
51my $answer = "";
52my $snmpkey=0;
53my $snmpoid=0;
54my $key=0;
55my $community = "public";
56my $port = 161;
57my @snmpoids;
58my $snmpifInErrors = '1.3.6.1.2.1.2.2.1.14';
59my $snmpifOutErrors = '1.3.6.1.2.1.2.2.1.20';
60my $snmpIfName = '1.3.6.1.2.1.2.2.1.2';
61my $hostname;
62my $session;
63my $error;
64my $response;
65my $ifup =0 ;
66my $ifdown =0;
67my $ifdormant = 0;
68my $ifmessage = "";
69my $snmp_version = 1;
70my $ifXTable;
71my $opt_h ;
72my $opt_V ;
73my $warn_level = 1000;
74my %ifStatus;
75my $iferrors = 0;
76
77
78
79
80
81# Just in case of problems, let's not hang Nagios
82$SIG{'ALRM'} = sub {
83 print ("ERROR: No snmp response from $hostname (alarm timeout)\n");
84 exit $ERRORS{"UNKNOWN"};
85};
86alarm($TIMEOUT);
87
88
89
90#Option checking
91$status = GetOptions(
92 "V" => \$opt_V, "version" => \$opt_V,
93 "h" => \$opt_h, "help" => \$opt_h,
94 "v=i" => \$snmp_version, "snmp_version=i" => \$snmp_version,
95 "C=s" =>\$community,"community=s" => \$community,
96 "p=i" =>\$port, "port=i" => \$port,
97 "H=s" => \$hostname, "hostname=s" => \$hostname,
98 "I" => \$ifXTable, "ifmib" => \$ifXTable );
99
100if ($status == 0)
101{
102 print_help() ;
103 exit $ERRORS{'OK'};
104}
105
106
107if ($opt_V) {
108 print_revision($PROGNAME,'$Revision: 1.3 $ ');
109 exit $ERRORS{'OK'};
110}
111
112if ($opt_h) {
113 print_help();
114 exit $ERRORS{'OK'};
115}
116
117if (! utils::is_hostname($hostname)){
118 usage();
119 exit $ERRORS{"UNKNOWN"};
120}
121
122if ( ! $snmp_version ) {
123 $snmp_version =1 ;
124}else{
125 if ( $snmp_version =~ /[12]/ ) {
126
127 ($session, $error) = Net::SNMP->session(
128 -hostname => $hostname,
129 -community => $community,
130 -port => $port,
131 -version => $snmp_version
132 );
133
134 if (!defined($session)) {
135 $state='UNKNOWN';
136 $answer=$error;
137 print ("$state: $answer");
138 exit $ERRORS{$state};
139 }
140
141
142 }elsif ( $snmp_version =~ /3/ ) {
143 $state='UNKNOWN';
144 print ("$state: No support for SNMP v3 yet\n");
145 exit $ERRORS{$state};
146 }else{
147 $state='UNKNOWN';
148 print ("$state: No support for SNMP v$snmp_version yet\n");
149 exit $ERRORS{$state};
150 }
151}
152
153
154
155push(@snmpoids,$snmpifInErrors);
156push(@snmpoids,$snmpifOutErrors);
157push(@snmpoids,$snmpIfName);
158
159
160foreach $snmpoid (@snmpoids) {
161
162 if (!defined($response = $session->get_table($snmpoid))) {
163 $answer=$session->error;
164 $session->close;
165 $state = 'CRITICAL';
166 print ("$state: $answer for $snmpoid with snmp version $snmp_version\n");
167 exit $ERRORS{$state};
168 }
169
170 foreach $snmpkey (keys %{$response}) {
171 $snmpkey =~ /.*\.(\d+)$/;
172 $key = $1;
173 $ifStatus{$key}{$snmpoid} = $response->{$snmpkey};
174 }
175}
176
177
178$session->close;
179
180foreach $key (keys %ifStatus) {
181 #print "DEBG : $key :: $ifStatus{$key}{$snmpIfName} \n";
182
183 if (defined($ifStatus{$key}{$snmpifInErrors})) {
184 if ($ifStatus{$key}{$snmpifInErrors} >= $warn_level ) {
185 $iferrors++;
186 $ifmessage .= sprintf("%s: has %s errors<BR>",
187 $ifStatus{$key}{$snmpIfName},
188 $ifStatus{$key}{$snmpifInErrors});
189 }
190 }
191}
192
193if ($iferrors > 0) {
194 $state = 'WARNING';
195}
196else {
197 $state = 'OK';
198}
199
200print ("$state: $ifmessage\n");
201exit $ERRORS{$state};
202
203sub usage {
204 printf "\nMissing arguments!\n";
205 printf "\n";
206 printf "check_ifstatus_errors -C <READCOMMUNITY> -p <PORT> -H <HOSTNAME>\n";
207 printf "Copyright (C) 2000 Christoph Kron\n";
208 printf "Updates 5/2002 Subhendu Ghosh\n";
209 printf "\n\n";
210 support();
211 exit $ERRORS{"UNKNOWN"};
212}
213
214sub print_help {
215 printf "check_ifstatus plugin for Nagios monitors operational \n";
216 printf "status of each network interface (except PPP interfaces) on the target host\n";
217 printf "\nUsage:\n";
218 printf " -H (--hostname) Hostname to query - (required)\n";
219 printf " -C (--community) SNMP read community (defaults to public,\n";
220 printf " used with SNMP v1 and v2c\n";
221 printf " -v (--snmp_version) 1 for SNMP v1 (default)\n";
222 printf " 2 for SNMP v2c\n";
223 printf " SNMP v2c will use get_bulk for less overhead\n";
224 printf " -p (--port) SNMP port (default 161)\n";
225 printf " -I (--ifmib) Agent supports IFMIB ifXTable. Do not use if\n";
226 printf " you don't know what this is.\n";
227 printf " -V (--version) Plugin version\n";
228 printf " -h (--help) usage help \n\n";
229 print_revision($PROGNAME, '$Revision: 1.3 $');
230
231}