]> git.michaelhowe.org Git - packages/a/afs-monitor.git/commitdiff
Single partition checking and formatted sizes in check_afsspace
authorRuss Allbery <rra@stanford.edu>
Wed, 20 Oct 2010 17:13:45 +0000 (10:13 -0700)
committerRuss Allbery <rra@stanford.edu>
Wed, 20 Oct 2010 17:14:26 +0000 (10:14 -0700)
Support checking a single partition in check_afsspace and print more
verbose information about total, used, and free space in that mode.
Format partition sizes using Number::Format if available.  Based on
work by Steve Rader.

NEWS
README
check_afsspace

diff --git a/NEWS b/NEWS
index 6a32c084ee4de7bca6dbd0f90be76f3b534a02c2..b2e9d7ba3f603ead2824853bc03fca5bbee767ce 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,11 @@ afs-monitor 2.0 (unreleased)
     Initial tarball release, based on check_afsspace 1.16, check_bos 1.7,
     check_rxdebug 1.11, and check_udebug 1.3.
 
+    Support checking a single partition in check_afsspace and print more
+    verbose information about total, used, and free space in that mode.
+    Format partition sizes using Number::Format if available.  Based on
+    work by Steve Rader.
+
     If the salvager is running (such as when started manually with bos
     salvage), check_bos now reports a warning stating that, rather than a
     critical error showing the auxiliary status line.  Reported by Steve
diff --git a/README b/README
index 08aea05d046ce3b37b5ca88a87857a37b6c4c7ac..00df0ec7606476a7743dbcbaec640565cd8a21ee 100644 (file)
--- a/README
+++ b/README
@@ -65,6 +65,9 @@ REQUIREMENTS
   bos, rxdebug, and udebug) and expect them to be in either /usr/bin or in
   /usr/local/bin.
 
+  check_afsspace will use Number::Format, if available, to format sizes
+  with IEC 60027 prefixes.
+
 INSTALLATION
 
   All that's required for installation is to copy the check_* scripts into
index 29da098cc3d77c6893299ad0de074c7b6fc66179..091cf5083a476b25e362f783a8fc9099e64b6c7b 100755 (executable)
@@ -25,6 +25,16 @@ use strict;
 
 use Getopt::Long qw(GetOptions);
 
+# Use Number::Format if it's available, but don't require it.
+our $FORMAT = 0;
+eval {
+    require Number::Format;
+    Number::Format->import ('format_bytes');
+};
+unless ($@) {
+    $FORMAT = 1;
+}
+
 ##############################################################################
 # Site configuration
 ##############################################################################
@@ -56,14 +66,15 @@ sub syntax {
 }
 
 # Parse command line options.
-my ($help, $host, $version);
+my ($help, $host, $partition, $version);
 Getopt::Long::config ('bundling', 'no_ignore_case');
-GetOptions ('c|critical=i' => \$CRITICAL,
-            'H|hostname=s' => \$host,
-            'h|help'       => \$help,
-            't|timeout=i'  => \$TIMEOUT,
-            'V|version'    => \$version,
-            'w|warning=i'  => \$WARNINGS)
+GetOptions ('c|critical=i'  => \$CRITICAL,
+            'H|hostname=s'  => \$host,
+            'h|help'        => \$help,
+            'p|partition=s' => \$partition,
+            't|timeout=i'   => \$TIMEOUT,
+            'V|version'     => \$version,
+            'w|warning=i'   => \$WARNINGS)
     or syntax ("invalid option");
 if ($help) {
     print "Feeding myself to perldoc, please wait....\n";
@@ -78,6 +89,10 @@ syntax ("host to check not specified") unless (defined $host);
 if ($WARNINGS > $CRITICAL) {
     syntax ("warning level $WARNINGS greater than critical level $CRITICAL");
 }
+if ($partition) {
+    $partition = "/vicep$partition" if length ($partition) <= 2;
+    $partition = "/$partition" if $partition !~ m%^/%;
+}
 
 # Set up the alarm.
 $SIG{ALRM} = sub {
@@ -90,20 +105,45 @@ alarm ($TIMEOUT);
 # partition.  Accumulate critical messages in @critical and warnings in
 # @warnings.  Accumulate all percentages in @all.
 my (@critical, @warnings, @all);
-my @data = `$VOS partinfo '$host' 2> /dev/null`;
+my $command = "$VOS partinfo -server '$host'";
+$command .= " -partition $partition" if defined ($partition);
+my @data = `$command 2> /dev/null`;
 if ($? != 0) {
     print "AFS CRITICAL - cannot contact server\n";
     exit 2;
 }
+$partition .= ':';
 for (@data) {
-    my ($partition, $free, $total) = (split)[4,5,11];
+    my ($part, $free, $total) = (split)[4,5,11];
+    next if (defined ($partition) and $part ne $partition);
     my $percent = int ((($total - $free) / $total) * 100);
+    my $used = $total - $free;
+    if ($FORMAT) {
+        $total = format_bytes ($total, mode => 'iec');
+        $free  = format_bytes ($free,  mode => 'iec');
+        $used  = format_bytes ($used,  mode => 'iec');
+    }
+    my $summary;
+    if ($partition) {
+        $summary = "$part$percent% used"
+            . " ($total total, $used used, $free free)";
+    } else {
+        $summary = "$part$percent% (free $free)";
+    }
     if ($percent >= $CRITICAL) {
-        push (@critical, "$partition$percent% (free $free)");
+        push (@critical, $summary);
     } elsif ($percent >= $WARNINGS) {
-        push (@warnings, "$partition$percent% (free $free)");
+        push (@warnings, $summary);
     }
-    push (@all, "$partition$percent%");
+    if ($partition) {
+        push (@all, $summary);
+    } else {
+        push (@all, "$part$percent%");
+    }
+}
+unless (@all) {
+    print "AFS CRITICAL - no partition found\n";
+    exit 2;
 }
 
 # Exit with the appropriate error messages.
@@ -129,7 +169,7 @@ check_afsspace - Monitor AFS disk space usage under Nagios
 =head1 SYNOPSIS
 
 B<check_afsspace> [B<-hV>] [B<-c> I<threshold>] [B<-w> I<threshold>]
-    [B<-t> I<timeout>] B<-H> I<host>
+    [B<-p> I<partition>] [B<-t> I<timeout>] B<-H> I<host>
 
 =head1 DESCRIPTION
 
@@ -149,6 +189,10 @@ the critical errors if any, otherwise giving the warnings if any,
 otherwise listing in an abbreviated form the percentage free space for all
 partitions.
 
+The check can be limited to a single partition by specifying that
+partition with the B<-p> option.  In this case, more verbose information
+about the total, used, and free space is given in the one line of output.
+
 =head1 OPTIONS
 
 =over 4
@@ -168,6 +212,14 @@ option is required.
 Print out this documentation (which is done simply by feeding the script
 to C<perldoc -t>).
 
+=item B<-p> I<partition>, B<--partition>=I<partition>
+
+Limit the results to the specified partition.  The partition can be given
+as the partition letter (C<a>, for example) or the full partition name
+(C</vicepa>), with or without the leading slash.  If this option is given,
+only that partition will be checked and more verbose information about
+total, used, and free space will be printed.
+
 =item B<-t> I<timeout>, B<--timeout>=I<timeout>
 
 Change the timeout for the C<vos partinfo> command.  The default timeout
@@ -223,7 +275,8 @@ tools page at L<http://www.eyrie.org/~eagle/software/afs-monitor/>.
 Originally written by Susan Feng for use with mon.  Updated by Quanah
 Gibson-Mount to work with Nagios, and then further updated by Russ Allbery
 <rra@stanford.edu> to support more standard options and to use a more
-uniform coding style.
+uniform coding style.  Support for checking a single partition based on
+work by Steve Rader.
 
 =head1 COPYRIGHT AND LICENSE