From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 9E3AC1FF0C0 for ; Wed, 18 Nov 2026 10:46:05 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id CB5AD2175E; Wed, 18 Nov 2026 10:44:51 +0100 (CET) From: Lukas Wagner To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox v2 17/63] notify: move check_matches from api_types::matcher to send::Bus Date: Wed, 18 Nov 2026 10:43:01 +0100 Message-ID: <20261118094348.273646-18-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261118094348.273646-1-l.wagner@proxmox.com> References: <20261118094348.273646-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794995036988 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.197 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: UZEUPJMNJ7C4NI7A77PSABLSH4UPMKKP X-Message-ID-Hash: UZEUPJMNJ7C4NI7A77PSABLSH4UPMKKP X-MailFrom: l.wagner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Evaluating all matchers and gathering a set of targets that are to be notified is only really needed when sending, and not as part of the API types. Signed-off-by: Lukas Wagner --- proxmox-notify/src/api_types/matcher/mod.rs | 41 --------------------- proxmox-notify/src/send.rs | 40 +++++++++++++++++++- 2 files changed, 38 insertions(+), 43 deletions(-) diff --git a/proxmox-notify/src/api_types/matcher/mod.rs b/proxmox-notify/src/api_types/matcher/mod.rs index c88ae09cd..dd9a987f4 100644 --- a/proxmox-notify/src/api_types/matcher/mod.rs +++ b/proxmox-notify/src/api_types/matcher/mod.rs @@ -1,9 +1,7 @@ -use std::collections::HashSet; use std::fmt::Debug; use proxmox_match_expression::Expression; use serde::{Deserialize, Serialize}; -use tracing::{error, info}; use proxmox_api_macro::api; use proxmox_schema::Updater; @@ -386,45 +384,6 @@ pub enum DeleteableMatcherProperty { Target, } -pub fn check_matches<'a>( - matchers: &'a [MatcherConfig], - notification: &Notification, -) -> HashSet<&'a str> { - let mut targets = HashSet::new(); - let mut matching_matchers = Vec::new(); - - for matcher in matchers { - if matcher.disable.unwrap_or_default() { - // Skip this matcher if it is disabled - info!("skipping disabled matcher '{name}'", name = matcher.name); - continue; - } - - match matcher.matches(notification) { - Ok(Some(t)) => { - matching_matchers.push(matcher.name.as_str()); - targets.extend(t.iter().map(|s| s.as_str())); - } - Ok(None) => {} - Err(err) => error!("matcher '{matcher}' failed: {err}", matcher = matcher.name), - } - } - - if !matching_matchers.is_empty() { - let target_list = Vec::from_iter(targets.iter().copied()); - - info!( - "notification matched the following matchers: {}. The following targets will be notified: {}", - matching_matchers.join(", "), - target_list.join(", ") - ); - } else { - info!("notification was not matched by any matcher"); - } - - targets -} - #[cfg(test)] mod tests { use super::*; diff --git a/proxmox-notify/src/send.rs b/proxmox-notify/src/send.rs index 3ef63aa8c..3cb9444c2 100644 --- a/proxmox-notify/src/send.rs +++ b/proxmox-notify/src/send.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use proxmox_uuid::Uuid; use serde::Deserialize; @@ -187,7 +187,7 @@ impl Bus { /// /// Any errors will not be returned but only logged. pub fn send(&self, context: &Context, notification: &Notification) { - let targets = crate::api_types::check_matches(self.matchers.as_slice(), notification); + let targets = self.check_matches(notification); for target in targets { if let Some(endpoint) = self.endpoints.get(target) { @@ -241,6 +241,42 @@ impl Bus { Ok(()) } + + fn check_matches(&self, notification: &Notification) -> HashSet<&str> { + let mut targets = HashSet::new(); + let mut matching_matchers = Vec::new(); + + for matcher in &self.matchers { + if matcher.disable.unwrap_or_default() { + // Skip this matcher if it is disabled + info!("skipping disabled matcher '{name}'", name = matcher.name); + continue; + } + + match matcher.matches(notification) { + Ok(Some(t)) => { + matching_matchers.push(matcher.name.as_str()); + targets.extend(t.iter().map(|s| s.as_str())); + } + Ok(None) => {} + Err(err) => error!("matcher '{matcher}' failed: {err}", matcher = matcher.name), + } + } + + if !matching_matchers.is_empty() { + let target_list = Vec::from_iter(targets.iter().copied()); + + info!( + "notification matched the following matchers: {}. The following targets will be notified: {}", + matching_matchers.join(", "), + target_list.join(", ") + ); + } else { + info!("notification was not matched by any matcher"); + } + + targets + } } #[cfg(test)] -- 2.47.3