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 CB8339568D for ; Fri, 12 Apr 2024 12:07:21 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id AD4877B8C for ; Fri, 12 Apr 2024 12:06:51 +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 ; Fri, 12 Apr 2024 12:06:47 +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 463D94519E for ; Fri, 12 Apr 2024 12:06:44 +0200 (CEST) From: Lukas Wagner To: pbs-devel@lists.proxmox.com Date: Fri, 12 Apr 2024 12:06:17 +0200 Message-Id: <20240412100631.94218-20-l.wagner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240412100631.94218-1-l.wagner@proxmox.com> References: <20240412100631.94218-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.005 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: [pbs-devel] [PATCH proxmox-backup 19/33] server: notifications: send acme notifications via notification system X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Apr 2024 10:07:21 -0000 Signed-off-by: Lukas Wagner --- debian/proxmox-backup-server.install | 2 ++ src/server/notifications.rs | 41 +++++++--------------- templates/Makefile | 24 +++++++------ templates/default/acme-err-body.txt.hbs | 7 ++++ templates/default/acme-err-subject.txt.hbs | 1 + 5 files changed, 35 insertions(+), 40 deletions(-) create mode 100644 templates/default/acme-err-body.txt.hbs create mode 100644 templates/default/acme-err-subject.txt.hbs diff --git a/debian/proxmox-backup-server.install b/debian/proxmox-backup-server.install index 52a01ca5..17951780 100644 --- a/debian/proxmox-backup-server.install +++ b/debian/proxmox-backup-server.install @@ -41,6 +41,8 @@ usr/share/zsh/vendor-completions/_pmtx usr/share/zsh/vendor-completions/_proxmox-backup-debug usr/share/zsh/vendor-completions/_proxmox-backup-manager usr/share/zsh/vendor-completions/_proxmox-tape +usr/share/proxmox-backup/templates/default/acme-err-body.txt.hbs +usr/share/proxmox-backup/templates/default/acme-err-subject.txt.hbs usr/share/proxmox-backup/templates/default/gc-err-body.txt.hbs usr/share/proxmox-backup/templates/default/gc-ok-body.txt.hbs usr/share/proxmox-backup/templates/default/gc-err-subject.txt.hbs diff --git a/src/server/notifications.rs b/src/server/notifications.rs index 0e2f3473..16b506f0 100644 --- a/src/server/notifications.rs +++ b/src/server/notifications.rs @@ -86,18 +86,6 @@ Please visit the web interface for further details: "###; -const ACME_CERTIFICATE_ERR_RENEWAL: &str = r###" - -Proxmox Backup Server was not able to renew a TLS certificate. - -Error: {{error}} - -Please visit the web interface for further details: - - - -"###; - lazy_static::lazy_static! { static ref HANDLEBARS: Handlebars<'static> = { @@ -110,8 +98,6 @@ lazy_static::lazy_static! { hb.register_template_string("tape_backup_ok_template", TAPE_BACKUP_OK_TEMPLATE)?; hb.register_template_string("tape_backup_err_template", TAPE_BACKUP_ERR_TEMPLATE)?; - hb.register_template_string("certificate_renewal_err_template", ACME_CERTIFICATE_ERR_RENEWAL)?; - Ok(()) }); @@ -581,23 +567,22 @@ pub fn send_certificate_renewal_mail(result: &Result<(), Error>) -> Result<(), E _ => return Ok(()), }; - if let Some(email) = lookup_user_email(Userid::root_userid()) { - let (fqdn, port) = get_server_url(); + let (fqdn, port) = get_server_url(); - let text = HANDLEBARS.render( - "certificate_renewal_err_template", - &json!({ - "fqdn": fqdn, - "port": port, - "error": error, - }), - )?; + let data = json!({ + "fqdn": fqdn, + "port": port, + "error": error, + }); - let subject = "Could not renew certificate"; + let metadata = HashMap::from([ + ("hostname".into(), proxmox_sys::nodename().into()), + ("type".into(), "acme".into()), + ]); - send_job_status_mail(&email, subject, &text)?; - } + let notification = Notification::from_template(Severity::Info, "acme-err", data, metadata); + send_notification(notification)?; Ok(()) } @@ -656,6 +641,4 @@ pub fn lookup_datastore_notify_settings( fn test_template_register() { assert!(HANDLEBARS.has_template("tape_backup_ok_template")); assert!(HANDLEBARS.has_template("tape_backup_err_template")); - - assert!(HANDLEBARS.has_template("certificate_renewal_err_template")); } diff --git a/templates/Makefile b/templates/Makefile index 56965400..824d28d9 100644 --- a/templates/Makefile +++ b/templates/Makefile @@ -1,12 +1,14 @@ include ../defines.mk -NOTIFICATION_TEMPLATES= \ - default/gc-err-body.txt.hbs \ - default/gc-ok-body.txt.hbs \ - default/gc-err-subject.txt.hbs \ - default/gc-ok-subject.txt.hbs \ - default/package-updates-body.txt.hbs \ - default/package-updates-subject.txt.hbs \ +NOTIFICATION_TEMPLATES= \ + default/acme-err-body.txt.hbs \ + default/acme-err-subject.txt.hbs \ + default/gc-err-body.txt.hbs \ + default/gc-ok-body.txt.hbs \ + default/gc-err-subject.txt.hbs \ + default/gc-ok-subject.txt.hbs \ + default/package-updates-body.txt.hbs \ + default/package-updates-subject.txt.hbs \ default/prune-err-body.txt.hbs \ default/prune-ok-body.txt.hbs \ default/prune-err-subject.txt.hbs \ @@ -14,10 +16,10 @@ NOTIFICATION_TEMPLATES= \ default/sync-err-body.txt.hbs \ default/sync-ok-body.txt.hbs \ default/sync-err-subject.txt.hbs \ - default/sync-ok-subject.txt.hbs \ - default/test-body.txt.hbs \ - default/test-body.html.hbs \ - default/test-subject.txt.hbs \ + default/sync-ok-subject.txt.hbs \ + default/test-body.txt.hbs \ + default/test-body.html.hbs \ + default/test-subject.txt.hbs \ default/verify-err-body.txt.hbs \ default/verify-ok-body.txt.hbs \ default/verify-err-subject.txt.hbs \ diff --git a/templates/default/acme-err-body.txt.hbs b/templates/default/acme-err-body.txt.hbs new file mode 100644 index 00000000..3cbfea4a --- /dev/null +++ b/templates/default/acme-err-body.txt.hbs @@ -0,0 +1,7 @@ +Proxmox Backup Server was not able to renew a TLS certificate. + +Error: {{error}} + +Please visit the web interface for further details: + + diff --git a/templates/default/acme-err-subject.txt.hbs b/templates/default/acme-err-subject.txt.hbs new file mode 100644 index 00000000..3cf4fe45 --- /dev/null +++ b/templates/default/acme-err-subject.txt.hbs @@ -0,0 +1 @@ +Could not renew certificate -- 2.39.2