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

dmichelsen at users.sourceforge.net dmichelsen at users.sourceforge.net
Tue Feb 19 13:25:00 CET 2013


Revision: 656
          http://opencsw.svn.sourceforge.net/opencsw/?rev=656&view=rev
Author:   dmichelsen
Date:     2013-02-19 12:24:59 +0000 (Tue, 19 Feb 2013)
Log Message:
-----------
check-zpool: Add highlevel duration, cleanup

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

Modified: mirror/check-zpool
===================================================================
--- mirror/check-zpool	2013-02-19 09:35:35 UTC (rev 655)
+++ mirror/check-zpool	2013-02-19 12:24:59 UTC (rev 656)
@@ -25,6 +25,17 @@
 # -d <scrub duration in hours>
 # -D <days since last scrub>
 
+sub time_duration2timedate_duration {
+  my ($dur) = shift @_;
+
+  my $sec = $dur % 60;	$dur = int( $dur / 60 );
+  my $min = $dur % 60;	$dur = int( $dur / 60 );
+  my $hour = $dur % 24;	$dur = int( $dur / 24 );
+  my $day = $dur % 7;	$dur = int( $dur / 7 );
+  my $week = $dur;
+  return DateTime::Duration->new( weeks => $week, days => $day, hours => $hour, minutes => $min, seconds => $sec );
+}
+
 package ZFS::Pool;
 
 use strict;
@@ -67,12 +78,14 @@
 
 sub scrub_in_progress {
   my ($this) = @_;
-  # scan: scrub in progress since Tue Feb  5 16:15:54 2013
   my $scan = $this->{status}->{scan};
+
+  # scan: scrub in progress since Tue Feb  5 16:15:54 2013
   my $since;
   if( $scan =~ /scrub in progress since (.*)$/m ) {
     $since = DateTime::Format::DateParse->parse_datetime( $1 );
   }
+
   return $since;
 }
 
@@ -170,12 +183,11 @@
       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
+          . ' which is longer than ' . $fmt->format_duration( time_duration2timedate_duration( $sd ), significant_units => 2 )
         );
       }
-    } else {
-      push @status, "pool '$poolname' is scrubbing for " . $scrub_duration;
     }
+    push @status, "pool '$poolname' is scrubbing for " . $scrub_duration;
   }
 
   # Warn if last scrub finished more -A <duration> ago
@@ -186,21 +198,16 @@
       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
+          . ' ago which is older than ' . $fmt->format_duration( time_duration2timedate_duration( $sa ), significant_units => 2 )
         );
       }
-    } else {
-      push @status, "pool '$poolname' was scrubbed $no_scrub_since ago";
     }
+    push @status, "pool '$poolname' was scrubbed $no_scrub_since ago";
   } else {
-    if( $sa ) {
-      if( $since ) {
-        push @status, "pool '$poolname' is scrubbed for the first time for $scrub_duration";
-      } else {
-        $np->nagios_exit( WARNING, "Scrub for the pool '$poolname' was never run"
-          . ' but must not be older than ' . $sat
-        );
-      }
+    if( !$since ) {
+      $np->nagios_exit( WARNING, "Scrub for the pool '$poolname' was never run"
+        . ' but must not be older than ' . $fmt->format_duration( time_duration2timedate_duration( $sa ), significant_units => 2 )
+      );
     }
   }
 
@@ -213,7 +220,7 @@
   # 4. warn if status is at least degraded, critical if faulted
   my $state = $p->state;
   if( $state eq 'ONLINE' ) {
-    # ok
+    # Ok
   } elsif( $state eq 'FAULTED' ) {
     $np->nagios_exit( CRITICAL, "State of the pool '$poolname' is FAULTED" );
   } elsif( $state eq 'DEGRADED' ) {
@@ -226,29 +233,3 @@
 
 $np->nagios_exit( OK, 'Pool status ' . join( ', ', @status ) );
 
-
-__END__
-# scan: scrub in progress since Tue Feb  5 16:15:54 2013
-my $scrub = $status{'scan'};
-if( $scrub =~ /scrub in progress since (.*)$/m ) {
-  #  scan: scrub in progress since Tue Feb  5 16:15:54 2013
-  #     58.5K repaired, 46.54% done
-  my $since = DateTime::Format::DateParse->parse_datetime( $1 );
-  my $howlong = DateTime->now - $since;
-  my ( $days, $hours, $minutes ) = $howlong->in_units('days','hours', 'minutes');
-  $hours += $days * 24;
-  my ($done) = ($scrub =~ / (\S+)% done/);
-  print "Scrub since ", sprintf( "%d:%02d", ${hours}, ${minutes} ), " hours, $done % done\n";
-} elsif( $scrub =~ /none requested/ ) {
-  # scan: none requested
-  print "No scrub\n";
-} elsif( $scrub =~ /scrub repaired (\d+) in (\S+) with (\d+) errors on (.*)/ ) {
-  # scan: scrub repaired 0 in 5h21m with 0 errors on Mon Nov  5 21:18:23 2012
-  my ($repairs, $scrubtime, $errors, $finished) = ($1, $2, $3, $4);
-  my $lastfinished = DateTime::Format::DateParse->parse_datetime( $finished );
-  my $days = DateTime->now->delta_days( $lastfinished );
-  print "Last scrub was ", $days->in_units( 'days' ), " days ago\n";
-} else {
-  print "Could not parse scan status:\n";
-  print $scrub;
-}

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