From 111fde880a5c4327bc81e8d97dc393a3561b94bc Mon Sep 17 00:00:00 2001 From: Jan Willamowius Date: Fri, 30 Sep 2005 08:22:45 +0000 Subject: [PATCH] allow allow numeric ranges for ports to ignore (patch by Alan Premselaar) --- .../Spong/Network/plugins/check_interfaces | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/lib/Spong/Network/plugins/check_interfaces b/src/lib/Spong/Network/plugins/check_interfaces index 865689f..a5e780a 100644 --- a/src/lib/Spong/Network/plugins/check_interfaces +++ b/src/lib/Spong/Network/plugins/check_interfaces @@ -103,28 +103,46 @@ sub check_interfaces { my $index; my $redcount = 0; foreach $index ( sort { $a <=> $b } keys %sifdesc) { - $message .= "interface $index status:\n"; - $message .= "\tifDescr: $sifdesc{$index}\n"; - $message .= "\tifType: $siftype{$index}\n"; - $message .= "\tifAdminStatus: $sifadminstatus{$index}\n"; - $message .= "\tifOperStatus: $sifoperstatus{$index}\n"; + my ($rstart,$rend) = (); + my $inrange = 0; # If interface is not up and is admin up, we got a problem if ($sifoperstatus{$index} != 1 && $sifadminstatus{$index} == 1) { my $skip = 0; if( @skipped_interfaces ) { foreach my $intf (@skipped_interfaces) { - if( $sifdesc{$index} eq $intf ) { - $skip = 1; last; + # handle ranges in interface to ignore value + if ($intf =~ /(\d+)-(\d+)/) { + $rstart = $1; + $rend = $2; + } + + ($inrange) = ( ($index >= $rstart) && ($index <= $rend) ) if (defined($rstart) && defined($rend)); + debug("$rstart - $rend [$index] ($inrange)"); + + if( ($sifdesc{$index} eq $intf) || ($index eq $intf) || ($inrange) ) { + $skip = 1; last; $inrange = 0; } } } $redcount++ unless $skip; + + if (!$skip) { + $message .= "interface $index status:\n"; + $message .= "\tifDescr: $sifdesc{$index}\n"; + $message .= "\tifType: $siftype{$index}\n"; + $message .= "\tifAdminStatus: $sifadminstatus{$index}\n"; + $message .= "\tifOperStatus: $sifoperstatus{$index}\n"; + } } } if ($redcount > 0) { $color = "red"; - $summary = "$redcount interfaces are down"; + if ($redcount == 1) { + $summary = "$redcount interface is down"; + } else { + $summary = "$redcount interfaces are down"; + } } else { $summary = "all interfaces up"; } @@ -201,7 +219,7 @@ See the L section for a detailed example. %HOSTS = ( 'hostname.my-inc.com' => { 'services' => 'interfaces', 'ip_addr' => ['192.168.13.123'], 'community' => 'local-read', - 'ignore_interfaces' => ['ppp1','ppp2']; + 'ignore_interfaces' => ['ppp1','ppp2', '5-7']; }, ); -- 2.30.2