From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 56F5199CD0 for ; Tue, 14 Nov 2023 14:00:51 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 06AAE30060 for ; Tue, 14 Nov 2023 14:00:19 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 14 Nov 2023 14:00:15 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id DE19942991 for ; Tue, 14 Nov 2023 14:00:14 +0100 (CET) From: Lukas Wagner To: pve-devel@lists.proxmox.com Date: Tue, 14 Nov 2023 13:59:24 +0100 Message-Id: <20231114130000.565122-17-l.wagner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231114130000.565122-1-l.wagner@proxmox.com> References: <20231114130000.565122-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.017 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_FILL_THIS_FORM_SHORT 0.01 Fill in a short form with personal information T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH v2 proxmox-perl-rs 16/52] notify: adapt to new matcher-based notification routing X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Nov 2023 13:00:51 -0000 Signed-off-by: Lukas Wagner --- common/src/notify.rs | 167 +++++++++++++------------------------------ 1 file changed, 50 insertions(+), 117 deletions(-) diff --git a/common/src/notify.rs b/common/src/notify.rs index 9f44225..4fbd705 100644 --- a/common/src/notify.rs +++ b/common/src/notify.rs @@ -1,10 +1,12 @@ #[perlmod::package(name = "Proxmox::RS::Notify")] mod export { + use std::collections::HashMap; + use std::sync::Mutex; + use anyhow::{bail, Error}; - use perlmod::Value; use serde_json::Value as JSONValue; - use std::sync::Mutex; + use perlmod::Value; use proxmox_http_error::HttpError; use proxmox_notify::endpoints::gotify::{ DeleteableGotifyProperty, GotifyConfig, GotifyConfigUpdater, GotifyPrivateConfig, @@ -13,10 +15,10 @@ mod export { use proxmox_notify::endpoints::sendmail::{ DeleteableSendmailProperty, SendmailConfig, SendmailConfigUpdater, }; - use proxmox_notify::filter::{ - DeleteableFilterProperty, FilterConfig, FilterConfigUpdater, FilterModeOperator, + use proxmox_notify::matcher::{ + CalendarMatcher, DeleteableMatcherProperty, FieldMatcher, MatchModeOperator, MatcherConfig, + MatcherConfigUpdater, SeverityMatcher, }; - use proxmox_notify::group::{DeleteableGroupProperty, GroupConfig, GroupConfigUpdater}; use proxmox_notify::{api, Config, Notification, Severity}; pub struct NotificationConfig { @@ -87,22 +89,22 @@ mod export { #[export(serialize_error)] fn send( #[try_from_ref] this: &NotificationConfig, - channel: &str, severity: Severity, title: String, body: String, - properties: Option, + template_data: Option, + fields: Option>, ) -> Result<(), HttpError> { let config = this.config.lock().unwrap(); - - let notification = Notification { + let notification = Notification::new_templated( severity, title, body, - properties, - }; + template_data.unwrap_or_default(), + fields.unwrap_or_default(), + ); - api::common::send(&config, channel, ¬ification) + api::common::send(&config, ¬ification) } #[export(serialize_error)] @@ -114,78 +116,6 @@ mod export { api::common::test_target(&config, target) } - #[export(serialize_error)] - fn get_groups( - #[try_from_ref] this: &NotificationConfig, - ) -> Result, HttpError> { - let config = this.config.lock().unwrap(); - api::group::get_groups(&config) - } - - #[export(serialize_error)] - fn get_group( - #[try_from_ref] this: &NotificationConfig, - id: &str, - ) -> Result { - let config = this.config.lock().unwrap(); - api::group::get_group(&config, id) - } - - #[export(serialize_error)] - fn add_group( - #[try_from_ref] this: &NotificationConfig, - name: String, - endpoints: Vec, - comment: Option, - filter: Option, - ) -> Result<(), HttpError> { - let mut config = this.config.lock().unwrap(); - api::group::add_group( - &mut config, - &GroupConfig { - name, - endpoint: endpoints, - comment, - filter, - }, - ) - } - - #[export(serialize_error)] - fn update_group( - #[try_from_ref] this: &NotificationConfig, - name: &str, - endpoints: Option>, - comment: Option, - filter: Option, - delete: Option>, - digest: Option<&str>, - ) -> Result<(), HttpError> { - let mut config = this.config.lock().unwrap(); - let digest = decode_digest(digest)?; - - api::group::update_group( - &mut config, - name, - &GroupConfigUpdater { - endpoint: endpoints, - comment, - filter, - }, - delete.as_deref(), - digest.as_deref(), - ) - } - - #[export(serialize_error)] - fn delete_group( - #[try_from_ref] this: &NotificationConfig, - name: &str, - ) -> Result<(), HttpError> { - let mut config = this.config.lock().unwrap(); - api::group::delete_group(&mut config, name) - } - #[export(serialize_error)] fn get_sendmail_endpoints( #[try_from_ref] this: &NotificationConfig, @@ -213,7 +143,6 @@ mod export { from_address: Option, author: Option, comment: Option, - filter: Option, ) -> Result<(), HttpError> { let mut config = this.config.lock().unwrap(); @@ -226,7 +155,7 @@ mod export { from_address, author, comment, - filter, + filter: None, }, ) } @@ -241,7 +170,6 @@ mod export { from_address: Option, author: Option, comment: Option, - filter: Option, delete: Option>, digest: Option<&str>, ) -> Result<(), HttpError> { @@ -257,7 +185,6 @@ mod export { from_address, author, comment, - filter, }, delete.as_deref(), digest.as_deref(), @@ -297,7 +224,6 @@ mod export { server: String, token: String, comment: Option, - filter: Option, ) -> Result<(), HttpError> { let mut config = this.config.lock().unwrap(); api::gotify::add_endpoint( @@ -306,7 +232,7 @@ mod export { name: name.clone(), server, comment, - filter, + filter: None, }, &GotifyPrivateConfig { name, token }, ) @@ -320,7 +246,6 @@ mod export { server: Option, token: Option, comment: Option, - filter: Option, delete: Option>, digest: Option<&str>, ) -> Result<(), HttpError> { @@ -330,11 +255,7 @@ mod export { api::gotify::update_endpoint( &mut config, name, - &GotifyConfigUpdater { - server, - comment, - filter, - }, + &GotifyConfigUpdater { server, comment }, &GotifyPrivateConfigUpdater { token }, delete.as_deref(), digest.as_deref(), @@ -351,38 +272,44 @@ mod export { } #[export(serialize_error)] - fn get_filters( + fn get_matchers( #[try_from_ref] this: &NotificationConfig, - ) -> Result, HttpError> { + ) -> Result, HttpError> { let config = this.config.lock().unwrap(); - api::filter::get_filters(&config) + api::matcher::get_matchers(&config) } #[export(serialize_error)] - fn get_filter( + fn get_matcher( #[try_from_ref] this: &NotificationConfig, id: &str, - ) -> Result { + ) -> Result { let config = this.config.lock().unwrap(); - api::filter::get_filter(&config, id) + api::matcher::get_matcher(&config, id) } #[export(serialize_error)] #[allow(clippy::too_many_arguments)] - fn add_filter( + fn add_matcher( #[try_from_ref] this: &NotificationConfig, name: String, - min_severity: Option, - mode: Option, + target: Option>, + match_severity: Option>, + match_field: Option>, + match_calendar: Option>, + mode: Option, invert_match: Option, comment: Option, ) -> Result<(), HttpError> { let mut config = this.config.lock().unwrap(); - api::filter::add_filter( + api::matcher::add_matcher( &mut config, - &FilterConfig { + &MatcherConfig { name, - min_severity, + match_severity, + match_field, + match_calendar, + target, mode, invert_match, comment, @@ -392,24 +319,30 @@ mod export { #[export(serialize_error)] #[allow(clippy::too_many_arguments)] - fn update_filter( + fn update_matcher( #[try_from_ref] this: &NotificationConfig, name: &str, - min_severity: Option, - mode: Option, + target: Option>, + match_severity: Option>, + match_field: Option>, + match_calendar: Option>, + mode: Option, invert_match: Option, comment: Option, - delete: Option>, + delete: Option>, digest: Option<&str>, ) -> Result<(), HttpError> { let mut config = this.config.lock().unwrap(); let digest = decode_digest(digest)?; - api::filter::update_filter( + api::matcher::update_matcher( &mut config, name, - &FilterConfigUpdater { - min_severity, + &MatcherConfigUpdater { + match_severity, + match_field, + match_calendar, + target, mode, invert_match, comment, @@ -420,12 +353,12 @@ mod export { } #[export(serialize_error)] - fn delete_filter( + fn delete_matcher( #[try_from_ref] this: &NotificationConfig, name: &str, ) -> Result<(), HttpError> { let mut config = this.config.lock().unwrap(); - api::filter::delete_filter(&mut config, name) + api::matcher::delete_matcher(&mut config, name) } #[export] -- 2.39.2