[pve-devel] [PATCH pve-manager 1/4] notification templates: vzdump: generate HTML table in template
Lukas Wagner
l.wagner at proxmox.com
Thu Mar 27 15:23:16 CET 2025
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 at 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
More information about the pve-devel
mailing list