From 9a4771b09fb7d802a38abfeba0c8e0b52bab29af Mon Sep 17 00:00:00 2001 From: Nick Peelman Date: Mon, 13 May 2013 09:30:09 -0400 Subject: Add check_ifstatus option to ignore interfaces by name Ignoring by index is not always an option, as the index can change on chassis switches as blade configurations change. --- plugins-scripts/check_ifstatus.pl | 57 ++++++++++++++++++++++++++------------- 1 file 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
", - $ifStatus{$key}{$snmpIfName}, - $ifStatus{$key}{$snmpIfAlias}); - }else{ - $ifmessage .= sprintf("%s: down
", - $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
\n", $ifStatus{$key}{$snmpIfName}, $ifStatus{$key}{$snmpIfAlias}); + }else{ + $ifmessage .= sprintf("%s: down
\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); -- cgit v1.2.3-74-g34f1