From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [RFC proxmox-backup 4/8] server: add sanity check job email notifications
Date: Wed, 13 Dec 2023 16:38:15 +0100 [thread overview]
Message-ID: <20231213153819.391392-5-c.ebner@proxmox.com> (raw)
In-Reply-To: <20231213153819.391392-1-c.ebner@proxmox.com>
Defines the email templates and method to send success/failure
notification emails for the sanity check jobs.
Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
src/server/email_notifications.rs | 78 +++++++++++++++++++++++++++++++
1 file changed, 78 insertions(+)
diff --git a/src/server/email_notifications.rs b/src/server/email_notifications.rs
index 43b55656..7672f30a 100644
--- a/src/server/email_notifications.rs
+++ b/src/server/email_notifications.rs
@@ -241,6 +241,36 @@ Please visit the web interface for further details:
"###;
+const SANITY_CHECK_OK_TEMPLATE: &str = r###"
+
+Job ID: {{jobname}}
+
+Sanity check successful.
+
+
+Please visit the web interface for further details:
+
+<https://{{fqdn}}:{{port}}/#pbsServerAdministration:tasks>
+
+"###;
+
+const SANITY_CHECK_ERR_TEMPLATE: &str = r###"
+
+Job ID: {{jobname}}
+
+Sanity checks failed:
+
+{{#each errors}}
+ {{this~}}
+{{/each}}
+
+
+Please visit the web interface for further details:
+
+<https://{{fqdn}}:{{port}}/#pbsServerAdministration:tasks>
+
+"###;
+
lazy_static::lazy_static! {
static ref HANDLEBARS: Handlebars<'static> = {
@@ -272,6 +302,9 @@ lazy_static::lazy_static! {
hb.register_template_string("certificate_renewal_err_template", ACME_CERTIFICATE_ERR_RENEWAL)?;
+ hb.register_template_string("sanity_check_ok_template", SANITY_CHECK_OK_TEMPLATE)?;
+ hb.register_template_string("sanity_check_err_template", SANITY_CHECK_ERR_TEMPLATE)?;
+
Ok(())
});
@@ -460,6 +493,48 @@ pub fn send_prune_status(
Ok(())
}
+pub fn send_sanity_check_status(
+ email: &str,
+ notify: Option<Notify>,
+ jobname: &str,
+ result: &Result<Vec<String>, Error>,
+) -> Result<(), Error> {
+ match notify {
+ None => { /* send notifications by default */ }
+ Some(notify) => {
+ if notify == Notify::Never || (result.is_ok() && notify == Notify::Error) {
+ return Ok(());
+ }
+ }
+ }
+
+ let (fqdn, port) = get_server_url();
+ let mut data = json!({
+ "jobname": jobname,
+ "fqdn": fqdn,
+ "port": port,
+ });
+
+ let (subject, text) = match result {
+ Ok(errors) if errors.is_empty() => (
+ format!("Sanity check successful"),
+ HANDLEBARS.render("sanity_check_ok_template", &data)?,
+ ),
+ Ok(errors) => {
+ data["errors"] = json!(errors);
+ (
+ format!("Sanity check failed"),
+ HANDLEBARS.render("sanity_check_err_template", &data)?,
+ )
+ }
+ Err(_) => return Ok(()),
+ };
+
+ send_job_status_mail(&email, &subject, &text)?;
+
+ Ok(())
+}
+
pub fn send_sync_status(
email: &str,
notify: DatastoreNotify,
@@ -760,4 +835,7 @@ fn test_template_register() {
assert!(HANDLEBARS.has_template("package_update_template"));
assert!(HANDLEBARS.has_template("certificate_renewal_err_template"));
+
+ assert!(HANDLEBARS.has_template("sanity_check_ok_template"));
+ assert!(HANDLEBARS.has_template("sanity_check_err_template"));
}
--
2.39.2
next prev parent reply other threads:[~2023-12-13 15:38 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-13 15:38 [pbs-devel] [RFC proxmox-backup 0/8] implement sanity check jobs Christian Ebner
2023-12-13 15:38 ` [pbs-devel] [RFC proxmox-backup 1/8] api-types: jobs: add sanity checks job types Christian Ebner
2023-12-13 15:38 ` [pbs-devel] [RFC proxmox-backup 2/8] config: implement sanity check job configuration Christian Ebner
2023-12-13 15:38 ` [pbs-devel] [RFC proxmox-backup 3/8] api: config: sanity check jobs api endpoints Christian Ebner
2023-12-13 15:38 ` Christian Ebner [this message]
2023-12-13 15:38 ` [pbs-devel] [RFC proxmox-backup 5/8] server: implement sanity check job Christian Ebner
2023-12-13 15:38 ` [pbs-devel] [RFC proxmox-backup 6/8] api: admin: add sanity check job api endpoints Christian Ebner
2023-12-13 15:38 ` [pbs-devel] [RFC proxmox-backup 7/8] manager: add sanity check jobs management cli commands Christian Ebner
2023-12-13 15:38 ` [pbs-devel] [RFC proxmox-backup 8/8] proxy: add sanity check task to scheduler Christian Ebner
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=20231213153819.391392-5-c.ebner@proxmox.com \
--to=c.ebner@proxmox.com \
--cc=pbs-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