]> git.etc.gen.nz Git - spong.git/commitdiff
allow allow numeric ranges for ports to ignore (patch by Alan Premselaar)
authorJan Willamowius <jan@willamowius.de>
Fri, 30 Sep 2005 08:22:45 +0000 (08:22 +0000)
committerJan Willamowius <jan@willamowius.de>
Fri, 30 Sep 2005 08:22:45 +0000 (08:22 +0000)
src/lib/Spong/Network/plugins/check_interfaces

index 865689f8b82cf60444f08814ff39acde6cc46c29..a5e780a4624e59ac4f10c8af6aaaee00146208c7 100644 (file)
@@ -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<Examples|"EXAMPLES"> 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'];
                                        },
             );