diff options
author | Nick Peelman <nick@peelman.us> | 2013-05-13 09:30:09 -0400 |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2014-09-10 20:39:00 +0200 |
commit | 9a4771b09fb7d802a38abfeba0c8e0b52bab29af (patch) | |
tree | 34318830e1cf00b4e74e6dabe6d3e18fd9ce5ea4 /plugins-scripts/check_ifstatus.pl | |
parent | 57fb03cea59c266a0930c3a368cbed40bbc66169 (diff) | |
download | monitoring-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-x | plugins-scripts/check_ifstatus.pl | 57 |
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 @@ | |||
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 |
@@ -95,8 +96,10 @@ my $ifXTable; | |||
95 | my $opt_h ; | 96 | my $opt_h ; |
96 | my $opt_V ; | 97 | my $opt_V ; |
97 | my $opt_u; | 98 | my $opt_u; |
99 | my $opt_n; | ||
98 | my $opt_x ; | 100 | my $opt_x ; |
99 | my %excluded ; | 101 | my %excluded ; |
102 | my %unused_names ; | ||
100 | my @unused_ports ; | 103 | my @unused_ports ; |
101 | my %session_opts; | 104 | my %session_opts; |
102 | 105 | ||
@@ -171,27 +174,30 @@ alarm(0); | |||
171 | foreach $key (keys %ifStatus) { | 174 | foreach $key (keys %ifStatus) { |
172 | 175 | ||
173 | # skip unused interfaces | 176 | # skip unused interfaces |
174 | if (!defined($ifStatus{$key}{'notInUse'})) { | 177 | my $ifName = $ifStatus{$key}{$snmpIfDescr}; |
178 | |||
179 | if (!defined($ifStatus{$key}{'notInUse'}) || !grep(/^${ifName}/, @unused_ports )) { | ||
175 | # check only if interface is administratively up | 180 | # check only if interface is administratively up |
176 | if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) { | 181 | if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) { |
177 | 182 | #check only if interface is not excluded | |
178 | # check only if interface type is not listed in %excluded | 183 | if (!defined $unused_names{$ifStatus{$key}{$snmpIfDescr}} ) { |
179 | if (!defined $excluded{$ifStatus{$key}{$snmpIfType}} ) { | 184 | # check only if interface type is not listed in %excluded |
180 | if ($ifStatus{$key}{$snmpIfOperStatus} == 1 ) { $ifup++ ;} | 185 | if (!defined $excluded{$ifStatus{$key}{$snmpIfType}} ) { |
181 | if ($ifStatus{$key}{$snmpIfOperStatus} == 2 ) { | 186 | if ($ifStatus{$key}{$snmpIfOperStatus} == 1 ) { $ifup++ ; } |
182 | $ifdown++ ; | 187 | if ($ifStatus{$key}{$snmpIfOperStatus} == 2 ) { |
183 | if (defined $ifXTable) { | 188 | $ifdown++ ; |
184 | $ifmessage .= sprintf("%s: down -> %s<BR>", | 189 | if (defined $ifXTable) { |
185 | $ifStatus{$key}{$snmpIfName}, | 190 | $ifmessage .= sprintf("%s: down -> %s<BR>\n", $ifStatus{$key}{$snmpIfName}, $ifStatus{$key}{$snmpIfAlias}); |
186 | $ifStatus{$key}{$snmpIfAlias}); | 191 | }else{ |
187 | }else{ | 192 | $ifmessage .= sprintf("%s: down <BR>\n",$ifStatus{$key}{$snmpIfDescr}); |
188 | $ifmessage .= sprintf("%s: down <BR>", | 193 | } |
189 | $ifStatus{$key}{$snmpIfDescr}); | 194 | } |
190 | } | 195 | if ($ifStatus{$key}{$snmpIfOperStatus} == 5 ) { $ifdormant++ ;} |
196 | } else { | ||
197 | $ifexclude++; | ||
191 | } | 198 | } |
192 | if ($ifStatus{$key}{$snmpIfOperStatus} == 5 ) { $ifdormant++ ;} | 199 | } else { |
193 | }else{ | 200 | $ifunused++; |
194 | $ifexclude++; | ||
195 | } | 201 | } |
196 | 202 | ||
197 | } | 203 | } |
@@ -259,6 +265,8 @@ sub print_help() { | |||
259 | printf " the descriptive name. Do not use if you don't know what this is. \n"; | 265 | 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"; | 266 | 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"; | 267 | printf " from the report (default for an empty list is PPP(23).\n"; |
268 | printf " -n (--unused_ports_by_name) A comma separated list of ifDescr values that should be excluded \n"; | ||
269 | 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"; | 270 | 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"; | 271 | printf " from the report (default is an empty exclusion list).\n"; |
264 | printf " See the IANAifType-MIB for a list of interface types.\n"; | 272 | printf " See the IANAifType-MIB for a list of interface types.\n"; |
@@ -299,6 +307,7 @@ sub process_arguments() { | |||
299 | "I" => \$ifXTable, "ifmib" => \$ifXTable, | 307 | "I" => \$ifXTable, "ifmib" => \$ifXTable, |
300 | "x:s" => \$opt_x, "exclude:s" => \$opt_x, | 308 | "x:s" => \$opt_x, "exclude:s" => \$opt_x, |
301 | "u=s" => \$opt_u, "unused_ports=s" => \$opt_u, | 309 | "u=s" => \$opt_u, "unused_ports=s" => \$opt_u, |
310 | "n=s" => \$opt_n, "unused_ports_by_name=s" => \$opt_n, | ||
302 | "M=i" => \$maxmsgsize, "maxmsgsize=i" => \$maxmsgsize, | 311 | "M=i" => \$maxmsgsize, "maxmsgsize=i" => \$maxmsgsize, |
303 | "t=i" => \$timeout, "timeout=i" => \$timeout, | 312 | "t=i" => \$timeout, "timeout=i" => \$timeout, |
304 | ); | 313 | ); |
@@ -406,6 +415,16 @@ sub process_arguments() { | |||
406 | } | 415 | } |
407 | } | 416 | } |
408 | 417 | ||
418 | # Excluded interface descriptors | ||
419 | if (defined $opt_n) { | ||
420 | my @unused = split(/,/,$opt_n); | ||
421 | if ( @unused ) { | ||
422 | foreach $key (@unused) { | ||
423 | $unused_names{$key} = 1; | ||
424 | } | ||
425 | } | ||
426 | } | ||
427 | |||
409 | # Excluded interface ports (ifIndex) - management reasons | 428 | # Excluded interface ports (ifIndex) - management reasons |
410 | if ($opt_u) { | 429 | if ($opt_u) { |
411 | @unused_ports = split(/,/,$opt_u); | 430 | @unused_ports = split(/,/,$opt_u); |