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 203431FF0E6 for ; Fri, 24 Jul 2026 08:47:18 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id E5127214AD; Fri, 24 Jul 2026 08:47:17 +0200 (CEST) Date: Fri, 24 Jul 2026 08:47:10 +0200 From: Arthur Bied-Charreton To: Lukas Wagner Subject: Re: [PATCH proxmox 14/29] notify: migrate PBS's and PVE's default matcher to expression syntax Message-ID: References: <20260709115716.299836-1-l.wagner@proxmox.com> <20260709115716.299836-15-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260709115716.299836-15-l.wagner@proxmox.com> X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1784875600707 X-SPAM-LEVEL: Spam detection results: 0 AWL 1.069 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_LOW -0.7 Sender listed at https://www.dnswl.org/, low 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: WAOMQA52VQDCYU4NEAFWIZE2ZWVMJSWW X-Message-ID-Hash: WAOMQA52VQDCYU4NEAFWIZE2ZWVMJSWW X-MailFrom: a.bied-charreton@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 CC: pbs-devel@lists.proxmox.com, pve-devel@lists.proxmox.com X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Backup Server development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Thu, Jul 09, 2026 at 01:57:01PM +0200, Lukas Wagner wrote: > Instead of providing the default matcher expression as a JSON blob, we > programmatically construct the appropricate SectionConfigData entity. > This required a change of the Context trait, now the default_config > method returns &'static SectionConfigData instead of &'static str. > > The actual SectionConfigData entity is only constructed once and then > stored in a OnceLock. > > A nice side-effect of this change is that the config-parsing code path > is more efficient, since we don't have to deserialize the default config > over and over again. > one comment inline > Signed-off-by: Lukas Wagner > --- > proxmox-notify/src/context/mod.rs | 4 +- > proxmox-notify/src/context/pbs.rs | 87 ++++++++++++++++++++------ > proxmox-notify/src/context/pve.rs | 67 +++++++++++++++----- > proxmox-notify/src/context/test.rs | 9 ++- > proxmox-notify/src/lib.rs | 6 +- > proxmox-notify/src/matcher/calendar.rs | 9 ++- > proxmox-notify/src/matcher/field.rs | 11 +++- > proxmox-notify/src/matcher/severity.rs | 10 ++- > 8 files changed, 157 insertions(+), 46 deletions(-) > > diff --git a/proxmox-notify/src/context/mod.rs b/proxmox-notify/src/context/mod.rs > index 87a2a716..70c3a567 100644 > --- a/proxmox-notify/src/context/mod.rs > +++ b/proxmox-notify/src/context/mod.rs > @@ -1,6 +1,8 @@ > use std::fmt::Debug; > use std::sync::Mutex; > > +use proxmox_section_config::SectionConfigData; > + > use crate::Error; > use crate::renderer::TemplateSource; > > @@ -24,7 +26,7 @@ pub trait Context: Send + Sync + Debug { > /// Proxy configuration for the current node > fn http_proxy_config(&self) -> Option; > /// Return default config for built-in targets/matchers. > - fn default_config(&self) -> &'static str; > + fn default_config(&self) -> &'static SectionConfigData; > /// Return the path of `filename` from `source` and a certain (optional) `namespace` > fn lookup_template( > &self, > diff --git a/proxmox-notify/src/context/pbs.rs b/proxmox-notify/src/context/pbs.rs > index a9121548..b2561ad1 100644 > --- a/proxmox-notify/src/context/pbs.rs > +++ b/proxmox-notify/src/context/pbs.rs > @@ -1,14 +1,19 @@ > use std::path::Path; > +use std::sync::OnceLock; > > use serde::Deserialize; > use tracing::error; > > use proxmox_schema::{ObjectSchema, Schema, StringSchema}; > -use proxmox_section_config::{SectionConfig, SectionConfigPlugin}; > +use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; > > -use crate::Error; > use crate::context::{Context, common}; > +use crate::endpoints::sendmail::{SENDMAIL_TYPENAME, SendmailConfig}; > +use crate::matcher::field::FieldMatcher; > +use crate::matcher::severity::SeverityMatcher; > +use crate::matcher::{MATCHER_TYPENAME, MatcherConfig}; > use crate::renderer::TemplateSource; > +use crate::{Error, Severity}; > > const PBS_USER_CFG_FILENAME: &str = "/etc/proxmox-backup/user.cfg"; > const PBS_NODE_CFG_FILENAME: &str = "/etc/proxmox-backup/node.cfg"; > @@ -60,21 +65,6 @@ fn lookup_mail_address(content: &str, username: &str) -> Option { > } > } > > -const DEFAULT_CONFIG: &str = "\ > -sendmail: mail-to-root > - comment Send mails to root@pam's email address > - mailto-user root@pam > - > - > -matcher: default-matcher > - mode all > - invert-match true > - match-field exact:type=prune > - match-severity info > - target mail-to-root > - comment Route everything but successful prune job notifications to mail-to-root > -"; > - > #[derive(Debug)] > pub struct PBSContext; > > @@ -102,8 +92,67 @@ impl Context for PBSContext { > content.and_then(|content| common::lookup_datacenter_config_key(&content, "http-proxy")) > } > > - fn default_config(&self) -> &'static str { > - DEFAULT_CONFIG > + fn default_config(&self) -> &'static SectionConfigData { > + static DEFAULT_CONFIG: OnceLock = OnceLock::new(); > + DEFAULT_CONFIG.get_or_init(|| { > + // FIXME: Long-term we want to move the trait implementation to the product, > + // maybe add some nice builder to construct the default config. > + // Moving this as-is to the product would expose a lot of internals > + // to the product. > + > + let mut config = SectionConfigData::default(); > + config > + .set_data( > + "mail-to-root", > + SENDMAIL_TYPENAME, > + SendmailConfig { > + name: "mail-to-root".into(), > + mailto_user: vec!["root@pam".into()], > + comment: Some("Send mails to root@pam's email address".into()), > + ..Default::default() > + }, > + ) > + .expect("failed to set 'mail-to-root' in default config"); > + > + use proxmox_match_expression::{not, any_of, all_of}; > + > + let expression = any_of![ > + not!( > + FieldMatcher::Exact { > + field: "type".into(), > + values: vec!["prune".into()], > + }.into() > + ), > + all_of![ > + FieldMatcher::Exact { > + field: "type".into(), > + values: vec!["prune".into()], > + }.into(), > + SeverityMatcher { > + severities: vec![Severity::Error, Severity::Warning], > + }.into(), > + ], > + ]; > + > + let expression = serde_json::to_string(&expression) > + .expect("failed serialize expression for 'default-matcher'"); > + > + config > + .set_data( > + "default-matcher", > + MATCHER_TYPENAME, > + MatcherConfig { > + name: "default-matcher".into(), > + expression: Some(expression), > + target: vec!["mail-to-root".into()], > + comment: Some("Route everything but successful prune job notifications to mail-to-root".into()), > + ..Default::default() > + }, > + ) > + .expect("failed to set 'default-matcher' in default config"); > + > + config > + }) > } afaict the default changes from 'suppress prune info notifications' to 'for prune notifications, only notify on error or warning'. not very familiar with the notifications sent by PBS, i assume prune jobs never send notice-level notifications? > > fn lookup_template( [...]