aboutsummaryrefslogtreecommitdiff
path: root/plugins-scripts/check_ifstatus.pl
diff options
context:
space:
mode:
authorGravatar Nick Peelman <nick@peelman.us> 2013-05-13 09:30:09 -0400
committerGravatar Holger Weiss <holger@zedat.fu-berlin.de> 2014-09-10 20:39:00 +0200
commit9a4771b09fb7d802a38abfeba0c8e0b52bab29af (patch)
tree34318830e1cf00b4e74e6dabe6d3e18fd9ce5ea4 /plugins-scripts/check_ifstatus.pl
parent57fb03cea59c266a0930c3a368cbed40bbc66169 (diff)
downloadmonitoring-plugins-9a4771b09fb7d802a38abfeba0c8e0b52bab29af.tar.gz
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.
Diffstat (limited to 'plugins-scripts/check_ifstatus.pl')
-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);