aboutsummaryrefslogtreecommitdiff
path: root/plugins-scripts
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-scripts')
-rwxr-xr-xplugins-scripts/check_ifstatus.pl57
1 files changed, 38 insertions, 19 deletions
diff --git a/plugins-scripts/check_ifstatus.pl b/plugins-scripts/check_ifstatus.pl
index 709ad174..9aa25151 100755
--- a/plugins-scripts/check_ifstatus.pl
+++ b/plugins-scripts/check_ifstatus.pl
@@ -9,6 +9,7 @@
# Added -u option (4/2003)
# Added -M option (10/2003)
# Added SNMPv3 support (10/2003)
+# Added -n option (07/2014)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -95,8 +96,10 @@ my $ifXTable;
my $opt_h ;
my $opt_V ;
my $opt_u;
+my $opt_n;
my $opt_x ;
my %excluded ;
+my %unused_names ;
my @unused_ports ;
my %session_opts;
@@ -171,27 +174,30 @@ alarm(0);
foreach $key (keys %ifStatus) {
# skip unused interfaces
- if (!defined($ifStatus{$key}{'notInUse'})) {
+ my $ifName = $ifStatus{$key}{$snmpIfDescr};
+
+ if (!defined($ifStatus{$key}{'notInUse'}) || !grep(/^${ifName}/, @unused_ports )) {
# check only if interface is administratively up
- if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) {
-
- # check only if interface type is not listed in %excluded
- if (!defined $excluded{$ifStatus{$key}{$snmpIfType}} ) {
- if ($ifStatus{$key}{$snmpIfOperStatus} == 1 ) { $ifup++ ;}
- if ($ifStatus{$key}{$snmpIfOperStatus} == 2 ) {
- $ifdown++ ;
- if (defined $ifXTable) {
- $ifmessage .= sprintf("%s: down -> %s<BR>",
- $ifStatus{$key}{$snmpIfName},
- $ifStatus{$key}{$snmpIfAlias});
- }else{
- $ifmessage .= sprintf("%s: down <BR>",
- $ifStatus{$key}{$snmpIfDescr});
- }
+ if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) {
+ #check only if interface is not excluded
+ if (!defined $unused_names{$ifStatus{$key}{$snmpIfDescr}} ) {
+ # check only if interface type is not listed in %excluded
+ if (!defined $excluded{$ifStatus{$key}{$snmpIfType}} ) {
+ if ($ifStatus{$key}{$snmpIfOperStatus} == 1 ) { $ifup++ ; }
+ if ($ifStatus{$key}{$snmpIfOperStatus} == 2 ) {
+ $ifdown++ ;
+ if (defined $ifXTable) {
+ $ifmessage .= sprintf("%s: down -> %s<BR>\n", $ifStatus{$key}{$snmpIfName}, $ifStatus{$key}{$snmpIfAlias});
+ }else{
+ $ifmessage .= sprintf("%s: down <BR>\n",$ifStatus{$key}{$snmpIfDescr});
+ }
+ }
+ if ($ifStatus{$key}{$snmpIfOperStatus} == 5 ) { $ifdormant++ ;}
+ } else {
+ $ifexclude++;
}
- if ($ifStatus{$key}{$snmpIfOperStatus} == 5 ) { $ifdormant++ ;}
- }else{
- $ifexclude++;
+ } else {
+ $ifunused++;
}
}
@@ -259,6 +265,8 @@ sub print_help() {
printf " the descriptive name. Do not use if you don't know what this is. \n";
printf " -x (--exclude) A comma separated list of ifType values that should be excluded \n";
printf " from the report (default for an empty list is PPP(23).\n";
+ printf " -n (--unused_ports_by_name) A comma separated list of ifDescr values that should be excluded \n";
+ printf " from the report (default is an empty exclusion list).\n";
printf " -u (--unused_ports) A comma separated list of ifIndex values that should be excluded \n";
printf " from the report (default is an empty exclusion list).\n";
printf " See the IANAifType-MIB for a list of interface types.\n";
@@ -299,6 +307,7 @@ sub process_arguments() {
"I" => \$ifXTable, "ifmib" => \$ifXTable,
"x:s" => \$opt_x, "exclude:s" => \$opt_x,
"u=s" => \$opt_u, "unused_ports=s" => \$opt_u,
+ "n=s" => \$opt_n, "unused_ports_by_name=s" => \$opt_n,
"M=i" => \$maxmsgsize, "maxmsgsize=i" => \$maxmsgsize,
"t=i" => \$timeout, "timeout=i" => \$timeout,
);
@@ -406,6 +415,16 @@ sub process_arguments() {
}
}
+ # Excluded interface descriptors
+ if (defined $opt_n) {
+ my @unused = split(/,/,$opt_n);
+ if ( @unused ) {
+ foreach $key (@unused) {
+ $unused_names{$key} = 1;
+ }
+ }
+ }
+
# Excluded interface ports (ifIndex) - management reasons
if ($opt_u) {
@unused_ports = split(/,/,$opt_u);