How to Customize the Proxmox VZDump Email Notification Format for Backup Summaries.

TonnarakNET

New Member
Mar 29, 2024
1
0
1
Hi,

I want the email notification to include only the VM table results, without attaching log data. The email should provide a summary of the backup results, such as:
  1. All backups succeeded.
  2. All backups succeeded except for specific VMIDs or VMNames.
  3. All backups failed.
Thank you.
 
https://bugzilla.proxmox.com/show_bug.cgi?id=6143

In the meanwhile you can edit the notification templates in /usr/share/proxmox-ve/templates/default, just be aware that your changes can be overridden by a package upgrade. Once the override mechanism as described in the bug report is implemented, this is not the case any more.
 
Hi.

I have some questions, Where to find the variable that we can use for backups, and which template to use? does it have a list of variable templates provided?

Thank you!
 
There are three template files, vzdump-body.html.hbs, vzdump-body.txt.hbs and vzdump-subject.txt.hbs. The subject template is used for the subject for the email. The backup notification mail is sent as a multi-part message, containing a plaintext part (vzdump-body.txt.hbs) and an HTML part (vzdump-body.html.hbs). If the HTML template file does not exist, the plaintext template is used for both the plaintext part and the HTML part.

Regarding variables, there is not really much more available than what is used at the moment in the existing templates. See [1] for which data is passed to the rendering engine.

The templates are based on Handlebars templates [2], refer to [3] for a syntax reference.

The following helper functions are available for our notification templates:
  • {{ human-byte <data> }} renders a byte value to humanly readable form (e.g. 1.4GiB)
  • {{ duration <data> }} format a duration (e.g. number of seconds to 1h 4m 10s)
  • {{ timestamp <data> }} format a Unix timestamp
  • {{ table <data> }} render a table. The data that is passed must conform to the expected schema (e.g see [4] for an example)
  • {{ object <data> }} format the passed data as pretty-printed JSON

The templates and helpers are still somewhat of an implementation detail and might change once we add the override mechanism.
Then we might add additional variables or helpers.

I hope this helps. Let me know if you have any further specific questions. Also let me know if you have any wishes or suggestions for what additional variables/helpers you could need, we will consider them when adding the override mechanism.

[1] https://git.proxmox.com/?p=pve-mana...e002a6268eec456d055c9ef42f79eb8e;hb=HEAD#l531
[2] https://docs.rs/handlebars/latest/handlebars/
[3] https://handlebarsjs.com/
[4] https://git.proxmox.com/?p=proxmox....18b027018f0d13532404b205e3dc6366;hb=HEAD#l101
 
If the HTML template file does not exist, the plaintext template is used for both the plaintext part and the HTML part.
Very useful info and look forward to the enhancement.

In my case, I send all my smtp notifications (including from pve) to a local smtp gateway and into Slack. To keep it condensed/readable on Slack, I have deleted the vzdump-body.html.hbs template to disable html content.

This works mostly ok, but strangely the text content that shows up in Slack includes <html><body><pre> tags at the top and bottom. Seems might be some code somewhere that must be calling the txt.hbs and adds in html wrapper tags when it's not needed.

Is there a clean/easy way to avoid this. Would be good if the enhancement resolves this as well.
 
In my case, I send all my smtp notifications (including from pve) to a local smtp gateway and into Slack. To keep it condensed/readable on Slack, I have deleted the vzdump-body.html.hbs template to disable html content.

This works mostly ok, but strangely the text content that shows up in Slack includes <html><body><pre> tags at the top and bottom. Seems might be some code somewhere that must be calling the txt.hbs and adds in html wrapper tags when it's not needed.

Is there a clean/easy way to avoid this. Would be good if the enhancement resolves this as well.

The mail-based notification targets always send multi-part messages, including a HTML part and a plaintext part. If the template for the HTML part could not be found, we render the plaintext one and wrap the content in <html><body><pre> tags. This is not likely to be changed with the introduced override mechanism (first draft here: [1]).
What we could do is to have an (advanced) setting for mail based targets to only send then plaintext part. Should not really hurt anyone and could help with these more exotic use cases like yours.

[1] https://lore.proxmox.com/pve-devel/20250313151734.258337-1-a.zeidler@proxmox.com/
 
That works for me. Thanks.

For now in case it helps others, you can use body_checks and header_checks to process the outgoing notification in proxmox/postfix, to strip out the <html><body><pre><tags> and to modify the email header to force the content to be received as plain text.
 
https://bugzilla.proxmox.com/show_bug.cgi?id=6143

In the meanwhile you can edit the notification templates in /usr/share/proxmox-ve/templates/default, just be aware that your changes can be overridden by a package upgrade. Once the override mechanism as described in the bug report is implemented, this is not the case any more.
Hi Lukas,

Not finding /usr/share/proxmox-ve/templates/default in my Proxmox install version 8.4.1. I see this is a recent post but my /usr/share/proxmox-ve/ folder only has one file in it (pve-apt-hook).

Thanks