]> git.proxmox.com Git - proxmox-backup.git/blobdiff - src/server/email_notifications.rs
tree-wide: fix needless borrows
[proxmox-backup.git] / src / server / email_notifications.rs
index 4e07ed1360fd4f6382656f8baf1515c0709e5c4f..33b106b487d1cdda06845fbb3941ea3ced7094dc 100644 (file)
@@ -3,23 +3,14 @@ use serde_json::json;
 
 use handlebars::{Handlebars, Helper, Context, RenderError, RenderContext, Output, HelperResult, TemplateError};
 
-use proxmox::tools::email::sendmail;
-use proxmox::api::schema::parse_property_string;
-use proxmox::try_block;
-
-use crate::{
-    config::datastore::DataStoreConfig,
-    config::verify::VerificationJobConfig,
-    config::sync::SyncJobConfig,
-    config::tape_job::TapeBackupJobSetup,
-    api2::types::{
-        APTUpdateInfo,
-        GarbageCollectionStatus,
-        Userid,
-        Notify,
-        DatastoreNotify,
-    },
-    tools::format::HumanByte,
+use proxmox_sys::email::sendmail;
+use proxmox_lang::try_block;
+use proxmox_schema::ApiType;
+
+use pbs_api_types::{
+    User, TapeBackupJobSetup, SyncJobConfig, VerificationJobConfig,
+    APTUpdateInfo, GarbageCollectionStatus, HumanByte,
+    Userid, Notify, DatastoreNotify, DataStoreConfig,
 };
 
 const GC_OK_TEMPLATE: &str = r###"
@@ -176,7 +167,13 @@ Datastore:  {{job.store}}
 Tape Pool:  {{job.pool}}
 Tape Drive: {{job.drive}}
 
+{{#if snapshot-list ~}}
+Snapshots included:
 
+{{#each snapshot-list~}}
+{{this}}
+{{/each~}}
+{{/if}}
 Tape Backup failed: {{error}}
 
 
@@ -242,14 +239,14 @@ fn send_job_status_mail(
     // so we include html as well
     let html = format!("<html><body><pre>\n{}\n<pre>", handlebars::html_escape(text));
 
-    let nodename = proxmox::tools::nodename();
+    let nodename = proxmox_sys::nodename();
 
     let author = format!("Proxmox Backup Server - {}", nodename);
 
     sendmail(
         &[email],
-        &subject,
-        Some(&text),
+        subject,
+        Some(text),
         Some(&html),
         None,
         Some(&author),
@@ -433,7 +430,7 @@ pub fn send_tape_backup_status(
 ) -> Result<(), Error> {
 
     let (fqdn, port) = get_server_url();
-    let duration: crate::tools::systemd::time::TimeSpan = summary.duration.into();
+    let duration: proxmox_time::TimeSpan = summary.duration.into();
     let mut data = json!({
         "job": job,
         "fqdn": fqdn,
@@ -507,7 +504,7 @@ fn get_server_url() -> (String, usize) {
 
     // user will surely request that they can change this
 
-    let nodename = proxmox::tools::nodename();
+    let nodename = proxmox_sys::nodename();
     let mut fqdn = nodename.to_owned();
 
     if let Ok(resolv_conf) = crate::api2::node::dns::read_etc_resolv_conf() {
@@ -527,7 +524,7 @@ pub fn send_updates_available(
 ) -> Result<(), Error> {
     // update mails always go to the root@pam configured email..
     if let Some(email) = lookup_user_email(Userid::root_userid()) {
-        let nodename = proxmox::tools::nodename();
+        let nodename = proxmox_sys::nodename();
         let subject = format!("New software packages available ({})", nodename);
 
         let (fqdn, port) = get_server_url();
@@ -546,9 +543,7 @@ pub fn send_updates_available(
 /// Lookup users email address
 pub fn lookup_user_email(userid: &Userid) -> Option<String> {
 
-    use crate::config::user::{self, User};
-
-    if let Ok(user_config) = user::cached_config() {
+    if let Ok(user_config) = pbs_config::user::cached_config() {
         if let Ok(user) = user_config.lookup::<User>("user", userid.as_str()) {
             return user.email;
         }
@@ -566,7 +561,7 @@ pub fn lookup_datastore_notify_settings(
 
     let notify = DatastoreNotify { gc: None, verify: None, sync: None };
 
-    let (config, _digest) = match crate::config::datastore::config() {
+    let (config, _digest) = match pbs_config::datastore::config() {
         Ok(result) => result,
         Err(_) => return (email, notify),
     };
@@ -583,7 +578,7 @@ pub fn lookup_datastore_notify_settings(
 
     let notify_str = config.notify.unwrap_or_default();
 
-    if let Ok(value) = parse_property_string(&notify_str, &DatastoreNotify::API_SCHEMA) {
+    if let Ok(value) = DatastoreNotify::API_SCHEMA.parse_property_string(&notify_str) {
         if let Ok(notify) = serde_json::from_value(value) {
             return (email, notify);
         }