From: Lukas Wagner <l.wagner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-manager v2 1/4] notification templates: vzdump: generate HTML table in template
Date: Fri, 28 Mar 2025 11:19:11 +0100 [thread overview]
Message-ID: <20250328101915.73951-3-l.wagner@proxmox.com> (raw)
In-Reply-To: <20250328101915.73951-1-l.wagner@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
next prev parent reply other threads:[~2025-03-28 10:20 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-28 10:19 [pve-devel] [PATCH cluster/ha-manager/manager v2 0/6] preparation for #6143: notification template cleanup Lukas Wagner
2025-03-28 10:19 ` [pve-devel] [PATCH pve-cluster v2 1/1] notify: add common_template_data Lukas Wagner
2025-04-04 10:15 ` [pve-devel] applied: " Thomas Lamprecht
2025-03-28 10:19 ` Lukas Wagner [this message]
2025-03-28 10:19 ` [pve-devel] [PATCH pve-manager v2 2/4] notifications: apt: clean up notification template Lukas Wagner
2025-03-28 10:19 ` [pve-devel] [PATCH pve-manager v2 3/4] notification: replication: add common properties to template data Lukas Wagner
2025-03-28 10:19 ` [pve-devel] [PATCH pve-manager v2 4/4] notifications: test: style fixup Lukas Wagner
2025-03-28 10:19 ` [pve-devel] [PATCH pve-ha-manager v2 1/1] notifications: overhaul fence notification Lukas Wagner
2025-04-04 18:25 ` [pve-devel] applied: " Thomas Lamprecht
2025-04-04 18:27 ` [pve-devel] applied-series: [PATCH cluster/ha-manager/manager v2 0/6] preparation for #6143: notification template cleanup Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250328101915.73951-3-l.wagner@proxmox.com \
--to=l.wagner@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal