[pve-devel] [PATCH v2 proxmox-perl-rs 24/42] notify: add api for notification filters
Lukas Wagner
l.wagner at proxmox.com
Wed May 24 15:56:31 CEST 2023
Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
---
pve-rs/src/notify.rs | 87 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 87 insertions(+)
diff --git a/pve-rs/src/notify.rs b/pve-rs/src/notify.rs
index 84bc184..9adeff5 100644
--- a/pve-rs/src/notify.rs
+++ b/pve-rs/src/notify.rs
@@ -13,6 +13,9 @@ mod export {
use proxmox_notify::endpoints::sendmail::{
DeleteableSendmailProperty, SendmailConfig, SendmailConfigUpdater,
};
+ use proxmox_notify::filter::{
+ DeleteableFilterProperty, FilterConfig, FilterConfigUpdater, FilterModeOperator,
+ };
use proxmox_notify::{api, api::ApiError, Config, Notification, Severity};
pub struct NotificationConfig {
@@ -321,4 +324,88 @@ mod export {
let mut config = this.config.lock().unwrap();
api::gotify::delete_gotify_endpoint(&mut config, name)
}
+
+ #[export(serialize_error)]
+ fn get_filters(
+ #[try_from_ref] this: &NotificationConfig,
+ ) -> Result<Vec<FilterConfig>, ApiError> {
+ let config = this.config.lock().unwrap();
+ api::filter::get_filters(&config)
+ }
+
+ #[export(serialize_error)]
+ fn get_filter(
+ #[try_from_ref] this: &NotificationConfig,
+ id: &str,
+ ) -> Result<FilterConfig, ApiError> {
+ let config = this.config.lock().unwrap();
+ api::filter::get_filter(&config, id)
+ }
+
+ #[export(serialize_error)]
+ #[allow(clippy::too_many_arguments)]
+ fn add_filter(
+ #[try_from_ref] this: &NotificationConfig,
+ name: String,
+ min_severity: Option<Severity>,
+ sub_filter: Option<Vec<String>>,
+ mode: Option<FilterModeOperator>,
+ match_property: Option<Vec<String>>,
+ invert_match: Option<bool>,
+ comment: Option<String>,
+ ) -> Result<(), ApiError> {
+ let mut config = this.config.lock().unwrap();
+ api::filter::add_filter(
+ &mut config,
+ &FilterConfig {
+ name,
+ min_severity,
+ sub_filter,
+ mode,
+ match_property,
+ invert_match,
+ comment,
+ },
+ )
+ }
+
+ #[export(serialize_error)]
+ #[allow(clippy::too_many_arguments)]
+ fn update_filter(
+ #[try_from_ref] this: &NotificationConfig,
+ name: &str,
+ min_severity: Option<Severity>,
+ sub_filter: Option<Vec<String>>,
+ mode: Option<FilterModeOperator>,
+ match_property: Option<Vec<String>>,
+ invert_match: Option<bool>,
+ comment: Option<String>,
+ delete: Option<Vec<DeleteableFilterProperty>>,
+ digest: Option<&str>,
+ ) -> Result<(), ApiError> {
+ let mut config = this.config.lock().unwrap();
+ api::filter::update_filter(
+ &mut config,
+ name,
+ &FilterConfigUpdater {
+ min_severity,
+ sub_filter,
+ mode,
+ match_property,
+ invert_match,
+ comment,
+ },
+ delete.as_deref(),
+ digest.map(|d| d.as_bytes()),
+ )
+ }
+
+ #[export(serialize_error)]
+ fn delete_filter(
+ #[try_from_ref] this: &NotificationConfig,
+ name: &str,
+ ) -> Result<(), ApiError> {
+ let mut config = this.config.lock().unwrap();
+ api::filter::delete_filter(&mut config, name)
+ }
}
--
2.30.2
More information about the pve-devel
mailing list