]> git.michaelhowe.org Git - packages/a/afs-monitor.git/commitdiff
Support filtering volumes of interest with a regex
authorChristian Ospelkaus <christian.ospelkaus@iqo.uni-hannover.de>
Sun, 13 Jan 2013 03:28:41 +0000 (19:28 -0800)
committerRuss Allbery <rra@stanford.edu>
Sun, 13 Jan 2013 03:28:41 +0000 (19:28 -0800)
When using the -H <hostname> option, support filtering the volumes
being checked on <hostname> through the new -r <regex> option.

check_afs_quotas

index ab7ac64e267481ede3add4fd4f2927bb1e7e2439..7c775ea2e3c8243863cece8a7f1077db745df70d 100755 (executable)
@@ -91,7 +91,7 @@ sub volinfo {
 # in a hash where the keys are volume names and the values are hashes
 # containing 'size' and 'quota' keys and values in KB.
 sub serverinfo {
-    my ($server, $partition) = @_;
+    my ($server, $partition, $volreg) = @_;
     my @command = ($VOS, 'listvol', '-server', $server, '-long', '-noauth');
     if (defined ($partition)) {
         push (@command, '-partition', $partition);
@@ -100,15 +100,19 @@ sub serverinfo {
         print "AFS CRITICAL - cannot contact server\n";
         exit 2;
     }
-    my ($volume, %results);
+    my ($volume, $size, %results);
     local $_;
     while (<LVOL>) {
         if (/^(\S+)\s+\d+ RW\s+(\d+) K\s+On-line\s*$/) {
-            $volume = $1;
-            $results{$volume}{size} = $2;
-        } elsif (/^\s+MaxQuota\s+(\d+) K\s*$/) {
-            $results{$volume}{quota} = $1 if defined $volume;
-        } elsif (/^\s*$/) { # next volume
+            $volume=$1;
+            $size=$2;
+            if (!defined($volreg)||($1 =~ m/($volreg)/)) {
+                $results{$volume}{size} = $size;
+            } else {
+                $volume = undef;
+            }
+        } elsif (/^\s+MaxQuota\s+(\d+) K\s*$/ && defined($volume)) {
+            $results{$volume}{quota} = $1;
             $volume = undef;
         }
     }
@@ -156,12 +160,13 @@ sub syntax {
 }
 
 # Parse command line options.
-my ($help, $host, $partition, $version, $volume);
+my ($help, $host, $partition, $version, $volume, $volreg);
 Getopt::Long::config ('bundling', 'no_ignore_case');
 GetOptions ('c|critical=i'  => \$CRITICAL,
             'H|hostname=s'  => \$host,
             'h|help'        => \$help,
             'n|volume=s'    => \$volume,
+            'r|volreg=s'    => \$volreg,
             'p|partition=s' => \$partition,
             't|timeout=i'   => \$TIMEOUT,
             'V|version'     => \$version,
@@ -208,7 +213,7 @@ if (defined ($volume)) {
         exit 0;
     }
 } else {
-    my %results = serverinfo ($host, $partition);
+    my %results = serverinfo ($host, $partition, $volreg);
     my (@ok, @warning, @critical);
     for my $volume (keys %results) {
         my ($percent, $summary)
@@ -249,6 +254,7 @@ check_afs_quotas - Monitor AFS quota usage under Nagios
 
 B<check_afs_quotas> [B<-hV>] [B<-c> I<threshold>] [B<-w> I<threshold>]
     [B<-t> I<timeout>] (B<-H> I<host> [B<-p> I<partition>] | B<-n> I<volume>)
+    [B<-r> I<regex>]
 
 =head1 DESCRIPTION
 
@@ -263,7 +269,8 @@ a warning if it is over 85% (changeable with the B<-c> and B<-w> options).
 To check a single volume, specify the volume name with B<-n>.  To check a
 whole server, specify the server name with B<-H>.  You can check only a
 single partition on a server by using the B<-p> option to name the
-partition in combination with B<-H>.
+partition in combination with B<-H>. When checking an entire server, the 
+volumes checked can be filtered by using a regular expression (B<-r>).
 
 If C<vos examine> or C<vos listvol> doesn't return within the timeout,
 B<check_afs_quotas> will return a critical error.  The default timeout is
@@ -319,6 +326,11 @@ Print out the version of B<check_afs_quotas> and quit.
 Change the warning percentage threshold to I<threshold>, which should be
 an integer percentage.  The default is 85.
 
+=item B<-r> I<regex>
+
+When processing an entire server (B<-H>), filter the volumes considered
+by I<regex>
+
 =back
 
 =head1 EXIT STATUS