index 8a23ca5eab902d1372ab6bae0d639028d83717a6..62891ff76ea80a1421904ccb9b119dbaea038a06 100644 (file)
sub usage ();
sub process_arguments ();
+my $timeout;
my $status;
my %ifOperStatus = ('1','up',
'2','down',
my $key;
my $lastc;
my $dormantWarn;
+my $adminWarn;
my $name;
+### Validate Arguments
+
+$status = process_arguments();
# Just in case of problems, let's not hang Nagios
print ("ERROR: No snmp response from $hostname (alarm)\n");
exit $ERRORS{"UNKNOWN"};
};
-alarm($TIMEOUT);
-
-
-### Validate Arguments
-$status = process_arguments();
+alarm($timeout);
## map ifdescr to ifindex - should look at being able to cache this value
## if AdminStatus is down - some one made a consious effort to change config
##
if ( not ($response->{$snmpIfAdminStatus} == 1) ) {
- $state = 'WARNING';
- $answer = "Interface $name (index $snmpkey) is administratively down.";
-
+ $answer = "Interface $name (index $snmpkey) is administratively down.";
+ if ( not defined $adminWarn or $adminWarn eq "w" ) {
+ $state = 'WARNING';
+ } elsif ( $adminWarn eq "i" ) {
+ $state = 'OK';
+ } elsif ( $adminWarn eq "c" ) {
+ $state = 'CRITICAL';
+ } else { # If wrong value for -a, say warning
+ $state = 'WARNING';
+ }
}
## Check operational status
elsif ( $response->{$snmpIfOperStatus} == 2 ) {
} elsif ( $response->{$snmpIfOperStatus} == 5 ) {
if (defined $dormantWarn ) {
if ($dormantWarn eq "w") {
- $state = 'WARNNG';
+ $state = 'WARNING';
$answer = "Interface $name (index $snmpkey) is dormant.";
}elsif($dormantWarn eq "c") {
$state = 'CRITICAL';
printf " -n (--name) the value should match the returned ifName\n";
printf " (Implies the use of -I)\n";
printf " -w (--warn =i|w|c) ignore|warn|crit if the interface is dormant (default critical)\n";
+ printf " -D (--admin-down =i|w|c) same for administratively down interfaces (default warning)\n";
printf " -M (--maxmsgsize) Max message size - usefull only for v1 or v2c\n";
+ printf " -t (--timeout) seconds before the plugin times out (default=$TIMEOUT)\n";
printf " -V (--version) Plugin version\n";
printf " -h (--help) usage help \n\n";
printf " -k or -d must be specified\n\n";
"k=i" => \$snmpkey, "key=i",\$snmpkey,
"d=s" => \$ifdescr, "descr=s" => \$ifdescr,
"l=s" => \$lastc, "lastchange=s" => \$lastc,
- "p=i" = >\$port, "port=i" =>\$port,
+ "p=i" => \$port, "port=i" =>\$port,
"H=s" => \$hostname, "hostname=s" => \$hostname,
- "I" => \$ifXTable, "ifmib" => \$ifXTable,
+ "I" => \$ifXTable, "ifmib" => \$ifXTable,
"n=s" => \$ifName, "name=s" => \$ifName,
"w=s" => \$dormantWarn, "warn=s" => \$dormantWarn,
- "M=i" => \$maxmsgsize, "maxmsgsize=i" => \$maxmsgsize);
+ "D=s" => \$adminWarn, "admin-down=s" => \$adminWarn,
+ "M=i" => \$maxmsgsize, "maxmsgsize=i" => \$maxmsgsize,
+ "t=i" => \$timeout, "timeout=i" => \$timeout,
+ );
}
}
+ unless (defined $timeout) {
+ $timeout = $TIMEOUT;
+ }
+
if ($snmp_version =~ /3/ ) {
# Must define a security level even though default is noAuthNoPriv
# v3 requires a security username
if (defined $seclevel && defined $secname) {
# Must define a security level even though defualt is noAuthNoPriv
- unless ($seclevel eq ('noAuthNoPriv' || 'authNoPriv' || 'authPriv' ) ) {
+ unless ( grep /^$seclevel$/, qw(noAuthNoPriv authNoPriv authPriv) ) {
usage();
exit $ERRORS{"UNKNOWN"};
}
# Authentication wanted
- if ($seclevel eq ('authNoPriv' || 'authPriv') ) {
+ if ( $seclevel eq 'authNoPriv' || $seclevel eq 'authPriv' ) {
- unless ($authproto eq ('MD5' || 'SHA1') ) {
+ unless ( $authproto eq 'MD5' || $authproto eq 'SHA1' ) {
usage();
exit $ERRORS{"UNKNOWN"};
}