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

dmichelsen at users.sourceforge.net dmichelsen at users.sourceforge.net
Tue Feb 19 15:57:27 CET 2013


Revision: 657
          http://opencsw.svn.sourceforge.net/opencsw/?rev=657&view=rev
Author:   dmichelsen
Date:     2013-02-19 14:57:26 +0000 (Tue, 19 Feb 2013)
Log Message:
-----------
check-zpool: Move to DateTime::Format::Duration::DurationString

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

Modified: mirror/check-zpool
===================================================================
--- mirror/check-zpool	2013-02-19 12:24:59 UTC (rev 656)
+++ mirror/check-zpool	2013-02-19 14:57:26 UTC (rev 657)
@@ -1,17 +1,15 @@
 #!/opt/csw/bin/perl
 
 # The following packages are needed to run this check:
-#   CSWpm-time-duration-parse CSWpm-datetime-format-dateparse CSWpm-nagios-plugin
+#   CSWpm-datetime-format-dateparse CSWpm-datetime-format-human-dur CSWpm-mouse CSWpm-datetime-format-dur-durstr CSWpm-nagios-plugin
 
 use strict;
 use warnings;
-use Time::Duration::Parse;
 use DateTime::Format::DateParse;
 use DateTime::Format::Human::Duration;
+use DateTime::Format::Duration::DurationString;
 use Nagios::Plugin;
 
-use Data::Dumper;
-
 # Pass:
 # - Name of pool
 
@@ -25,17 +23,6 @@
 # -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;
@@ -158,13 +145,13 @@
 my $sdt = $np->opts->get('warn-scrub-duration');
 my $sd;
 if( $sdt ) {
-  $sd = parse_duration( $sdt );
+  $sd = DateTime::Format::Duration::DurationString->new()->parse( $sdt )->to_duration;
 }
 
 my $sat = $np->opts->get('warn-scrub-age');
 my $sa;
 if( $sat ) {
-  $sa = parse_duration( $sat );
+  $sa = DateTime::Format::Duration::DurationString->new()->parse( $sat )->to_duration;
 }
 
 my $fmt = DateTime::Format::Human::Duration->new();
@@ -180,10 +167,10 @@
   if( $since ) {
     $scrub_duration = $fmt->format_duration( DateTime->now->subtract_datetime( $since ), significant_units => 2 );
     if( $sd ) {
-      my $should_have_finished = $since->clone()->add( seconds => $sd );
+      my $should_have_finished = $since->clone()->add_duration( $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 ' . $fmt->format_duration( time_duration2timedate_duration( $sd ), significant_units => 2 )
+          . ' which is longer than ' . $fmt->format_duration( $sd, significant_units => 2 )
         );
       }
     }
@@ -195,10 +182,10 @@
   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 );
+      my $should_have_scrubbed = $last->clone()->add_duration( $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 ' . $fmt->format_duration( time_duration2timedate_duration( $sa ), significant_units => 2 )
+          . ' ago which is older than ' . $fmt->format_duration( $sa, significant_units => 2 )
         );
       }
     }
@@ -206,7 +193,7 @@
   } else {
     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 )
+        . ' but must not be older than ' . $fmt->format_duration( $sa, significant_units => 2 )
       );
     }
   }

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