From b49adcf8cf80a1afa185b81429bfdb227dc16ffb Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Sat, 12 Jan 2013 19:39:13 -0800 Subject: [PATCH] Coding style and NEWS for the volume regular expression filter --- NEWS | 4 ++++ check_afs_quotas | 31 +++++++++++++++++-------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/NEWS b/NEWS index 66cedee..f3976ac 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,10 @@ afs-monitor 2.4 (unreleased) + Support filtering the volumes considered on a particular server by a + regular expression in check_afs_quotas. The regular expression is + specified with a new -r option. Patch from Christian Ospelkaus. + Also ignore bos status output from long-running scheduled jobs, such as AFS backups. Patch from Georg Sluyterman. diff --git a/check_afs_quotas b/check_afs_quotas index 7c775ea..03ea40a 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, $volreg) = @_; + my ($server, $partition, $regex) = @_; my @command = ($VOS, 'listvol', '-server', $server, '-long', '-noauth'); if (defined ($partition)) { push (@command, '-partition', $partition); @@ -104,16 +104,17 @@ sub serverinfo { local $_; while () { if (/^(\S+)\s+\d+ RW\s+(\d+) K\s+On-line\s*$/) { - $volume=$1; - $size=$2; - if (!defined($volreg)||($1 =~ m/($volreg)/)) { + ($volume, $size) = ($1, $2); + if (!defined ($regex) || $volume =~ /$regex/) { $results{$volume}{size} = $size; } else { $volume = undef; } - } elsif (/^\s+MaxQuota\s+(\d+) K\s*$/ && defined($volume)) { + } elsif (/^\s+MaxQuota\s+(\d+) K\s*$/ && defined $volume) { $results{$volume}{quota} = $1; $volume = undef; + } elsif (/^\s*$/) { # next volume + $volume = undef; } } return %results; @@ -160,13 +161,13 @@ sub syntax { } # Parse command line options. -my ($help, $host, $partition, $version, $volume, $volreg); +my ($help, $host, $partition, $regex, $version, $volume); 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, + 'r|regex=s' => \$regex, 'p|partition=s' => \$partition, 't|timeout=i' => \$TIMEOUT, 'V|version' => \$version, @@ -183,6 +184,8 @@ if ($help) { syntax ("extra arguments on command line") if @ARGV; syntax ("host or volume to check not specified") unless (defined ($host) || defined ($volume)); +syntax ("regex specified without host to check") + if (defined ($regex) && !defined ($host)); if ($WARNINGS > $CRITICAL) { syntax ("warning level $WARNINGS greater than critical level $CRITICAL"); } @@ -213,7 +216,7 @@ if (defined ($volume)) { exit 0; } } else { - my %results = serverinfo ($host, $partition, $volreg); + my %results = serverinfo ($host, $partition, $regex); my (@ok, @warning, @critical); for my $volume (keys %results) { my ($percent, $summary) @@ -269,7 +272,7 @@ 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>. When checking an entire server, the +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, @@ -312,6 +315,11 @@ particular partition. The partition can be given in any of the forms recognized by the AFS tools (so both the partition letter C and the full partition name C will work). +=item B<-r> I + +When processing an entire server (B<-H>), ignore any volumes that don't +match the specified Perl regular expression. + =item B<-t> I, B<--timeout>=I Change the timeout for the C command. The default timeout @@ -326,11 +334,6 @@ 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