From cfc80e70015e08eae7f2c1686fbe91828f805db4 Mon Sep 17 00:00:00 2001 From: Christian Ospelkaus Date: Sat, 12 Jan 2013 19:28:41 -0800 Subject: [PATCH] Support filtering volumes of interest with a regex When using the -H option, support filtering the volumes being checked on through the new -r option. --- check_afs_quotas | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/check_afs_quotas b/check_afs_quotas index ab7ac64..7c775ea 100755 --- a/check_afs_quotas +++ b/check_afs_quotas @@ -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 () { 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 [B<-hV>] [B<-c> I] [B<-w> I] [B<-t> I] (B<-H> I [B<-p> I] | B<-n> I) + [B<-r> I] =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 or C doesn't return within the timeout, B will return a critical error. The default timeout is @@ -319,6 +326,11 @@ Print out the version of B and quit. Change the warning percentage threshold to I, which should be an integer percentage. The default is 85. +=item B<-r> I + +When processing an entire server (B<-H>), filter the volumes considered +by I + =back =head1 EXIT STATUS -- 2.39.5