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,
}
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);
}
}
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,
};
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,
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,
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,
/// 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};
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(
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,
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);
}
}
}
};
- 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();
}
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);
}
}