]> git.proxmox.com Git - pve-manager.git/commitdiff
fix #5067: vzdump: include total backup size in notification
authorLukas Wagner <l.wagner@proxmox.com>
Thu, 14 Dec 2023 14:11:53 +0000 (15:11 +0100)
committerFiona Ebner <f.ebner@proxmox.com>
Mon, 29 Jan 2024 09:31:52 +0000 (10:31 +0100)
The old backup job notification mails from before the notification
system overhaul included the total time as well as the total size.

The total size was missing from the new, template-based backup report,
thus we add it back in this commit.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
[FE: style fix - use parentheses for returning list]
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
PVE/VZDump.pm

index 4185ed6253ca497c241a912a3f6f31416da6dbe9..1c81c82ebb752aed43f51877f23414bf15775774 100644 (file)
@@ -414,15 +414,17 @@ sub sanitize_task_list {
     }
 }
 
-sub count_failed_tasks {
+my sub aggregate_task_statistics {
     my ($tasklist) = @_;
 
     my $error_count = 0;
+    my $total_size = 0;
     for my $task (@$tasklist) {
        $error_count++ if $task->{state} ne 'ok';
+       $total_size += $task->{size} if $task->{state} eq 'ok';
     }
 
-    return $error_count;
+    return ($error_count, $total_size);
 }
 
 sub get_hostname {
@@ -437,9 +439,10 @@ my $body_template = <<EOT;
 {{error-message}}
 {{heading-1 "Details"}}
 {{table guest-table}}
-
+{{#verbatim}}
 Total running time: {{duration total-time}}
-
+Total size: {{human-bytes total-size}}
+{{/verbatim}}
 {{heading-1 "Logs"}}
 {{verbatim-monospaced logs}}
 EOT
@@ -456,7 +459,7 @@ sub send_notification {
     my $mode = $opts->{"notification-mode"} // 'auto';
 
     sanitize_task_list($tasklist);
-    my $error_count = count_failed_tasks($tasklist);
+    my ($error_count, $total_size) = aggregate_task_statistics($tasklist);
 
     my $failed = ($error_count || $err);
 
@@ -486,12 +489,13 @@ sub send_notification {
     my $hostname = get_hostname();
 
     my $notification_props = {
-       "hostname"      => $hostname,
+       "hostname" => $hostname,
        "error-message" => $err,
-       "guest-table"   => build_guest_table($tasklist),
-       "logs"          => $text_log_part,
-       "status-text"   => $status_text,
-       "total-time"    => $total_time,
+       "guest-table" => build_guest_table($tasklist),
+       "logs" => $text_log_part,
+       "status-text" => $status_text,
+       "total-time" => $total_time,
+       "total-size" => $total_size,
     };
 
     my $fields = {