diff options
-rwxr-xr-x | plugins-scripts/check_ifstatus.pl | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/plugins-scripts/check_ifstatus.pl b/plugins-scripts/check_ifstatus.pl index 38b87fcc..f0b7c491 100755 --- a/plugins-scripts/check_ifstatus.pl +++ b/plugins-scripts/check_ifstatus.pl | |||
@@ -97,11 +97,12 @@ my $opt_V ; | |||
97 | my $opt_u; | 97 | my $opt_u; |
98 | my $opt_n; | 98 | my $opt_n; |
99 | my $opt_x ; | 99 | my $opt_x ; |
100 | my $opt_d; | ||
100 | my %excluded ; | 101 | my %excluded ; |
101 | my %unused_names ; | 102 | my %unused_names ; |
102 | my @unused_ports ; | 103 | my @unused_ports ; |
103 | my %session_opts; | 104 | my %session_opts; |
104 | 105 | my @exclude_descriptions; | |
105 | 106 | ||
106 | 107 | ||
107 | 108 | ||
@@ -134,6 +135,7 @@ if (!defined($session)) { | |||
134 | } | 135 | } |
135 | 136 | ||
136 | 137 | ||
138 | push(@snmpoids,$snmpLocIfDescr); | ||
137 | push(@snmpoids,$snmpIfOperStatus); | 139 | push(@snmpoids,$snmpIfOperStatus); |
138 | push(@snmpoids,$snmpIfAdminStatus); | 140 | push(@snmpoids,$snmpIfAdminStatus); |
139 | push(@snmpoids,$snmpIfDescr); | 141 | push(@snmpoids,$snmpIfDescr); |
@@ -180,18 +182,28 @@ foreach $key (keys %ifStatus) { | |||
180 | if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) { | 182 | if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) { |
181 | #check only if interface is not excluded | 183 | #check only if interface is not excluded |
182 | if (!defined $unused_names{$ifStatus{$key}{$snmpIfDescr}} ) { | 184 | if (!defined $unused_names{$ifStatus{$key}{$snmpIfDescr}} ) { |
183 | # check only if interface type is not listed in %excluded | 185 | #check only if interface is not excluded (by description) |
184 | if (!defined $excluded{$ifStatus{$key}{$snmpIfType}} ) { | 186 | #counter for matching descriptions |
185 | if ($ifStatus{$key}{$snmpIfOperStatus} == 1 ) { $ifup++ ; } | 187 | my $match_descr = 0; |
186 | if ($ifStatus{$key}{$snmpIfOperStatus} == 2 ) { | 188 | foreach my $description (@exclude_descriptions) { |
187 | $ifdown++ ; | 189 | if ($ifStatus{$key}{$snmpLocIfDescr} =~ /^$description/) { $match_descr = 1; } |
188 | if (defined $ifXTable) { | 190 | } |
189 | $ifmessage .= sprintf("%s: down -> %s<BR>\n", $ifStatus{$key}{$snmpIfName}, $ifStatus{$key}{$snmpIfAlias}); | 191 | if ($match_descr == 0) { |
190 | }else{ | 192 | # check only if interface type is not listed in %excluded |
191 | $ifmessage .= sprintf("%s: down <BR>\n",$ifStatus{$key}{$snmpIfDescr}); | 193 | if (!defined $excluded{$ifStatus{$key}{$snmpIfType}} ) { |
192 | } | 194 | if ($ifStatus{$key}{$snmpIfOperStatus} == 1 ) { $ifup++ ; } |
195 | if ($ifStatus{$key}{$snmpIfOperStatus} == 2 ) { | ||
196 | $ifdown++ ; | ||
197 | if (defined $ifXTable) { | ||
198 | $ifmessage .= sprintf("%s: down -> %s<BR>\n", $ifStatus{$key}{$snmpIfName}, $ifStatus{$key}{$snmpIfAlias}); | ||
199 | }else{ | ||
200 | $ifmessage .= sprintf("%s: down <BR>\n",$ifStatus{$key}{$snmpIfDescr}); | ||
201 | } | ||
202 | } | ||
203 | if ($ifStatus{$key}{$snmpIfOperStatus} == 5 ) { $ifdormant++ ;} | ||
204 | } else { | ||
205 | $ifexclude++; | ||
193 | } | 206 | } |
194 | if ($ifStatus{$key}{$snmpIfOperStatus} == 5 ) { $ifdormant++ ;} | ||
195 | } else { | 207 | } else { |
196 | $ifexclude++; | 208 | $ifexclude++; |
197 | } | 209 | } |
@@ -264,6 +276,9 @@ sub print_help() { | |||
264 | printf " the descriptive name. Do not use if you don't know what this is. \n"; | 276 | printf " the descriptive name. Do not use if you don't know what this is. \n"; |
265 | printf " -x (--exclude) A comma separated list of ifType values that should be excluded \n"; | 277 | printf " -x (--exclude) A comma separated list of ifType values that should be excluded \n"; |
266 | printf " from the report (default for an empty list is PPP(23).\n"; | 278 | printf " from the report (default for an empty list is PPP(23).\n"; |
279 | printf " -d (--exclude_ports_by_description) A comma separated list of LocIfDescr values that should be excluded \n"; | ||
280 | printf " from the report (default is an empty exclusion list). Done using regexp '/^arg/', ex:\n"; | ||
281 | printf " '-d connect,test' will match with descriptions like 'testing phase' but not 'in testing'.\n"; | ||
267 | printf " -n (--unused_ports_by_name) A comma separated list of ifDescr values that should be excluded \n"; | 282 | 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"; | 283 | printf " from the report (default is an empty exclusion list).\n"; |
269 | printf " -u (--unused_ports) A comma separated list of ifIndex values that should be excluded \n"; | 284 | printf " -u (--unused_ports) A comma separated list of ifIndex values that should be excluded \n"; |
@@ -306,6 +321,7 @@ sub process_arguments() { | |||
306 | "I" => \$ifXTable, "ifmib" => \$ifXTable, | 321 | "I" => \$ifXTable, "ifmib" => \$ifXTable, |
307 | "x:s" => \$opt_x, "exclude:s" => \$opt_x, | 322 | "x:s" => \$opt_x, "exclude:s" => \$opt_x, |
308 | "u=s" => \$opt_u, "unused_ports=s" => \$opt_u, | 323 | "u=s" => \$opt_u, "unused_ports=s" => \$opt_u, |
324 | "d=s" => \$opt_d, "exclude_ports_by_description=s" => \$opt_d, | ||
309 | "n=s" => \$opt_n, "unused_ports_by_name=s" => \$opt_n, | 325 | "n=s" => \$opt_n, "unused_ports_by_name=s" => \$opt_n, |
310 | "M=i" => \$maxmsgsize, "maxmsgsize=i" => \$maxmsgsize, | 326 | "M=i" => \$maxmsgsize, "maxmsgsize=i" => \$maxmsgsize, |
311 | "t=i" => \$timeout, "timeout=i" => \$timeout, | 327 | "t=i" => \$timeout, "timeout=i" => \$timeout, |
@@ -414,6 +430,11 @@ sub process_arguments() { | |||
414 | } | 430 | } |
415 | } | 431 | } |
416 | 432 | ||
433 | # Exclude interfaces by descriptions | ||
434 | if (defined $opt_d) { | ||
435 | @exclude_descriptions = split(/,/,$opt_d); | ||
436 | } | ||
437 | |||
417 | # Excluded interface descriptors | 438 | # Excluded interface descriptors |
418 | if (defined $opt_n) { | 439 | if (defined $opt_n) { |
419 | my @unused = split(/,/,$opt_n); | 440 | my @unused = split(/,/,$opt_n); |