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 678D21FF0C0 for ; Wed, 18 Nov 2026 10:48:48 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id B715F21AEF; Wed, 18 Nov 2026 10:45:01 +0100 (CET) From: Lukas Wagner To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox-backup v2 47/63] api: notification: send test notification via proxmox_notify::send Date: Wed, 18 Nov 2026 10:43:31 +0100 Message-ID: <20261118094348.273646-48-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: 1794995040982 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.191 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: 46X5GIX5EILI6262KWIEFTYTV3IXT3ZD X-Message-ID-Hash: 46X5GIX5EILI6262KWIEFTYTV3IXT3ZD 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: proxmox-notify dropped its test_target function, since a notification can now be addressed to a single target directly, without involving any matchers. Testing a disabled target has always been possible, so force-enable the target via the new proxmox_notify::api::set_entity_disabled before sending; otherwise, the test notification would never be delivered. This change only affects the in-memory copy of the configuration and is never written to disk. Signed-off-by: Lukas Wagner --- src/api2/config/notifications/targets.rs | 39 ++++++++++++++++++++---- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/api2/config/notifications/targets.rs b/src/api2/config/notifications/targets.rs index bf0cfa3de..f523ae6ee 100644 --- a/src/api2/config/notifications/targets.rs +++ b/src/api2/config/notifications/targets.rs @@ -1,7 +1,10 @@ -use anyhow::Error; -use serde_json::Value; +use anyhow::{Context, Error, bail}; +use serde_json::{Value, json}; -use proxmox_notify::api_types::{ENTITY_NAME_SCHEMA, Target}; +use proxmox_notify::{ + Notification, Recipient, Severity, + api_types::{ENTITY_NAME_SCHEMA, Target, TargetReceiptStatus}, +}; use proxmox_router::{Permission, Router, RpcEnvironment, SubdirMap, list_subdirs_api_method}; use proxmox_schema::api; use proxmox_sortable_macro::sortable; @@ -48,10 +51,34 @@ pub fn list_targets(_param: Value, _rpcenv: &mut dyn RpcEnvironment) -> Result Result<(), Error> { let context = server::notifications::context(); + let mut config = pbs_config::notifications::config(context)?; - let config = pbs_config::notifications::config(context)?; - proxmox_notify::test_target(context, &config, &name)?; - Ok(()) + // Testing disabled targets must work too; the modified config is not persisted. + proxmox_notify::api::set_entity_disabled(&mut config, &name, false)?; + + let notification = Notification::template_builder("test", json!({ "target": &name })) + .severity(Severity::Info) + .recipient(Recipient::Target(name.clone())) + .build()?; + + let receipt = proxmox_notify::send(context, &config, ¬ification)?; + + match receipt + .target_receipts() + .first() + .context("target receipt array did not contain expected entry")? + .status() + { + TargetReceiptStatus::Delivered => Ok(()), + TargetReceiptStatus::Error { error_message } => { + bail!("could not test target: {error_message}") + } + TargetReceiptStatus::Disabled => { + bail!( + "target {name} disabled while sending test notification -- this should not happen" + ) + } + } } #[sortable] -- 2.47.3