Imported Upstream version 3.3.3
[debian/amanda] / perl / Amanda / Report / human.pm
index b40890a3f438b32200ea182170066471c8bac205..a88cb2934a936c0e08665efc1bc72e492e3054ac 100644 (file)
@@ -1,8 +1,9 @@
-# Copyright (c) 2010 Zmanda, Inc.  All Rights Reserved.
+# Copyright (c) 2010-2012 Zmanda, Inc.  All Rights Reserved.
 #
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 as published
-# by the Free Software Foundation.
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
@@ -21,6 +22,7 @@ package Amanda::Report::human;
 
 use strict;
 use warnings;
+use Carp;
 
 use POSIX;
 use Data::Dumper;
@@ -313,7 +315,7 @@ sub print_human_amreport
     my ( $self, $fh ) = @_;
 
     $fh ||= $self->{fh}
-      || die "error: no file handle given to print_human_amreport\n";
+      || confess "error: no file handle given to print_human_amreport\n";
 
     ## collect statistics
     $self->calculate_stats();
@@ -396,7 +398,7 @@ sub output_tapeinfo
     my %incr_stats  = %{ $self->{incr_stats} };
     my %total_stats = %{ $self->{total_stats} };
 
-    if (@$tape_labels > 0) {
+    if (getconf($CNF_REPORT_USE_MEDIA) and @$tape_labels > 0) {
 
        # slightly different sentence depending on the run type
         my $tapelist_str;
@@ -457,47 +459,49 @@ sub output_tapeinfo
         }
     }
 
-    my $nb_new_tape = 0;
-    my $run_tapes   = getconf($CNF_RUNTAPES);
+    if (getconf($CNF_REPORT_NEXT_MEDIA)) {
+       my $nb_new_tape = 0;
+       my $run_tapes   = getconf($CNF_RUNTAPES);
 
-    if ($run_tapes) {
-        ($run_tapes > 1)
+       if ($run_tapes) {
+            ($run_tapes > 1)
           ? print $fh "The next $run_tapes tapes Amanda expects to use are: "
           : print $fh "The next tape Amanda expects to use is: ";
-    }
+       }
 
-    my $first = 1;
-    foreach my $i ( 0 .. ( $run_tapes - 1 ) ) {
+       my $first = 1;
+       foreach my $i ( 0 .. ( $run_tapes - 1 ) ) {
 
-        if ( my $tape_label =
-            Amanda::Tapelist::get_last_reusable_tape_label($i) ) {
+            if ( my $tape_label =
+               Amanda::Tapelist::get_last_reusable_tape_label($i) ) {
+
+               if ($nb_new_tape) {
+                   print $fh ", " if !$first;
+                   print $fh "$nb_new_tape new tape"
+                           . ( $nb_new_tape > 1 ? "s" : "" );
+                   $nb_new_tape = 0;
+                   $first = 0;
+               }
 
-           if ($nb_new_tape) {
-               print $fh ", " if !$first;
-               print $fh "$nb_new_tape new tape"
-                       . ( $nb_new_tape > 1 ? "s" : "" );
-               $nb_new_tape = 0;
+               print $fh
+                   $first ? "" : ", ",
+                   $tape_label;
                $first = 0;
-           }
+            } else {
+               $nb_new_tape++;
+            }
+       }
 
-           print $fh
-               $first ? "" : ", ",
-               $tape_label;
-           $first = 0;
-        } else {
-            $nb_new_tape++;
-        }
-    }
+       if ($nb_new_tape) {
+            print $fh ", " if !$first;
+            print $fh "$nb_new_tape new tape"
+              . ( $nb_new_tape > 1 ? "s" : "" );
+       }
+       print $fh ".\n";
 
-    if ($nb_new_tape) {
-        print $fh ", " if !$first;
-        print $fh "$nb_new_tape new tape"
-          . ( $nb_new_tape > 1 ? "s" : "" );
+       my $new_tapes = Amanda::Tapelist::list_new_tapes(getconf($CNF_RUNTAPES));
+       print $fh "$new_tapes\n" if $new_tapes;
     }
-    print $fh ".\n";
-
-    my $new_tapes = Amanda::Tapelist::list_new_tapes(getconf($CNF_RUNTAPES));
-    print $fh "$new_tapes\n" if $new_tapes;
 
     return;
 }
@@ -1046,6 +1050,7 @@ sub output_summary
     my $nodump_PARTIAL_format = get_summary_format($col_spec, 'nodump-PARTIAL', @summary_linedata);
     my $nodump_FAILED_format = get_summary_format($col_spec, 'nodump-FAILED', @summary_linedata);
     my $nodump_FLUSH_format = get_summary_format($col_spec, 'nodump-FLUSH', @summary_linedata);
+    my $nodump_NOT_FLUSHED_format = get_summary_format($col_spec, 'nodump-NOT FLUSHED', @summary_linedata);
     my $skipped_format = get_summary_format($col_spec, 'skipped', @summary_linedata);
 
     ## print the header names
@@ -1105,6 +1110,10 @@ sub output_summary
            print $fh sprintf($nodump_FAILED_format, @data);
        } elsif ($type eq 'nodump-FLUSH') {
            print $fh sprintf($nodump_FLUSH_format, @data);
+       } elsif ($type eq 'nodump-NOT FLUSHED') {
+debug("nodump_NOT_FLUSHED_format; $nodump_NOT_FLUSHED_format");
+debug("data: " . Data::Dumper::Dumper(\@data));
+           print $fh sprintf($nodump_NOT_FLUSHED_format, @data);
        } elsif ($type eq 'missing') {
            print $fh sprintf($missing_format, @data[0..2]);
        } elsif ($type eq 'noflush') {
@@ -1126,7 +1135,7 @@ sub output_summary
 ##  ('missing', host, disk, '' ..) # MISSING -----
 ##  ('noflush', host, disk, '' ..) # NO FILE TO FLUSH ------
 ##  ('nodump-$msg', host, disk, level, '', out, '--', '',
-##         '', tapetime, taperate, taperpartial)  # ... {FLUSH|FAILED|PARTIAL} ...
+##         '', tapetime, taperate, taperpartial)  # ... {FLUSH|NOT FLUSHED|FAILED|PARTIAL} ...
 ##  ('skipped', host, disk, '' ..) # SKIPPED -----
 ##
 ## the taperpartial column is not covered by the columnspec, and "hangs off"
@@ -1192,10 +1201,10 @@ sub get_summary_info
        push @rvs, [@rv];
     } elsif (keys %{$alldumps} == 0) {
        my @rv;
-       push @rv, $report->get_flag("amflush_run")? 'noflush' : 'missing';
+       push @rv, $report->get_flag("amflush_run")? 'nodump-NOT FLUSHED' : 'missing';
        push @rv, $hostname;
        push @rv, $disk_out;
-       push @rv, ("",) x 8;
+       push @rv, ("",) x 9;
        push @rvs, [@rv];
     }
 
@@ -1223,6 +1232,7 @@ sub get_summary_info
            if defined $dumper;
 
        my ( $out_size, $dump_time, $dump_rate, $tape_time, $tape_rate ) = (0) x 5;
+       my $tape_failure_from = '';
        my ($dumper_status) = "";
        my $saw_dumper = 0; # no dumper will mean this was a flush
        my $taper_partial = 0; # was the last taper run partial?
@@ -1242,6 +1252,7 @@ sub get_summary_info
                $out_size  = $try->{taper}{kb};
                $tape_time = $try->{taper}{sec};
                $tape_rate = $try->{taper}{kps};
+               $tape_failure_from = $try->{taper}{failure_from};
            } elsif ( exists $try->{taper}
                && ( $try->{taper}{status} eq "partial" ) ) {
 
@@ -1250,9 +1261,11 @@ sub get_summary_info
                $out_size  = $try->{taper}{kb};
                $tape_time = $try->{taper}{sec} if !$tape_time;
                $tape_rate = $try->{taper}{kps} if !$tape_rate;
+               $tape_failure_from = $try->{taper}{failure_from};
            } elsif (exists $try->{taper} && ( $try->{taper}{status} eq "fail")) {
                $tape_time = undef;
                $tape_rate = undef;
+               $tape_failure_from = $try->{taper}{failure_from};
            }
 
            if (!$out_size &&
@@ -1318,7 +1331,7 @@ sub get_summary_info
 
        my @rv;
 
-       if ( !$orig_size && !$out_size && (!defined($tape_time) || !$tape_time)) {
+       if ( !$orig_size && !$out_size && ((!defined($tape_time) || !$tape_time) && !defined($tape_failure_from))) {
            push @rv, $report->get_flag("amflush_run")? 'noflush' : 'missing';
            push @rv, $hostname;
            push @rv, $disk_out;
@@ -1333,20 +1346,27 @@ sub get_summary_info
            push @rv, $compression;
            push @rv, $dump_time ? $fmt_col_field->(6, mnsc($dump_time)) : "PARTIAL";
            push @rv, $dump_rate ? $fmt_col_field->(7, $dump_rate) : "";
-           push @rv, $fmt_col_field->(8,
+           if (defined $tape_failure_from and $tape_failure_from eq 'config') {
+               push @rv, $format_space->(8,"");
+               push @rv, $format_space->(9,"");
+           } else {
+               push @rv, $fmt_col_field->(8,
                    (defined $tape_time) ?
                            $tape_time ? mnsc($tape_time) : ""
                          : "FAILED");
-           push @rv, (defined $tape_rate) ?
-               $tape_rate ?
-                   $fmt_col_field->(9, $tape_rate)
-                 : $format_space->(9, "")
-             : $format_space->(9, "FAILED");
+               push @rv, (defined $tape_rate) ?
+                         $tape_rate ?
+                               $fmt_col_field->(9, $tape_rate)
+                             : $format_space->(9, "")
+                         : $format_space->(9, "FAILED");
+           }
            push @rv, $taper_partial? " PARTIAL" : ""; # column 10
        } else {
            my $message = $saw_dumper?
                            ($dumper_status eq 'failed') ? 'FAILED' : 'PARTIAL'
-                         : 'FLUSH';
+                         : (defined $tape_failure_from and
+                            $tape_failure_from eq 'config') ? 'NOT FLUSHED'
+                                                            : 'FLUSH';
            push @rv, "nodump-$message";
            push @rv, $hostname;
            push @rv, $disk_out;
@@ -1356,15 +1376,21 @@ sub get_summary_info
            push @rv, $compression;
            push @rv, '';
            push @rv, '';
-           push @rv, $fmt_col_field->(8,
-                   (defined $tape_time) ?
-                           $tape_time ? mnsc($tape_time) : ""
-                         : "FAILED");
-           push @rv, (defined $tape_rate) ?
-               $tape_rate ?
-                   $fmt_col_field->(9, $tape_rate)
-                 : $format_space->(9, "")
-             : $format_space->(9, "FAILED");
+           if (defined $tape_failure_from and $tape_failure_from eq 'config') {
+               push @rv, $format_space->(8,"");
+               push @rv, $format_space->(9,"");
+               next if !$report->get_flag("amflush_run"); # do not print a line for flush with config error
+           } else {
+              push @rv, $fmt_col_field->(8,
+                      (defined $tape_time) ?
+                              $tape_time ? mnsc($tape_time) : ""
+                            : "FAILED");
+              push @rv, (defined $tape_rate) ?
+                  $tape_rate ?
+                      $fmt_col_field->(9, $tape_rate)
+                    : $format_space->(9, "")
+                : $format_space->(9, "FAILED");
+           }
            push @rv, $taper_partial? " PARTIAL" : "";
        }
        push @rvs, [@rv];
@@ -1510,9 +1536,9 @@ sub set_col_spec
     my $disp_unit = $self->{disp_unit};
 
     $self->{col_spec} = [
-        [ "HostName", 0, 12, 12, 0, "%-*.*s", "HOSTNAME" ],
-        [ "Disk",     1, 11, 11, 0, "%-*.*s", "DISK" ],
-        [ "Level",    1, 1,  1,  0, "%*.*d",  "L" ],
+        [ "HostName", 0, 12, 12, 1, "%-*.*s", "HOSTNAME" ],
+        [ "Disk",     1, 11, 11, 1, "%-*.*s", "DISK" ],
+        [ "Level",    1, 1,  1,  1, "%*.*d",  "L" ],
         [ "OrigKB",   1, 7,  0,  1, "%*.*f",  "ORIG-" . $disp_unit . "B" ],
         [ "OutKB",    1, 7,  0,  1, "%*.*f",  "OUT-" . $disp_unit . "B" ],
         [ "Compress", 1, 6,  1,  1, "%*.*f",  "COMP%" ],
@@ -1531,11 +1557,10 @@ sub apply_col_spec_override
     my ($self) = @_;
     my $col_spec = $self->{col_spec};
 
-    my %col_spec_override = read_col_spec_override();
+    my %col_spec_override = $self->read_col_spec_override();
 
     foreach my $col (@$col_spec) {
         if ( my $col_override = $col_spec_override{ $col->[COLSPEC_NAME] } ) {
-
             my $override_col_val_if_def = sub {
                 my ( $field, $or_num ) = @_;
                 if ( defined $col_override->[$or_num]
@@ -1554,22 +1579,36 @@ sub apply_col_spec_override
 
 sub read_col_spec_override
 {
-    ## takes no arguments
+    my ($self) = @_;
+
     my $col_spec_str = getconf($CNF_COLUMNSPEC) || return;
     my %col_spec_override = ();
+    my $col_spec = $self->{col_spec};
 
     foreach (split(",", $col_spec_str)) {
 
         $_ =~ m/^(\w+)           # field name
                 =([-:\d]+)       # field values
                 $/x
-          or die "error: malformed columnspec string:$col_spec_str";
+          or confess "error: malformed columnspec string:$col_spec_str";
 
         my $field = $1;
+       my $found = 0;
+
+       foreach my $col (@$col_spec) {
+           if (lc $field eq lc $col->[0]) {
+               $field = $col->[0];
+               $found = 1;
+           }
+       }
+       if ($found == 0) {
+           die("Invalid field name: $field");
+       }
+
         my @field_values = split ':', $2;
 
         # too many values
-        die "error: malformed columnspec string:$col_spec_str"
+        confess "error: malformed columnspec string:$col_spec_str"
           if (@field_values > 3);
 
         # all values *should* be in the right place.  If not enough