From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id CC7D893C80 for ; Tue, 9 Apr 2024 15:33:55 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B64621F9FA for ; Tue, 9 Apr 2024 15:33:55 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 9 Apr 2024 15:33:54 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 5CB26420C8 for ; Tue, 9 Apr 2024 15:26:08 +0200 (CEST) From: Lukas Wagner To: pve-devel@lists.proxmox.com Date: Tue, 9 Apr 2024 15:25:55 +0200 Message-Id: <20240409132555.364926-20-l.wagner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240409132555.364926-1-l.wagner@proxmox.com> References: <20240409132555.364926-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.506 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% CONTENT_AFTER_HTML 1 More content after HTML close tag + other spam signs 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [apt.pm, vzdump.pm, replication.pm] Subject: [pve-devel] [PATCH manager 19/19] notifications: use named templates instead of in-code templates X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Apr 2024 13:33:55 -0000 This commit adapts notification sending for - package update - replication - backups to use named templates (installed in /usr/share/proxmox-ve/templates) instead of passing template strings defined in code to the notification stack. Signed-off-by: Lukas Wagner Tested-by: Folke Gleumes --- Makefile | 2 +- PVE/API2/APT.pm | 9 +------ PVE/API2/Replication.pm | 20 +--------------- PVE/VZDump.pm | 6 ++--- templates/Makefile | 24 +++++++++++++++++++ .../default/package-updates-body.html.hbs | 6 +++++ .../default/package-updates-body.txt.hbs | 3 +++ .../default/package-updates-subject.txt.hbs | 1 + templates/default/replication-body.html.hbs | 18 ++++++++++++++ templates/default/replication-body.txt.hbs | 12 ++++++++++ templates/default/replication-subject.txt.hbs | 1 + templates/default/test-body.html.hbs | 1 + templates/default/test-body.txt.hbs | 1 + templates/default/test-subject.txt.hbs | 1 + templates/default/vzdump-body.html.hbs | 11 +++++++++ templates/default/vzdump-body.txt.hbs | 10 ++++++++ templates/default/vzdump-subject.txt.hbs | 1 + 17 files changed, 95 insertions(+), 32 deletions(-) create mode 100644 templates/Makefile create mode 100644 templates/default/package-updates-body.html.hbs create mode 100644 templates/default/package-updates-body.txt.hbs create mode 100644 templates/default/package-updates-subject.txt.hbs create mode 100644 templates/default/replication-body.html.hbs create mode 100644 templates/default/replication-body.txt.hbs create mode 100644 templates/default/replication-subject.txt.hbs create mode 100644 templates/default/test-body.html.hbs create mode 100644 templates/default/test-body.txt.hbs create mode 100644 templates/default/test-subject.txt.hbs create mode 100644 templates/default/vzdump-body.html.hbs create mode 100644 templates/default/vzdump-body.txt.hbs create mode 100644 templates/default/vzdump-subject.txt.hbs diff --git a/Makefile b/Makefile index 28295395..337682b3 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ DSC=$(PACKAGE)_$(DEB_VERSION).dsc DEB=$(PACKAGE)_$(DEB_VERSION)_$(DEB_HOST_ARCH).deb DESTDIR= -SUBDIRS = aplinfo PVE bin www services configs network-hooks test +SUBDIRS = aplinfo PVE bin www services configs network-hooks test templates all: $(SUBDIRS) set -e && for i in $(SUBDIRS); do $(MAKE) -C $$i; done diff --git a/PVE/API2/APT.pm b/PVE/API2/APT.pm index 54121ec2..b4a24c3e 100644 --- a/PVE/API2/APT.pm +++ b/PVE/API2/APT.pm @@ -238,12 +238,6 @@ __PACKAGE__->register_method({ return $pkglist; }}); -my $updates_available_subject_template = "New software packages available ({{hostname}})"; -my $updates_available_body_template = <register_method({ name => 'update_database', path => 'update', @@ -358,8 +352,7 @@ __PACKAGE__->register_method({ }; PVE::Notify::info( - $updates_available_subject_template, - $updates_available_body_template, + "package-updates", $template_data, $metadata_fields, ); diff --git a/PVE/API2/Replication.pm b/PVE/API2/Replication.pm index 0dc944c9..d84ac1ab 100644 --- a/PVE/API2/Replication.pm +++ b/PVE/API2/Replication.pm @@ -92,23 +92,6 @@ my sub _should_mail_at_failcount { return $i * 48 == $fail_count; }; -my $replication_error_subject_template = "Replication Job: '{{job-id}}' failed"; -my $replication_error_body_template = < + + The following updates are available: + {{table updates}} + + diff --git a/templates/default/package-updates-body.txt.hbs b/templates/default/package-updates-body.txt.hbs new file mode 100644 index 00000000..14bdbf9e --- /dev/null +++ b/templates/default/package-updates-body.txt.hbs @@ -0,0 +1,3 @@ +The following updates are available: + +{{table updates}} diff --git a/templates/default/package-updates-subject.txt.hbs b/templates/default/package-updates-subject.txt.hbs new file mode 100644 index 00000000..556a67b8 --- /dev/null +++ b/templates/default/package-updates-subject.txt.hbs @@ -0,0 +1 @@ +New software packages available ({{hostname}}) diff --git a/templates/default/replication-body.html.hbs b/templates/default/replication-body.html.hbs new file mode 100644 index 00000000..d1dea6a1 --- /dev/null +++ b/templates/default/replication-body.html.hbs @@ -0,0 +1,18 @@ + + + Replication job '{{job-id}}' with target '{{job-target}}' and schedule '{{job-schedule}}' failed!

+ + Last successful sync: {{timestamp last-sync}}
+ Next sync try: {{timestamp next-sync}}
+ Failure count: {{failure-count}}
+ + {{#if (eq failure-count 3)}} + Note: The system will now reduce the frequency of error reports, as the job appears to be stuck. + {{/if}} +
+ Error:
+
+{{error}}
+        
+ + diff --git a/templates/default/replication-body.txt.hbs b/templates/default/replication-body.txt.hbs new file mode 100644 index 00000000..a9273fef --- /dev/null +++ b/templates/default/replication-body.txt.hbs @@ -0,0 +1,12 @@ +Replication job '{{job-id}}' with target '{{job-target}}' and schedule '{{job-schedule}}' failed! + +Last successful sync: {{timestamp last-sync}} +Next sync try: {{timestamp next-sync}} +Failure count: {{failure-count}} + +{{#if (eq failure-count 3)}} +Note: The system will now reduce the frequency of error reports, as the job +appears to be stuck. +{{/if}} +Error: +{{ error }} diff --git a/templates/default/replication-subject.txt.hbs b/templates/default/replication-subject.txt.hbs new file mode 100644 index 00000000..9dbaafcd --- /dev/null +++ b/templates/default/replication-subject.txt.hbs @@ -0,0 +1 @@ +Replication Job: '{{job-id}}' failed diff --git a/templates/default/test-body.html.hbs b/templates/default/test-body.html.hbs new file mode 100644 index 00000000..26a43dde --- /dev/null +++ b/templates/default/test-body.html.hbs @@ -0,0 +1 @@ +This is a test of the notification target '{{ target }}'. diff --git a/templates/default/test-body.txt.hbs b/templates/default/test-body.txt.hbs new file mode 100644 index 00000000..26a43dde --- /dev/null +++ b/templates/default/test-body.txt.hbs @@ -0,0 +1 @@ +This is a test of the notification target '{{ target }}'. diff --git a/templates/default/test-subject.txt.hbs b/templates/default/test-subject.txt.hbs new file mode 100644 index 00000000..cb8e1320 --- /dev/null +++ b/templates/default/test-subject.txt.hbs @@ -0,0 +1 @@ +Test notification diff --git a/templates/default/vzdump-body.html.hbs b/templates/default/vzdump-body.html.hbs new file mode 100644 index 00000000..b6730cbb --- /dev/null +++ b/templates/default/vzdump-body.html.hbs @@ -0,0 +1,11 @@ + + + {{error-message}} +

Details

+ {{table guest-table}} + Total running time: {{duration total-time}}
+ Total size: {{human-bytes total-size}}
+

Logs

+
{{logs}}
+ + diff --git a/templates/default/vzdump-body.txt.hbs b/templates/default/vzdump-body.txt.hbs new file mode 100644 index 00000000..90f5b0a4 --- /dev/null +++ b/templates/default/vzdump-body.txt.hbs @@ -0,0 +1,10 @@ +{{error-message}} +Details +======= +{{table guest-table}} +Total running time: {{duration total-time}} +Total size: {{human-bytes total-size}} + +Logs +==== +{{logs}} diff --git a/templates/default/vzdump-subject.txt.hbs b/templates/default/vzdump-subject.txt.hbs new file mode 100644 index 00000000..98a3d9aa --- /dev/null +++ b/templates/default/vzdump-subject.txt.hbs @@ -0,0 +1 @@ +vzdump backup status ({{hostname}}): {{status-text}} -- 2.39.2