diff options
Diffstat (limited to 'web/attachments/44653-check_ifstatus_errors.txt')
| -rw-r--r-- | web/attachments/44653-check_ifstatus_errors.txt | 231 |
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 | |||
| 30 | use POSIX; | ||
| 31 | use strict; | ||
| 32 | use lib "/usr/lib/nagios/plugins" ; | ||
| 33 | use utils qw($TIMEOUT %ERRORS &print_revision &support); | ||
| 34 | |||
| 35 | use Net::SNMP; | ||
| 36 | use Getopt::Long; | ||
| 37 | Getopt::Long::Configure('bundling'); | ||
| 38 | |||
| 39 | my $PROGNAME = "check_ifstatus"; | ||
| 40 | |||
| 41 | |||
| 42 | my $status; | ||
| 43 | my %ifOperStatus = ('1','up', | ||
| 44 | '2','down', | ||
| 45 | '3','testing', | ||
| 46 | '4','unknown', | ||
| 47 | '5','dormant', | ||
| 48 | '6','notPresent'); | ||
| 49 | |||
| 50 | my $state = "UNKNOWN"; | ||
| 51 | my $answer = ""; | ||
| 52 | my $snmpkey=0; | ||
| 53 | my $snmpoid=0; | ||
| 54 | my $key=0; | ||
| 55 | my $community = "public"; | ||
| 56 | my $port = 161; | ||
| 57 | my @snmpoids; | ||
| 58 | my $snmpifInErrors = '1.3.6.1.2.1.2.2.1.14'; | ||
| 59 | my $snmpifOutErrors = '1.3.6.1.2.1.2.2.1.20'; | ||
| 60 | my $snmpIfName = '1.3.6.1.2.1.2.2.1.2'; | ||
| 61 | my $hostname; | ||
| 62 | my $session; | ||
| 63 | my $error; | ||
| 64 | my $response; | ||
| 65 | my $ifup =0 ; | ||
| 66 | my $ifdown =0; | ||
| 67 | my $ifdormant = 0; | ||
| 68 | my $ifmessage = ""; | ||
| 69 | my $snmp_version = 1; | ||
| 70 | my $ifXTable; | ||
| 71 | my $opt_h ; | ||
| 72 | my $opt_V ; | ||
| 73 | my $warn_level = 1000; | ||
| 74 | my %ifStatus; | ||
| 75 | my $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 | }; | ||
| 86 | alarm($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 | |||
| 100 | if ($status == 0) | ||
| 101 | { | ||
| 102 | print_help() ; | ||
| 103 | exit $ERRORS{'OK'}; | ||
| 104 | } | ||
| 105 | |||
| 106 | |||
| 107 | if ($opt_V) { | ||
| 108 | print_revision($PROGNAME,'$Revision: 1.3 $ '); | ||
| 109 | exit $ERRORS{'OK'}; | ||
| 110 | } | ||
| 111 | |||
| 112 | if ($opt_h) { | ||
| 113 | print_help(); | ||
| 114 | exit $ERRORS{'OK'}; | ||
| 115 | } | ||
| 116 | |||
| 117 | if (! utils::is_hostname($hostname)){ | ||
| 118 | usage(); | ||
| 119 | exit $ERRORS{"UNKNOWN"}; | ||
| 120 | } | ||
| 121 | |||
| 122 | if ( ! $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 | |||
| 155 | push(@snmpoids,$snmpifInErrors); | ||
| 156 | push(@snmpoids,$snmpifOutErrors); | ||
| 157 | push(@snmpoids,$snmpIfName); | ||
| 158 | |||
| 159 | |||
| 160 | foreach $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 | |||
| 180 | foreach $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 | |||
| 193 | if ($iferrors > 0) { | ||
| 194 | $state = 'WARNING'; | ||
| 195 | } | ||
| 196 | else { | ||
| 197 | $state = 'OK'; | ||
| 198 | } | ||
| 199 | |||
| 200 | print ("$state: $ifmessage\n"); | ||
| 201 | exit $ERRORS{$state}; | ||
| 202 | |||
| 203 | sub 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 | |||
| 214 | sub 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 | } | ||
