[pve-devel] [PATCH proxmox 05/18] notification: allow adding new sendmail endpoints / filters
Lukas Wagner
l.wagner at proxmox.com
Mon Mar 27 17:18:44 CEST 2023
This is needed to migrate the PVE codebase from sendmail to the new
notification module - there, every place in the code that currently
sends out mails will add an 'ephemeral' sendmail endpoint, and also a
simple severity filter if needed. This ensures that there is a smooth
migration to the new notification module, without any events going
unnoticed.
Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
---
proxmox-notification/src/lib.rs | 1 +
proxmox-notification/src/methods.rs | 55 +++++++++++++++++++++++++++++
2 files changed, 56 insertions(+)
create mode 100644 proxmox-notification/src/methods.rs
diff --git a/proxmox-notification/src/lib.rs b/proxmox-notification/src/lib.rs
index fc724dd..24429e4 100644
--- a/proxmox-notification/src/lib.rs
+++ b/proxmox-notification/src/lib.rs
@@ -14,6 +14,7 @@ use serde::{Deserialize, Serialize};
mod config;
mod endpoints;
pub mod filter;
+pub mod methods;
#[api()]
#[derive(Clone, Debug, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd)]
diff --git a/proxmox-notification/src/methods.rs b/proxmox-notification/src/methods.rs
new file mode 100644
index 0000000..4f841e3
--- /dev/null
+++ b/proxmox-notification/src/methods.rs
@@ -0,0 +1,55 @@
+use anyhow::Error;
+
+use crate::{
+ endpoints::sendmail::{SendmailConfig, SENDMAIL_TYPENAME},
+ filter::{FilterConfig, FilterModeOperator, FILTER_TYPENAME},
+ Config, Severity,
+};
+
+pub fn add_sendmail_endpoint(
+ config: &mut Config,
+ name: &str,
+ recipient: Vec<String>,
+ from_address: Option<String>,
+ author: Option<String>,
+ filter: Option<String>,
+) -> Result<(), Error> {
+ config.0.set_data(
+ name,
+ SENDMAIL_TYPENAME,
+ &SendmailConfig {
+ name: name.into(),
+ recipient,
+ from_address,
+ author,
+ filter,
+ },
+ )?;
+
+ Ok(())
+}
+
+pub fn add_filter(
+ config: &mut Config,
+ name: &str,
+ min_severity: Option<Severity>,
+ sub_filter: Option<Vec<String>>,
+ mode: Option<FilterModeOperator>,
+ match_property: Option<Vec<String>>,
+ invert_match: Option<bool>,
+) -> Result<(), Error> {
+ config.0.set_data(
+ name,
+ FILTER_TYPENAME,
+ &FilterConfig {
+ name: name.into(),
+ min_severity,
+ sub_filter,
+ mode,
+ match_property,
+ invert_match,
+ },
+ )?;
+
+ Ok(())
+}
--
2.30.2
More information about the pve-devel
mailing list