From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9])
	by lore.proxmox.com (Postfix) with ESMTPS id E2A8C1FF164
	for <inbox@lore.proxmox.com>; Fri, 28 Mar 2025 11:20:04 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 62A39367A9;
	Fri, 28 Mar 2025 11:19:56 +0100 (CET)
From: Lukas Wagner <l.wagner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Fri, 28 Mar 2025 11:19:11 +0100
Message-Id: <20250328101915.73951-3-l.wagner@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20250328101915.73951-1-l.wagner@proxmox.com>
References: <20250328101915.73951-1-l.wagner@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.013 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pve-devel] [PATCH pve-manager v2 1/4] notification templates:
 vzdump: generate HTML table in template
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

Instead of relying on the 'magic' table helper, we generate the guest
list in the vzdump HTML notification template using native Handlebars
syntax ({{#each}}). The template becomes a bit more ugly, mostly due to
HTML email's requirements to use inline CSS styling, but in the context
of providing user-customizable notification templates this is much
nicer. It gives the user a starting point for their modificiations
(custom styling, changing table formatting/order/etc.), which was not
possible before.

The plaintext template stays as is for now, mostly due to the fact that
the table helper automatically aligns table columns - something that
is not easily possible with native Handlebars syntax.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 PVE/VZDump.pm                            | 21 +++++++++------------
 templates/default/vzdump-body.html.hbs   | 24 ++++++++++++++++++++++--
 templates/default/vzdump-body.txt.hbs    |  2 +-
 templates/default/vzdump-subject.txt.hbs |  2 +-
 4 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index fd89945e..e0fbc555 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -528,16 +528,13 @@ sub send_notification {
 	    "See Task History for details!\n";
     };
 
-    my $notification_props = {
-	# Hostname, might include domain part
-	"hostname" => get_hostname(),
-	"error-message" => $err,
-	"guest-table" => build_guest_table($tasklist),
-	"logs" => $text_log_part,
-	"status-text" => $status_text,
-	"total-time" => $total_time,
-	"total-size" => $total_size,
-    };
+    my $template_data = PVE::Notify::common_template_data();
+    $template_data->{error} = $err;
+    $template_data->{"guest-table"} = build_guest_table($tasklist);
+    $template_data->{logs} = $text_log_part;
+    $template_data->{"status-text"} = $status_text;
+    $template_data->{"total-size"} = $total_size;
+    $template_data->{"total-time"} = $total_time;
 
     my $fields = {
 	type => "vzdump",
@@ -586,7 +583,7 @@ sub send_notification {
 	    PVE::Notify::notify(
 		$severity,
 		"vzdump",
-		$notification_props,
+		$template_data,
 		$fields,
 		$notification_config
 	    );
@@ -597,7 +594,7 @@ sub send_notification {
 	PVE::Notify::notify(
 	    $severity,
 	    "vzdump",
-	    $notification_props,
+	    $template_data,
 	    $fields,
 	);
     }
diff --git a/templates/default/vzdump-body.html.hbs b/templates/default/vzdump-body.html.hbs
index b6730cbb..7f2245d7 100644
--- a/templates/default/vzdump-body.html.hbs
+++ b/templates/default/vzdump-body.html.hbs
@@ -1,8 +1,28 @@
 <html>
     <body>
-        {{error-message}}
+        {{error}}
         <h1 style="font-size: 1.2em">Details</h1>
-        {{table guest-table}}
+        <table style="border: 1px solid;border-collapse=collapse;">
+            <tr>
+                <th style="border: 1px solid;border-collapse=collapse;">VMID</th>
+                <th style="border: 1px solid;border-collapse=collapse;">Name</th>
+                <th style="border: 1px solid;border-collapse=collapse;">Status</th>
+                <th style="border: 1px solid;border-collapse=collapse;">Time</th>
+                <th style="border: 1px solid;border-collapse=collapse;">Size</th>
+                <th style="border: 1px solid;border-collapse=collapse;">Filename</th>
+            </tr>
+        {{#each guest-table.data}}
+            <tr>
+                <td style="border: 1px solid;border-collapse=collapse;">{{this.vmid}}</th>
+                <td style="border: 1px solid;border-collapse=collapse;">{{this.name}}</th>
+                <td style="border: 1px solid;border-collapse=collapse;">{{this.status}}</th>
+                <td style="border: 1px solid;border-collapse=collapse;">{{duration this.time}}</th>
+                <td style="border: 1px solid;border-collapse=collapse;">{{human-bytes this.size}}</th>
+                <td style="border: 1px solid;border-collapse=collapse;">{{this.filename}}</th>
+            </tr>
+        {{/each}}
+        </table>
+        <br/>
         Total running time: {{duration total-time}}<br/>
         Total size: {{human-bytes total-size}}<br/>
         <h1 style="font-size: 1.2em">Logs</h1>
diff --git a/templates/default/vzdump-body.txt.hbs b/templates/default/vzdump-body.txt.hbs
index 90f5b0a4..4bd0fab8 100644
--- a/templates/default/vzdump-body.txt.hbs
+++ b/templates/default/vzdump-body.txt.hbs
@@ -1,4 +1,4 @@
-{{error-message}}
+{{error}}
 Details
 =======
 {{table guest-table}}
diff --git a/templates/default/vzdump-subject.txt.hbs b/templates/default/vzdump-subject.txt.hbs
index 98a3d9aa..107b5fc7 100644
--- a/templates/default/vzdump-subject.txt.hbs
+++ b/templates/default/vzdump-subject.txt.hbs
@@ -1 +1 @@
-vzdump backup status ({{hostname}}): {{status-text}}
+vzdump backup status ({{fqdn}}): {{status-text}}
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel