Fixed bug when parsing filesystems that have no data on a given date.
[zfs-nexenta/.git] / zfs-log-parser
index 5c280032b97c63149c2411ca89e980aba24fc0d1..f3619dbe912fc5caf4e13184119905a8304a37c8 100755 (executable)
@@ -94,6 +94,7 @@ sub parse_snapshot_totals_logfile {
     $header="";
     while(<FILE>) {
        $line = $_;
+        if($line =~ /logfile turned over/) { next; }
        if(($in_totals == 0) && ($line =~ /(\S+)\s+(\S+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\S+)\s+(\S+)/)) {
            $dayname=$1; $month=$2; $daynum=$3; $hour=$4; $minute=$5; $sec=$6; $year=$8;
            $in_totals = 1;
@@ -103,12 +104,12 @@ sub parse_snapshot_totals_logfile {
            if(!defined $founddates{$date}) { $header .= $date . " "; }
            $founddates{$date} = 1;
        }
-       if(($in_totals == 1) && ($line =~ /^\s+$/)) {
+       elsif(($in_totals == 1) && ($line =~ /^\s+$/)) {
            $in_totals = 0;
        }
-       if(($in_totals == 1) && ($line =~ /(\S+)\s+([\d\.]+)(\w+)\s+(\d+)/)) {
+       elsif(($in_totals == 1) && ($line =~ /(\S+)\s+([\d\.]*)(\w+)\s+(\d+)/)) {
            $filesystem = $1; $data = $2; $size = $3; $num_snaps = $4;
-           if($filesystem =~ /Snapshots/) { next; }
+           if($filesystem =~ /Snapshots/ || $filesystem =~ /Total/) { next; }
            if($filesystem =~ /$backup_pool/) { next; }
            if(length($filesystem) > $maxlen) { $maxlen = length($filesystem); }
            if($size =~ /K/i) { $data = $data * $kilo; }
@@ -128,6 +129,7 @@ sub parse_snapshot_totals_logfile {
        foreach $date (sort keys %$hashref) {
            if($date !~ /(\d+)-(\d+)-(\d+)/) { next; }
            $date_data=adjust_data($totals{$filesystem}{$date}{data});
+            if($date_data eq "") { $date_data = "0"; }
            $data .= sprintf("%10s",$date_data). " ";
            $date_totals{$date}{data} += $totals{$filesystem}{$date}{data};
        }