From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 3ADB61FF0B7 for ; Fri, 13 Nov 2026 16:16:03 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 9DC4421C01; Fri, 13 Nov 2026 16:10:14 +0100 (CET) From: Lukas Wagner To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox-perl-rs 48/55] pve: notify: add `PVE::RS::Notify::enqueue` method Date: Fri, 13 Nov 2026 16:08:21 +0100 Message-ID: <20261113150828.756836-49-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261113150828.756836-1-l.wagner@proxmox.com> References: <20261113150828.756836-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: 1794582529120 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.202 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: G67JJT72TTL5KP4ZBNFU67N3WBS5KA4G X-Message-ID-Hash: G67JJT72TTL5KP4ZBNFU67N3WBS5KA4G 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: This finally gives us a way to send notifications from unprivileged processes (one needs to be root to read the priv/notifications.cfg file), as well as without blocking (especially important for the HA CRM, since there we send fencing notifications in the same update loop which also resets the software watchdog). Signed-off-by: Lukas Wagner --- pve-rs/Cargo.toml | 2 +- pve-rs/src/bindings/notify.rs | 68 +++++++++++++++++++++++++++++++++-- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/pve-rs/Cargo.toml b/pve-rs/Cargo.toml index f8982e2..ed7d0e4 100644 --- a/pve-rs/Cargo.toml +++ b/pve-rs/Cargo.toml @@ -39,7 +39,7 @@ proxmox-http = { version = "1.0.2", features = ["client-sync", "client-trait"] } proxmox-http-error = "1" proxmox-log = "1" proxmox-network-types = "1.1.2" -proxmox-notify = { version = "2", features = [ "api-impl", "legacy-matchers", "pve-context", "send-impl" ] } +proxmox-notify = { version = "2", features = [ "api-impl", "legacy-matchers", "pve-context", "queue-submitter", "send-impl" ] } proxmox-oci = "0.2.2" proxmox-openid = "1.0.2" proxmox-resource-scheduling = "2" diff --git a/pve-rs/src/bindings/notify.rs b/pve-rs/src/bindings/notify.rs index a5faa93..6c494d9 100644 --- a/pve-rs/src/bindings/notify.rs +++ b/pve-rs/src/bindings/notify.rs @@ -12,7 +12,9 @@ pub mod pve_rs_notify { use std::collections::HashMap; use std::sync::Mutex; - use anyhow::{Error, bail}; + use anyhow::{Context, Error, bail}; + use nix::sys::stat::Mode; + use nix::unistd::{Group, User}; use serde_json::{Value as JSONValue, json}; use perlmod::Value; @@ -25,8 +27,10 @@ pub mod pve_rs_notify { SendmailConfig, SendmailConfigUpdater, SmtpConfig, SmtpConfigUpdater, SmtpPrivateConfig, SmtpPrivateConfigUpdater, Target, TargetReceiptStatus, WebhookConfig, WebhookConfigUpdater, }; - use proxmox_notify::{Config, Notification, Recipient, Severity, api}; + use proxmox_notify::queue::QueueSubmitter; + use proxmox_notify::{Config, EmailRecipient, Notification, Recipient, Severity, api}; use proxmox_notify::{http_bail, http_err}; + use proxmox_sys::fs::CreateOptions; /// A notification configuration instance. /// @@ -557,4 +561,64 @@ pub mod pve_rs_notify { let config = this.config.lock().unwrap(); api::common::get_referenced_entities(&config, name) } + + /// Send a notification by submitting it to the product's notification + /// queue. + /// + /// A dedicated worker task (pve-notify-worker) regularly processes any + /// queued notification and sends them to the appropriate destinations. + /// + /// If `recipient` is set, the `recipient` field will be set + /// to [`Recipient::Email`] with the provided [`EmailRecipient`]. This is + /// to support the old, legacy-sendmail mode also for notifications sent + /// through the notification worker. + /// + /// # Errors + /// + /// - The notification could not be serialized + /// - The serialized notification could not be written to the queue (e.g. permissions of the + /// queue directory are set wrong, the directory does not exist, etc.) + #[export] + pub fn enqueue( + severity: Severity, + template_name: String, + template_data: Option, + fields: Option>, + recipient: Option, + ) -> Result<(), anyhow::Error> { + const QUEUE_BASE_PATH: &str = "/var/lib/pve-manager/notifications/queue"; + + let mut notification_builder = + Notification::template_builder(template_name, template_data.unwrap_or_default()) + .severity(severity) + .fields(fields.unwrap_or_default()); + + if let Some(recipient) = recipient { + notification_builder = notification_builder.recipient(Recipient::Email(recipient)); + } + + let notification = notification_builder.build()?; + + let queue = QueueSubmitter::new(QUEUE_BASE_PATH, queue_file_options()?); + queue.submit(¬ification)?; + + Ok(()) + } + + fn queue_file_options() -> Result { + let uid = User::from_name("www-data") + .context("could not look up username 'www-data'")? + .context("user 'www-data' does not exist")? + .uid; + + let gid = Group::from_name("www-data") + .context("could not look up group 'www-data'")? + .context("group 'www-data' does not exist")? + .gid; + + Ok(CreateOptions::new() + .owner(uid) + .group(gid) + .perm(Mode::from_bits_truncate(0o660))) + } } -- 2.47.3