[csw-devel] SF.net SVN: opencsw:[653] mirror/check-zpool

dmichelsen at users.sourceforge.net dmichelsen at users.sourceforge.net
Mon Feb 18 11:01:24 CET 2013


Revision: 653
          http://opencsw.svn.sourceforge.net/opencsw/?rev=653&view=rev
Author:   dmichelsen
Date:     2013-02-18 10:01:23 +0000 (Mon, 18 Feb 2013)
Log Message:
-----------
check-zpool: Enhance status output

Modified Paths:
--------------
    mirror/check-zpool

Modified: mirror/check-zpool
===================================================================
--- mirror/check-zpool	2013-02-12 13:02:33 UTC (rev 652)
+++ mirror/check-zpool	2013-02-18 10:01:23 UTC (rev 653)
@@ -156,28 +156,40 @@
 
 my $fmt = DateTime::Format::Human::Duration->new();
 
+my @status;
+
 foreach my $poolname (@pools) {
   my $p = ZFS::Pool->new( pool => $poolname );
 
   # Warn if scrub takes longer then -D <duration>
   my $since = $p->scrub_in_progress;
-  if( $sd && $since ) {
-    my $should_have_finished = $since->clone()->add( seconds => $sd );
-    if( DateTime->compare( DateTime->now, $should_have_finished ) > 0 ) {
-      $np->nagios_exit( WARNING, "Scrub is running for the pool '$poolname' for "
-        . $fmt->format_duration( DateTime->now->subtract_datetime( $since ), significant_units => 2 ) . ' which is longer than ' . $sdt
-      );
+  if( $since ) {
+    my $scrub_duration = $fmt->format_duration( DateTime->now->subtract_datetime( $since ), significant_units => 2 );
+    if( $sd ) {
+      my $should_have_finished = $since->clone()->add( seconds => $sd );
+      if( DateTime->compare( DateTime->now, $should_have_finished ) > 0 ) {
+        $np->nagios_exit( WARNING, "Scrub is running for the pool '$poolname' for " . $scrub_duration
+          . ' which is longer than ' . $sdt
+        );
+      }
+    } else {
+      push @status, "pool '$poolname' is scrubbing for " . $scrub_duration;
     }
   }
 
   # Warn if last scrub finished more -A <duration> ago
   my $last = $p->last_scrub;
-  if( $sa && $last ) {
-    my $should_have_scrubbed = $last->clone()->add( seconds => $sa );
-    if( $sa && $last && DateTime->compare( DateTime->now, $should_have_scrubbed ) > 0 ) {
-      $np->nagios_exit( WARNING, "Scrub for the pool '$poolname' was run "
-        . $fmt->format_duration( DateTime->now->subtract_datetime( $last ), significant_units => 2 ) . ' ago which is older than ' . $sat
-      );
+  if( $last ) {
+    my $no_scrub_since = $fmt->format_duration( DateTime->now->subtract_datetime( $last ), significant_units => 2 );
+    if( $sa ) {
+      my $should_have_scrubbed = $last->clone()->add( seconds => $sa );
+      if( $sa && $last && DateTime->compare( DateTime->now, $should_have_scrubbed ) > 0 ) {
+        $np->nagios_exit( WARNING, "Scrub for the pool '$poolname' was run " . $no_scrub_since
+          . ' ago which is older than ' . $sat
+        );
+      }
+    } else {
+      push @status, "pool '$poolname' was scrubbed $no_scrub_since ago";
     }
   }
 
@@ -199,12 +211,9 @@
     # State is UNKNOWN or... who knows?
     $np->nagios_exit( WARNING, "State of the pool '$poolname' is $state" );
   }
-
-#  print "Last: ", $last || 'undef', ' ', ($last ? DateTime->now->delta_days( $last)->in_units( 'days' ) : ''), "\n";
-#  print "State: ", $p->state, "\n";
 }
 
-$np->nagios_exit( OK, 'Pool status ' . join( ', ', @pools ) . ' is ok' );
+$np->nagios_exit( OK, 'Pool status ' . join( ', ', @status ) );
 
 
 __END__

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the devel mailing list