diff options
Diffstat (limited to 'plugins-scripts/check_ifstatus.pl')
| -rwxr-xr-x | plugins-scripts/check_ifstatus.pl | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/plugins-scripts/check_ifstatus.pl b/plugins-scripts/check_ifstatus.pl index 709ad174..2c76d0c8 100755 --- a/plugins-scripts/check_ifstatus.pl +++ b/plugins-scripts/check_ifstatus.pl | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | # Added -u option (4/2003) | 9 | # Added -u option (4/2003) |
| 10 | # Added -M option (10/2003) | 10 | # Added -M option (10/2003) |
| 11 | # Added SNMPv3 support (10/2003) | 11 | # Added SNMPv3 support (10/2003) |
| 12 | # Added -n option (07/2014) | ||
| 12 | # | 13 | # |
| 13 | # This program is free software; you can redistribute it and/or | 14 | # This program is free software; you can redistribute it and/or |
| 14 | # modify it under the terms of the GNU General Public License | 15 | # modify it under the terms of the GNU General Public License |
| @@ -34,7 +35,6 @@ use POSIX; | |||
| 34 | use strict; | 35 | use strict; |
| 35 | use FindBin; | 36 | use FindBin; |
| 36 | use lib "$FindBin::Bin"; | 37 | use lib "$FindBin::Bin"; |
| 37 | use lib '@libexecdir@'; | ||
| 38 | use utils qw($TIMEOUT %ERRORS &print_revision &support); | 38 | use utils qw($TIMEOUT %ERRORS &print_revision &support); |
| 39 | 39 | ||
| 40 | use Net::SNMP; | 40 | use Net::SNMP; |
| @@ -95,8 +95,10 @@ my $ifXTable; | |||
| 95 | my $opt_h ; | 95 | my $opt_h ; |
| 96 | my $opt_V ; | 96 | my $opt_V ; |
| 97 | my $opt_u; | 97 | my $opt_u; |
| 98 | my $opt_n; | ||
| 98 | my $opt_x ; | 99 | my $opt_x ; |
| 99 | my %excluded ; | 100 | my %excluded ; |
| 101 | my %unused_names ; | ||
| 100 | my @unused_ports ; | 102 | my @unused_ports ; |
| 101 | my %session_opts; | 103 | my %session_opts; |
| 102 | 104 | ||
| @@ -171,27 +173,30 @@ alarm(0); | |||
| 171 | foreach $key (keys %ifStatus) { | 173 | foreach $key (keys %ifStatus) { |
| 172 | 174 | ||
| 173 | # skip unused interfaces | 175 | # skip unused interfaces |
| 174 | if (!defined($ifStatus{$key}{'notInUse'})) { | 176 | my $ifName = $ifStatus{$key}{$snmpIfDescr}; |
| 177 | |||
| 178 | if (!defined($ifStatus{$key}{'notInUse'}) && !grep(/^${ifName}/, @unused_ports )) { | ||
| 175 | # check only if interface is administratively up | 179 | # check only if interface is administratively up |
| 176 | if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) { | 180 | if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) { |
| 177 | 181 | #check only if interface is not excluded | |
| 178 | # check only if interface type is not listed in %excluded | 182 | if (!defined $unused_names{$ifStatus{$key}{$snmpIfDescr}} ) { |
| 179 | if (!defined $excluded{$ifStatus{$key}{$snmpIfType}} ) { | 183 | # check only if interface type is not listed in %excluded |
| 180 | if ($ifStatus{$key}{$snmpIfOperStatus} == 1 ) { $ifup++ ;} | 184 | if (!defined $excluded{$ifStatus{$key}{$snmpIfType}} ) { |
| 181 | if ($ifStatus{$key}{$snmpIfOperStatus} == 2 ) { | 185 | if ($ifStatus{$key}{$snmpIfOperStatus} == 1 ) { $ifup++ ; } |
| 182 | $ifdown++ ; | 186 | if ($ifStatus{$key}{$snmpIfOperStatus} == 2 ) { |
| 183 | if (defined $ifXTable) { | 187 | $ifdown++ ; |
| 184 | $ifmessage .= sprintf("%s: down -> %s<BR>", | 188 | if (defined $ifXTable) { |
| 185 | $ifStatus{$key}{$snmpIfName}, | 189 | $ifmessage .= sprintf("%s: down -> %s<BR>\n", $ifStatus{$key}{$snmpIfName}, $ifStatus{$key}{$snmpIfAlias}); |
| 186 | $ifStatus{$key}{$snmpIfAlias}); | 190 | }else{ |
| 187 | }else{ | 191 | $ifmessage .= sprintf("%s: down <BR>\n",$ifStatus{$key}{$snmpIfDescr}); |
| 188 | $ifmessage .= sprintf("%s: down <BR>", | 192 | } |
| 189 | $ifStatus{$key}{$snmpIfDescr}); | 193 | } |
| 190 | } | 194 | if ($ifStatus{$key}{$snmpIfOperStatus} == 5 ) { $ifdormant++ ;} |
| 195 | } else { | ||
| 196 | $ifexclude++; | ||
| 191 | } | 197 | } |
| 192 | if ($ifStatus{$key}{$snmpIfOperStatus} == 5 ) { $ifdormant++ ;} | 198 | } else { |
| 193 | }else{ | 199 | $ifunused++; |
| 194 | $ifexclude++; | ||
| 195 | } | 200 | } |
| 196 | 201 | ||
| 197 | } | 202 | } |
| @@ -259,6 +264,8 @@ sub print_help() { | |||
| 259 | printf " the descriptive name. Do not use if you don't know what this is. \n"; | 264 | printf " the descriptive name. Do not use if you don't know what this is. \n"; |
| 260 | printf " -x (--exclude) A comma separated list of ifType values that should be excluded \n"; | 265 | printf " -x (--exclude) A comma separated list of ifType values that should be excluded \n"; |
| 261 | printf " from the report (default for an empty list is PPP(23).\n"; | 266 | printf " from the report (default for an empty list is PPP(23).\n"; |
| 267 | printf " -n (--unused_ports_by_name) A comma separated list of ifDescr values that should be excluded \n"; | ||
| 268 | printf " from the report (default is an empty exclusion list).\n"; | ||
| 262 | printf " -u (--unused_ports) A comma separated list of ifIndex values that should be excluded \n"; | 269 | printf " -u (--unused_ports) A comma separated list of ifIndex values that should be excluded \n"; |
| 263 | printf " from the report (default is an empty exclusion list).\n"; | 270 | printf " from the report (default is an empty exclusion list).\n"; |
| 264 | printf " See the IANAifType-MIB for a list of interface types.\n"; | 271 | printf " See the IANAifType-MIB for a list of interface types.\n"; |
| @@ -299,6 +306,7 @@ sub process_arguments() { | |||
| 299 | "I" => \$ifXTable, "ifmib" => \$ifXTable, | 306 | "I" => \$ifXTable, "ifmib" => \$ifXTable, |
| 300 | "x:s" => \$opt_x, "exclude:s" => \$opt_x, | 307 | "x:s" => \$opt_x, "exclude:s" => \$opt_x, |
| 301 | "u=s" => \$opt_u, "unused_ports=s" => \$opt_u, | 308 | "u=s" => \$opt_u, "unused_ports=s" => \$opt_u, |
| 309 | "n=s" => \$opt_n, "unused_ports_by_name=s" => \$opt_n, | ||
| 302 | "M=i" => \$maxmsgsize, "maxmsgsize=i" => \$maxmsgsize, | 310 | "M=i" => \$maxmsgsize, "maxmsgsize=i" => \$maxmsgsize, |
| 303 | "t=i" => \$timeout, "timeout=i" => \$timeout, | 311 | "t=i" => \$timeout, "timeout=i" => \$timeout, |
| 304 | ); | 312 | ); |
| @@ -406,6 +414,16 @@ sub process_arguments() { | |||
| 406 | } | 414 | } |
| 407 | } | 415 | } |
| 408 | 416 | ||
| 417 | # Excluded interface descriptors | ||
| 418 | if (defined $opt_n) { | ||
| 419 | my @unused = split(/,/,$opt_n); | ||
| 420 | if ( @unused ) { | ||
| 421 | foreach $key (@unused) { | ||
| 422 | $unused_names{$key} = 1; | ||
| 423 | } | ||
| 424 | } | ||
| 425 | } | ||
| 426 | |||
| 409 | # Excluded interface ports (ifIndex) - management reasons | 427 | # Excluded interface ports (ifIndex) - management reasons |
| 410 | if ($opt_u) { | 428 | if ($opt_u) { |
| 411 | @unused_ports = split(/,/,$opt_u); | 429 | @unused_ports = split(/,/,$opt_u); |
