diff --git a/lib/Site/ZpoolScrub.pm b/lib/Site/ZpoolScrub.pm index 86a3b36301fcddc9cadcf733d58a6f25be4c9b3a..3b3786fb7776ac64770c048b85c95aace92d4893 100644 --- a/lib/Site/ZpoolScrub.pm +++ b/lib/Site/ZpoolScrub.pm @@ -86,12 +86,51 @@ sub handler { my $oldhowlong = ( ( -r $statusfile ) ? `cat $statusfile` : 0 ); chomp $oldhowlong; $oldhowlong = 0 unless $oldhowlong =~ /^[\d]+$/; - my ($when,$days,$h,$m,$s,$howlong,$togo,$repaired,$errors,$canceled) - =(0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0); + my ($when,$days,$h,$m,$s,$howlong,$togo,$repaired,$errors,$canceled,$State,$Status,$Action) + =(0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0, '', '', ''); my $STATUSCMD = "/usr/sbin/zpool status $zpool"; open (my $status, "-|", $STATUSCMD)or die "can't run $STATUSCMD: $!"; - while (<$status>) { - if (/^\s*scan:\s+scrub\s+canceled\s+on\s+(.+)$/){ + LINE: while (<$status>) { +=pod + state: ONLINE +=cut + if(/^\s*state:\s(\S*)\s*$/) { + $State = $1 + } +=pod +status: One or more devices are faulted in response to persistent errors. + Sufficient replicas exist for the pool to continue functioning in a + degraded state. +action: Replace the faulted device, or use 'zpool clear' to mark the device + repaired. + - or - +status: One or more devices has experienced an unrecoverable error. An + attempt was made to correct the error. Applications are unaffected. +action: Determine if the device needs to be replaced, and clear the errors + using 'zpool clear' or replace the device with 'zpool replace'. +=cut + elsif (/^\s*status:\s+(.+)$/){ + $Status = $1; + while(<$status>) { + redo LINE if (/^\s*[a-z]*:/); + chomp; + $_ =~ s/\s+/ /g; + $Status .= $_; + } + } + elsif (/^\s*action:\s+(.+)$/){ + $Action = $1; + while(<$status>) { + redo LINE if (/^\s*[a-z]*:/); + chomp; + $_ =~ s/\s+/ /g; + $Action .= $_; + } + } +=pod + scan: scrub cancelled on Thu Mar 7 01:46:05 2019 +=cut + elsif (/^\s*scan:\s+scrub\s+canceled\s+on\s+(.+)$/){ $when = $1; $when = `$DATE '+%s'` - `$DATE '+%s' -d "$when"`; $when = int(($when+30)/60); @@ -178,12 +217,15 @@ sub handler { $howlong = $when + $togo } return { - "when" => [$when, "i"], - "howlong" => [$howlong, "i"], - "togo" => [$togo, "i"], - "repaired" => [$repaired, "i"], + "when" => [$when, "i"], + "howlong" => [$howlong, "i"], + "togo" => [$togo, "i"], + "repaired" => [$repaired,"i"], "errors" => [$errors, "i"], - "canceled" => [$canceled, "i"], + "canceled" => [$canceled,"i"], + "state" => [$State, "s"], + "status" => [$Status, "s"], + "action" => [$Action, "s"], } }