send sync job status emails
This commit is contained in:
@ -7,6 +7,7 @@ use proxmox::tools::email::sendmail;
|
||||
|
||||
use crate::{
|
||||
config::verify::VerificationJobConfig,
|
||||
config::sync::SyncJobConfig,
|
||||
api2::types::{
|
||||
Userid,
|
||||
GarbageCollectionStatus,
|
||||
@ -68,6 +69,28 @@ Verification failed on these snapshots:
|
||||
|
||||
"###;
|
||||
|
||||
const SYNC_OK_TEMPLATE: &str = r###"
|
||||
|
||||
Job ID: {{job.id}}
|
||||
Datastore: {{job.store}}
|
||||
Remote: {{job.remote}}
|
||||
Remote Store: {{job.remote-store}}
|
||||
|
||||
Synchronization successful.
|
||||
|
||||
"###;
|
||||
|
||||
const SYNC_ERR_TEMPLATE: &str = r###"
|
||||
|
||||
Job ID: {{job.id}}
|
||||
Datastore: {{job.store}}
|
||||
Remote: {{job.remote}}
|
||||
Remote Store: {{job.remote-store}}
|
||||
|
||||
Synchronization failed: {{error}}
|
||||
|
||||
"###;
|
||||
|
||||
lazy_static::lazy_static!{
|
||||
|
||||
static ref HANDLEBARS: Handlebars<'static> = {
|
||||
@ -84,6 +107,9 @@ lazy_static::lazy_static!{
|
||||
hb.register_template_string("verify_ok_template", VERIFY_OK_TEMPLATE).unwrap();
|
||||
hb.register_template_string("verify_err_template", VERIFY_ERR_TEMPLATE).unwrap();
|
||||
|
||||
hb.register_template_string("sync_ok_template", SYNC_OK_TEMPLATE).unwrap();
|
||||
hb.register_template_string("sync_err_template", SYNC_ERR_TEMPLATE).unwrap();
|
||||
|
||||
hb
|
||||
};
|
||||
}
|
||||
@ -200,6 +226,41 @@ pub fn send_verify_status(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn send_sync_status(
|
||||
email: &str,
|
||||
job: &SyncJobConfig,
|
||||
result: &Result<(), Error>,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
let text = match result {
|
||||
Ok(()) => {
|
||||
let data = json!({ "job": job });
|
||||
HANDLEBARS.render("sync_ok_template", &data)?
|
||||
}
|
||||
Err(err) => {
|
||||
let data = json!({ "job": job, "error": err.to_string() });
|
||||
HANDLEBARS.render("sync_err_template", &data)?
|
||||
}
|
||||
};
|
||||
|
||||
let subject = match result {
|
||||
Ok(()) => format!(
|
||||
"Sync remote '{}' datastore '{}' successful",
|
||||
job.remote,
|
||||
job.remote_store,
|
||||
),
|
||||
Err(_) => format!(
|
||||
"Sync remote '{}' datastore '{}' failed",
|
||||
job.remote,
|
||||
job.remote_store,
|
||||
),
|
||||
};
|
||||
|
||||
send_job_status_mail(email, &subject, &text)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Lookup users email address
|
||||
///
|
||||
/// For "backup@pam", this returns the address from "root@pam".
|
||||
|
Reference in New Issue
Block a user