proxy: use new datastore notify settings
This commit is contained in:
parent
6e545d0058
commit
f47c1d3a2f
|
@ -75,7 +75,7 @@ pub fn do_sync_job(
|
|||
let job_id = job.jobname().to_string();
|
||||
let worker_type = job.jobtype().to_string();
|
||||
|
||||
let email = crate::server::lookup_user_email(auth_id.user());
|
||||
let (email, notify) = crate::server::lookup_datastore_notify_settings(&sync_job.store);
|
||||
|
||||
let upid_str = WorkerTask::spawn(
|
||||
&worker_type,
|
||||
|
@ -126,7 +126,7 @@ pub fn do_sync_job(
|
|||
}
|
||||
|
||||
if let Some(email) = email {
|
||||
if let Err(err) = crate::server::send_sync_status(&email, &sync_job2, &result) {
|
||||
if let Err(err) = crate::server::send_sync_status(&email, notify, &sync_job2, &result) {
|
||||
eprintln!("send sync notification failed: {}", err);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,12 +6,14 @@ use handlebars::{Handlebars, Helper, Context, RenderError, RenderContext, Output
|
|||
use proxmox::tools::email::sendmail;
|
||||
|
||||
use crate::{
|
||||
config::datastore::DataStoreConfig,
|
||||
config::verify::VerificationJobConfig,
|
||||
config::sync::SyncJobConfig,
|
||||
api2::types::{
|
||||
APTUpdateInfo,
|
||||
GarbageCollectionStatus,
|
||||
Userid,
|
||||
Notify,
|
||||
},
|
||||
tools::format::HumanByte,
|
||||
};
|
||||
|
@ -188,11 +190,16 @@ fn send_job_status_mail(
|
|||
|
||||
pub fn send_gc_status(
|
||||
email: &str,
|
||||
notify: Notify,
|
||||
datastore: &str,
|
||||
status: &GarbageCollectionStatus,
|
||||
result: &Result<(), Error>,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
if notify == Notify::Never || (result.is_ok() && notify == Notify::Error) {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let (fqdn, port) = get_server_url();
|
||||
let mut data = json!({
|
||||
"datastore": datastore,
|
||||
|
@ -237,10 +244,15 @@ pub fn send_gc_status(
|
|||
|
||||
pub fn send_verify_status(
|
||||
email: &str,
|
||||
notify: Notify,
|
||||
job: VerificationJobConfig,
|
||||
result: &Result<Vec<String>, Error>,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
if notify == Notify::Never || (result.is_ok() && notify == Notify::Error) {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let (fqdn, port) = get_server_url();
|
||||
let mut data = json!({
|
||||
"job": job,
|
||||
|
@ -280,10 +292,15 @@ pub fn send_verify_status(
|
|||
|
||||
pub fn send_sync_status(
|
||||
email: &str,
|
||||
notify: Notify,
|
||||
job: &SyncJobConfig,
|
||||
result: &Result<(), Error>,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
if notify == Notify::Never || (result.is_ok() && notify == Notify::Error) {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let (fqdn, port) = get_server_url();
|
||||
let mut data = json!({
|
||||
"job": job,
|
||||
|
@ -362,7 +379,7 @@ pub fn send_updates_available(
|
|||
/// Lookup users email address
|
||||
///
|
||||
/// For "backup@pam", this returns the address from "root@pam".
|
||||
pub fn lookup_user_email(userid: &Userid) -> Option<String> {
|
||||
fn lookup_user_email(userid: &Userid) -> Option<String> {
|
||||
|
||||
use crate::config::user::{self, User};
|
||||
|
||||
|
@ -379,6 +396,36 @@ pub fn lookup_user_email(userid: &Userid) -> Option<String> {
|
|||
None
|
||||
}
|
||||
|
||||
/// Lookup Datastore notify settings
|
||||
pub fn lookup_datastore_notify_settings(
|
||||
store: &str,
|
||||
) -> (Option<String>, Notify) {
|
||||
|
||||
let mut notify = Notify::Always;
|
||||
let mut email = None;
|
||||
|
||||
let (config, _digest) = match crate::config::datastore::config() {
|
||||
Ok(result) => result,
|
||||
Err(_) => return (email, notify),
|
||||
};
|
||||
|
||||
let config: DataStoreConfig = match config.lookup("datastore", store) {
|
||||
Ok(result) => result,
|
||||
Err(_) => return (email, notify),
|
||||
};
|
||||
|
||||
email = match config.notify_user {
|
||||
Some(ref userid) => lookup_user_email(userid),
|
||||
None => lookup_user_email(Userid::backup_userid()),
|
||||
};
|
||||
|
||||
if let Some(value) = config.notify {
|
||||
notify = value;
|
||||
}
|
||||
|
||||
(email, notify)
|
||||
}
|
||||
|
||||
// Handlerbar helper functions
|
||||
|
||||
fn handlebars_humam_bytes_helper(
|
||||
|
|
|
@ -17,10 +17,10 @@ pub fn do_garbage_collection_job(
|
|||
to_stdout: bool,
|
||||
) -> Result<String, Error> {
|
||||
|
||||
let email = crate::server::lookup_user_email(auth_id.user());
|
||||
|
||||
let store = datastore.name().to_string();
|
||||
|
||||
let (email, notify) = crate::server::lookup_datastore_notify_settings(&store);
|
||||
|
||||
let worker_type = job.jobtype().to_string();
|
||||
let upid_str = WorkerTask::new_thread(
|
||||
&worker_type,
|
||||
|
@ -50,7 +50,7 @@ pub fn do_garbage_collection_job(
|
|||
|
||||
if let Some(email) = email {
|
||||
let gc_status = datastore.last_gc_status();
|
||||
if let Err(err) = crate::server::send_gc_status(&email, &store, &gc_status, &result) {
|
||||
if let Err(err) = crate::server::send_gc_status(&email, notify, &store, &gc_status, &result) {
|
||||
eprintln!("send gc notification failed: {}", err);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ pub fn do_verification_job(
|
|||
}
|
||||
};
|
||||
|
||||
let email = crate::server::lookup_user_email(auth_id.user());
|
||||
let (email, notify) = crate::server::lookup_datastore_notify_settings(&verification_job.store);
|
||||
|
||||
let job_id = job.jobname().to_string();
|
||||
let worker_type = job.jobtype().to_string();
|
||||
|
@ -84,7 +84,7 @@ pub fn do_verification_job(
|
|||
}
|
||||
|
||||
if let Some(email) = email {
|
||||
if let Err(err) = crate::server::send_verify_status(&email, verification_job, &result) {
|
||||
if let Err(err) = crate::server::send_verify_status(&email, notify, verification_job, &result) {
|
||||
eprintln!("send verify notification failed: {}", err);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue