public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker
@ 2026-11-18  9:42 Lukas Wagner
  2026-11-18  9:42 ` [PATCH proxmox v2 01/63] notify: disallow `unsafe` code Lukas Wagner
                   ` (63 more replies)
  0 siblings, 64 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:42 UTC (permalink / raw)
  To: pve-devel

The notification stack will soon be integrated into a new product (PDM), so it
makes sense to use this opportunity for any pending breaking changes and
general cleanup of the notification stack, partly driven by the worker
implementation, pending feature work (notification history), and overdue
maintenance work to reduce technical debt.

The introduction of a shared worker implementation lifts long-standing limitations in PVE,
where only the privileged process could send notifications. The worker will also be used
in PDM.

## Refactoring

- Refactoring the proxmox_notify::Error type
  Using the old type was quite annoying (one had to use Error::Generic nearly everywhere), the
  new one applies the lessons-learned from the old one.
  While this is technically a breaking change, none of the callers used returned errors
  other than logging/stringifying them, so the callers need no change

- Pass context along with calls, wrapped in a context wrapper type, instead of
  setting it via set_context

- Dropped features 
  - gotify
  - webhook
  - sendmail
  - smtp
  - mail-forwarder

  The intention was for products to be able to opt into the endpoints they need.
  Up until now, there was no instance of one endpoint type not being used
  by a product, hence they are dropped and replaced by a single 'send-impl'
  feature. If we ever introduce a type of endpoint that will only used
  by a single product, we can still introduce a new flag for this one.

- New feature flags
  - send-impl: everything needed to *send* a notification
  - api-impl: API handler implementations
  - api-types: API types; useful for the Rust-based PDM UI once we integrate it there
  - queue-submitter: facilities to submit a notification to the notiticiation queue
  - queue-worker: implementation of the notification worker and queue consumer

- restructuring of module paths
  - lib.rs was huge, so it was split up into appropriate submodules
  - api types were moved into an 'api_types' submodule

- cleanup of the public crate interface
  - many types didn't need to be public, so these were removed from the public
    interface to ease further maintenance

- switch to typed section config

- don't repeatedly re-parse builtin-configuration; do it once
  and store it a OnceLock

- offer builder for instantiating notifications. This allow us
  to extend notifications with new optional fields later.

- Notifications get a `recipient` field, where a recipient can be a the regular matcher
  system, a target, or a list of email addresses.

  The 'target' mode allows us to drop the special-cased 'test_target' API. Now, testing a
  a target is just a regular send, the 'send receipts' feature described later allows us
  continue reporting any error to the user when testing a target.

  The 'email' is a shortcut that creates an implicit 'sendmail' endpoint, which allows
  us to simplify the 'legacy-sendmail' mode in the application code. Now, it uses a
  regular proxmox_notify::send and does not need to fake a notification config first.

  The main motivation of this changes were the introduction of the notification queue and
  planning of the notification history. The 'recipient' approach allows us to unify
  a lot of code paths, removing special cases that would need to be considered.
  Now, *any* notification, goes through the queue and will be eventually be
  persisted in the notification queue.

## Features

- send receipts `proxmox_notify::send` did not return any indiciation whether
  the notification was sent successfully, it was only logged. This series now
  returns a 'receipt', that includes information about which matcher matched a
  notification, which targets were notified, including any errors (per target).
  Eventually, this receipt will also be recorded in the notification history,
  giving users a clear picture about which notification was sent when, where and
  why.

 - notification queue / worker PBS already used a queue-based approach for
  sending notifications from the unprivileged proxy process. This series adds a
  generic queue and worker implementation to proxmox_notify which can be used by
  all products (PVE and soon PDM). This resolves a long standing issue where a
  hanging notification send call would would block the cluster resource manager
  for possibly extended periods of time


## User-facing changes

 - The switch to the queue-based approach means that any log message produced
   by the notification stack will not be shown in a task log when sending a
   notification. For now, these will only show up the system logs. In the future,
   I'd like to integrate this with the notification history, in the history view
   it should be possible to retrieve the log messages that were logged for any
   notification (by entering a tracing span with the notification UUID set as a
   field, which makes it possible to filter the system log for messages for a
   specific notification)

  - In PVE, there is a new daemon 'pve-notify-worker'
    This one is the host for the notification worker task in PVE.

  - For forwarded emails:
    proxmox-mail-forward will now only forward each email once if multiple products
    are co-installed, with PVE taking precedence over PBS.

## Bumps

 - proxmox-notify should receive a major version bump (2 -> 3); the API breakage is deliberate
   for cleaning up tech debt and preparing for the integration in PDM.
 - libpve-rs-perl must depend on proxmox-notify v3
 - proxmox-backup must depend on proxmox-notify v3

 - pve-notify-worker needs a first release
 - libpve-notify-perl must depend on bumped libpve-rs-perl
   (enqueue method)
 - pve-manager must depend on bumped libpve-notify-perl
   (simplified interface for legacy-sendmail)

 - proxmox-mail-forward must depend on proxmox-notify v3

  - proxmox-mail-forward has a Breaks on pve-manager and proxmox-backup-server,
    must be adadpted when applying


Changes since v1:
  - Verify the template name via SAFE_ID_REGEX on construction and before sending a
    notification

  - stub CalendarMatcher::matches on wasm32 for now, just to make it compile.
    Later, we should go back and have a version of proxmox_time::DailyDuration
    that also works on wasm32

  - Use ConfigDigest::detect_verification

  - Move pve-notify-worker to the proxmox-mail-forward repo
    (we might rename the repo at some point)

  - Harden reading notifications in the worker (don't follow symlinks, maximum
    size of the notification file, etc.)


proxmox:

Lukas Wagner (44):
  notify: disallow `unsafe` code
  notify: refactor error type
  notify: move `Endpoint` trait to endpoint module as pub(crate)
  notify: use ConfigDigest instead of raw byte arrays
  notify: remove static context and pass context as parameter
  notify: matcher: drop unused field matcher verifiers
  notify: introduce 'send-impl', 'api-impl' and 'api-types' features
  notify: matcher: make matcher validation methods public
  notify: matcher: stub CalendarMatcher::matches on wasm32
  notify: make SendmailEndpoint and SmtpEndpoint private types
  notify: move `send`, `test_target` and `Bus` to new `send` module
  notify: move Origin type to api_types module
  notify: move Target type to api_types module
  notify: move Config to config module
  notify: move Notification and sub-types to `notification` module
  notify: move schema module to api_types
  notify: move check_matches from api_types::matcher to send::Bus
  notify: move TemplateSource to context module
  notify: config: cleanup helper names and visibility
  notify: config: rename section config parser/writer methods
  notify: config: pass builtins explicitly when parsing section config
  notify: implement PartialEq for all Config types
  notify: use typed SectionConfigData
  notify: api: api types: rename Deleteable* -> Deletable*
  notify: context: parse builtin config only once
  notify: context: parse proxy config in trait impl, not at the callsite
  notify: gate sub-modules with the appropriate feature flags
  notify: fold mail-forwarder feature into send-impl
  notify: forwarded mails: don't hardcode severity and metadata fields
  notify: don't pass uid when instantiating forwarded mail notifications
  notify: derive PartialEq for Notification type
  notify: add getters for severity and fields on Notification type
  notify: add test suite for Notification type
  notify: serialize raw, forwarded mail content as base64
  notify: unify code paths for legacy-sendmail and regular notifications
  notify: add backwards-compat note to Notification type
  notify: remove 'test_target' API
  notify: replace notification instantiation with builder pattern
  notify: add send receipts
  notify: make sure that template name matches SAFE_ID_REGEX
  notify: implement notification queue submitter
  notify: context: add read_config
  notify: queue: add queue consumer
  notify: queue: add worker task

 Cargo.toml                                    |   1 +
 proxmox-notify/Cargo.toml                     |  75 +-
 proxmox-notify/src/api/common.rs              |  42 +-
 proxmox-notify/src/api/gotify.rs              | 122 ++-
 proxmox-notify/src/api/matcher.rs             | 148 ++--
 proxmox-notify/src/api/mod.rs                 | 191 ++---
 proxmox-notify/src/api/sendmail.rs            |  76 +-
 proxmox-notify/src/api/smtp.rs                | 133 ++-
 proxmox-notify/src/api/webhook.rs             | 176 ++--
 proxmox-notify/src/api_types/gotify.rs        |  70 ++
 .../src/{ => api_types}/matcher/calendar.rs   |  34 +-
 .../src/{ => api_types}/matcher/expression.rs |   2 +-
 .../src/{ => api_types}/matcher/field.rs      | 101 ++-
 .../src/{ => api_types}/matcher/mod.rs        | 100 +--
 .../src/{ => api_types}/matcher/severity.rs   |  24 +-
 proxmox-notify/src/api_types/mod.rs           |  79 ++
 proxmox-notify/src/api_types/receipt.rs       | 138 ++++
 proxmox-notify/src/{ => api_types}/schema.rs  |   0
 proxmox-notify/src/api_types/sendmail.rs      |  95 +++
 proxmox-notify/src/api_types/smtp.rs          | 137 ++++
 proxmox-notify/src/api_types/webhook.rs       | 211 +++++
 proxmox-notify/src/config.rs                  | 358 +++++----
 proxmox-notify/src/context/mod.rs             |  79 +-
 proxmox-notify/src/context/pbs.rs             |  52 +-
 proxmox-notify/src/context/pve.rs             |  52 +-
 proxmox-notify/src/context/test.rs            |  50 +-
 proxmox-notify/src/endpoints/common/mail.rs   |  29 +-
 proxmox-notify/src/endpoints/common/mod.rs    |   1 -
 proxmox-notify/src/endpoints/gotify.rs        | 107 +--
 proxmox-notify/src/endpoints/mod.rs           |  20 +-
 proxmox-notify/src/endpoints/sendmail.rs      | 137 +---
 proxmox-notify/src/endpoints/smtp.rs          | 209 +----
 proxmox-notify/src/endpoints/webhook.rs       | 307 ++-----
 proxmox-notify/src/error.rs                   | 237 ++++++
 proxmox-notify/src/lib.rs                     | 754 +-----------------
 proxmox-notify/src/notification.rs            | 478 +++++++++++
 proxmox-notify/src/queue/consumer.rs          | 513 ++++++++++++
 proxmox-notify/src/queue/mod.rs               |  35 +
 proxmox-notify/src/queue/submitter.rs         | 171 ++++
 proxmox-notify/src/queue/worker.rs            | 640 +++++++++++++++
 proxmox-notify/src/renderer/mod.rs            |  44 +-
 proxmox-notify/src/send.rs                    | 489 ++++++++++++
 .../testdata/notifications-priv.cfg.ref       |   8 +
 proxmox-notify/testdata/notifications.cfg.ref |  29 +
 44 files changed, 4524 insertions(+), 2230 deletions(-)
 create mode 100644 proxmox-notify/src/api_types/gotify.rs
 rename proxmox-notify/src/{ => api_types}/matcher/calendar.rs (77%)
 rename proxmox-notify/src/{ => api_types}/matcher/expression.rs (98%)
 rename proxmox-notify/src/{ => api_types}/matcher/field.rs (73%)
 rename proxmox-notify/src/{ => api_types}/matcher/mod.rs (84%)
 rename proxmox-notify/src/{ => api_types}/matcher/severity.rs (83%)
 create mode 100644 proxmox-notify/src/api_types/mod.rs
 create mode 100644 proxmox-notify/src/api_types/receipt.rs
 rename proxmox-notify/src/{ => api_types}/schema.rs (100%)
 create mode 100644 proxmox-notify/src/api_types/sendmail.rs
 create mode 100644 proxmox-notify/src/api_types/smtp.rs
 create mode 100644 proxmox-notify/src/api_types/webhook.rs
 create mode 100644 proxmox-notify/src/error.rs
 create mode 100644 proxmox-notify/src/notification.rs
 create mode 100644 proxmox-notify/src/queue/consumer.rs
 create mode 100644 proxmox-notify/src/queue/mod.rs
 create mode 100644 proxmox-notify/src/queue/submitter.rs
 create mode 100644 proxmox-notify/src/queue/worker.rs
 create mode 100644 proxmox-notify/src/send.rs
 create mode 100644 proxmox-notify/testdata/notifications-priv.cfg.ref
 create mode 100644 proxmox-notify/testdata/notifications.cfg.ref


proxmox-backup:

Lukas Wagner (4):
  notifications: don't ignore verification errors in legacy-sendmail
    mode
  notifications: adapt to proxmox-notify API changes
  api: notification: send test notification via proxmox_notify::send
  notifications: send all notifications via proxmox-notify's queue

 Cargo.toml                                    |  13 +-
 pbs-config/Cargo.toml                         |  10 +-
 pbs-config/src/notifications.rs               |  10 +-
 src/api2/config/notifications/gotify.rs       |  31 +-
 src/api2/config/notifications/matchers.rs     |  29 +-
 src/api2/config/notifications/sendmail.rs     |  29 +-
 src/api2/config/notifications/smtp.rs         |  29 +-
 src/api2/config/notifications/targets.rs      |  46 +-
 src/api2/config/notifications/webhook.rs      |  29 +-
 src/bin/docgen.rs                             |   7 +-
 src/bin/proxmox-backup-api.rs                 |   3 +-
 src/bin/proxmox-backup-manager.rs             |   1 -
 src/bin/proxmox-backup-proxy.rs               |   1 -
 src/bin/proxmox-daily-update.rs               |   3 -
 .../notifications/gotify.rs                   |   2 +-
 .../notifications/matchers.rs                 |   2 +-
 .../notifications/sendmail.rs                 |   2 +-
 .../notifications/smtp.rs                     |   2 +-
 .../notifications/webhook.rs                  |   2 +-
 src/server/notifications/mod.rs               | 595 ++++++++----------
 tests/data/serialized_notification.json       |   1 +
 tests/notifications.rs                        |  11 +
 22 files changed, 436 insertions(+), 422 deletions(-)
 create mode 100644 tests/data/serialized_notification.json
 create mode 100644 tests/notifications.rs


proxmox-perl-rs:

Lukas Wagner (2):
  pve: notify: adapt to changes in the public API of proxmox-notify
  pve: notify: add `PVE::RS::Notify::enqueue` method

 pve-rs/Cargo.toml             |   2 +-
 pve-rs/src/bindings/mod.rs    |   3 -
 pve-rs/src/bindings/notify.rs | 237 +++++++++++++++++++++++-----------
 pve-rs/src/lib.rs             |  29 +++--
 4 files changed, 179 insertions(+), 92 deletions(-)


pve-cluster:

Lukas Wagner (1):
  notify: send notifications via notification queue

 src/PVE/Notify.pm | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)


pve-manager:

Lukas Wagner (5):
  vzdump: send legacy-sendmail notifications via simplified API
  debian: create notification queue directory via tmpfiles
  debian: add 'pve-notify-worker' as dependecy
  api: services: add 'pve-notify-worker' as known service
  services: request pve-notify-worker.service via Wants

 PVE/API2/Services.pm          |  1 +
 PVE/VZDump.pm                 | 28 ++--------------------------
 debian/control                |  1 +
 debian/tmpfiles               |  5 +++--
 services/pvedaemon.service    |  2 +-
 services/pvescheduler.service |  1 +
 6 files changed, 9 insertions(+), 29 deletions(-)


proxmox-mail-forward:

Lukas Wagner (7):
  forward mails via notification queue
  use return code to signal permanent or temporary failure
  limit size of mail read from stdin
  cargo: move mail forwarder into a workspace member crate
  add crate for code shared between the mail-forwarder and the worker
  add pve-notify-worker crate and package
  debian: add versioned break for pve-manager and proxmox-backup-server

 Cargo.toml                          |  26 ++--
 Makefile                            |  17 ++-
 common/Cargo.toml                   |  13 ++
 common/src/lib.rs                   |  78 ++++++++++
 debian/control                      |   8 ++
 debian/proxmox-mail-forward.install |   1 +
 debian/pve-notify-worker.install    |   1 +
 debian/pve-notify-worker.service    |  13 ++
 debian/rules                        |   6 +-
 proxmox-mail-forward/Cargo.toml     |  18 +++
 proxmox-mail-forward/src/main.rs    | 212 ++++++++++++++++++++++++++++
 pve-notify-worker/Cargo.toml        |  21 +++
 pve-notify-worker/src/main.rs       |  64 +++++++++
 src/main.rs                         | 149 -------------------
 14 files changed, 458 insertions(+), 169 deletions(-)
 create mode 100644 common/Cargo.toml
 create mode 100644 common/src/lib.rs
 create mode 100644 debian/proxmox-mail-forward.install
 create mode 100644 debian/pve-notify-worker.install
 create mode 100644 debian/pve-notify-worker.service
 create mode 100644 proxmox-mail-forward/Cargo.toml
 create mode 100644 proxmox-mail-forward/src/main.rs
 create mode 100644 pve-notify-worker/Cargo.toml
 create mode 100644 pve-notify-worker/src/main.rs
 delete mode 100644 src/main.rs


Summary over all repositories:
  91 files changed, 5622 insertions(+), 2944 deletions(-)

-- 
Generated by murpp 0.12.1




^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 01/63] notify: disallow `unsafe` code
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
@ 2026-11-18  9:42 ` Lukas Wagner
  2026-11-18  9:42 ` [PATCH proxmox v2 02/63] notify: refactor error type Lukas Wagner
                   ` (62 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:42 UTC (permalink / raw)
  To: pve-devel

There is no good reason to allow unsafe in this crate. If we ever really
need it, we can still add #[allow(unsafe_code)] locally.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/lib.rs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/proxmox-notify/src/lib.rs b/proxmox-notify/src/lib.rs
index cc22bb8e9..1ce6f89e6 100644
--- a/proxmox-notify/src/lib.rs
+++ b/proxmox-notify/src/lib.rs
@@ -1,4 +1,5 @@
 #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
+#![deny(unsafe_code)]
 
 use std::collections::HashMap;
 use std::error::Error as StdError;
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 02/63] notify: refactor error type
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
  2026-11-18  9:42 ` [PATCH proxmox v2 01/63] notify: disallow `unsafe` code Lukas Wagner
@ 2026-11-18  9:42 ` Lukas Wagner
  2026-11-18  9:42 ` [PATCH proxmox v2 03/63] notify: move `Endpoint` trait to endpoint module as pub(crate) Lukas Wagner
                   ` (61 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:42 UTC (permalink / raw)
  To: pve-devel

The old Error type was quite annoying to use which is why it was
replaced by a new one. Instead of manually implementing the expected
interfaces, this time we use the `thiserror` crate to derive the
appropriate implementations.

While this is technically a breaking change, none of the existing users
of proxmox-notify match on any concrete error variants, so this change
does not require any modifications in application code. Some error
messages change slightly due to the restructuring of error variants.

One noteworthy change is that the implementations of the Context trait
do not return `Error` anymore, instead, they return a Box<dyn Error>,
which is then wrapped into an appropriate variant of the crate-owned
Error type wherever a context method is called. This is a deliberate
design decision. Eventually, the implementations of Context should live
in the application code, and I want to refrain from instantiating
proxmox_notify::Error in application code.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/Cargo.toml                |   1 +
 proxmox-notify/src/api/common.rs         |   4 +-
 proxmox-notify/src/config.rs             |   9 +-
 proxmox-notify/src/context/mod.rs        |   9 +-
 proxmox-notify/src/context/pbs.rs        |   8 +-
 proxmox-notify/src/context/pve.rs        |  13 +-
 proxmox-notify/src/context/test.rs       |   4 +-
 proxmox-notify/src/endpoints/gotify.rs   |   7 +-
 proxmox-notify/src/endpoints/sendmail.rs |  10 +-
 proxmox-notify/src/endpoints/smtp.rs     |  42 +++---
 proxmox-notify/src/endpoints/webhook.rs  |  44 +++---
 proxmox-notify/src/error.rs              | 165 +++++++++++++++++++++++
 proxmox-notify/src/lib.rs                |  75 +----------
 proxmox-notify/src/matcher/calendar.rs   |   4 +-
 proxmox-notify/src/matcher/field.rs      |  29 ++--
 proxmox-notify/src/matcher/mod.rs        |  22 +--
 proxmox-notify/src/matcher/severity.rs   |   8 +-
 proxmox-notify/src/renderer/mod.rs       |  11 +-
 18 files changed, 294 insertions(+), 171 deletions(-)
 create mode 100644 proxmox-notify/src/error.rs

diff --git a/proxmox-notify/Cargo.toml b/proxmox-notify/Cargo.toml
index 326f5f9e5..6796c2915 100644
--- a/proxmox-notify/Cargo.toml
+++ b/proxmox-notify/Cargo.toml
@@ -25,6 +25,7 @@ regex.workspace = true
 serde = { workspace = true, features = ["derive"] }
 serde_json.workspace = true
 serde_regex.workspace = true
+thiserror.workspace = true
 
 proxmox-api-macro.workspace = true
 proxmox-base64 = { workspace = true, optional = true }
diff --git a/proxmox-notify/src/api/common.rs b/proxmox-notify/src/api/common.rs
index fa2356e2a..bc89695f8 100644
--- a/proxmox-notify/src/api/common.rs
+++ b/proxmox-notify/src/api/common.rs
@@ -1,7 +1,7 @@
 use proxmox_http_error::HttpError;
 
 use super::http_err;
-use crate::{Bus, Config, Notification};
+use crate::{Bus, Config, Error, Notification};
 
 /// Send a notification to a given target.
 ///
@@ -33,7 +33,7 @@ pub fn test_target(config: &Config, endpoint: &str) -> Result<(), HttpError> {
     })?;
 
     bus.test_target(endpoint).map_err(|err| match err {
-        crate::Error::TargetDoesNotExist(endpoint) => {
+        Error::TargetDoesNotExist(endpoint) => {
             http_err!(NOT_FOUND, "endpoint '{endpoint}' does not exist")
         }
         _ => http_err!(INTERNAL_SERVER_ERROR, "Could not test target: {err}"),
diff --git a/proxmox-notify/src/config.rs b/proxmox-notify/src/config.rs
index 952e77262..c280e8285 100644
--- a/proxmox-notify/src/config.rs
+++ b/proxmox-notify/src/config.rs
@@ -124,7 +124,7 @@ pub fn config(raw_config: &str) -> Result<(SectionConfigData, [u8; 32]), Error>
     let digest = openssl::sha::sha256(raw_config.as_bytes());
     let data = config_parser()
         .parse("notifications.cfg", raw_config)
-        .map_err(|err| Error::ConfigDeserialization(err.into()))?;
+        .map_err(Error::config_deserialization)?;
 
     Ok((data, digest))
 }
@@ -133,18 +133,19 @@ pub fn private_config(raw_config: &str) -> Result<(SectionConfigData, [u8; 32]),
     let digest = openssl::sha::sha256(raw_config.as_bytes());
     let data = private_config_parser()
         .parse("priv/notifications.cfg", raw_config)
-        .map_err(|err| Error::ConfigDeserialization(err.into()))?;
+        .map_err(Error::config_deserialization)?;
+
     Ok((data, digest))
 }
 
 pub fn write(config: &SectionConfigData) -> Result<String, Error> {
     config_parser()
         .write("notifications.cfg", config)
-        .map_err(|err| Error::ConfigSerialization(err.into()))
+        .map_err(Error::config_serialization)
 }
 
 pub fn write_private(config: &SectionConfigData) -> Result<String, Error> {
     private_config_parser()
         .write("priv/notifications.cfg", config)
-        .map_err(|err| Error::ConfigSerialization(err.into()))
+        .map_err(Error::config_serialization)
 }
diff --git a/proxmox-notify/src/context/mod.rs b/proxmox-notify/src/context/mod.rs
index 87a2a7165..a81a35caa 100644
--- a/proxmox-notify/src/context/mod.rs
+++ b/proxmox-notify/src/context/mod.rs
@@ -1,7 +1,7 @@
 use std::fmt::Debug;
 use std::sync::Mutex;
 
-use crate::Error;
+use crate::error::BoxedError;
 use crate::renderer::TemplateSource;
 
 #[cfg(any(feature = "pve-context", feature = "pbs-context"))]
@@ -13,6 +13,11 @@ pub mod pve;
 #[cfg(test)]
 mod test;
 
+// NOTE: Don't use proxmox_notify::Error in this trait, rather return a [`BoxedError`]. You
+// may wrap the boxed error into an appropriate variant of proxmox_notify::Error at
+// the callsite, but product-code (which includes the trait implementations of Context) should
+// not have to instantiate proxmox_notify::Error themselves.
+
 /// Product-specific context
 pub trait Context: Send + Sync + Debug {
     /// Look up a user's email address from users.cfg
@@ -31,7 +36,7 @@ pub trait Context: Send + Sync + Debug {
         filename: &str,
         namespace: Option<&str>,
         source: TemplateSource,
-    ) -> Result<Option<String>, Error>;
+    ) -> Result<Option<String>, BoxedError>;
 }
 
 #[cfg(not(test))]
diff --git a/proxmox-notify/src/context/pbs.rs b/proxmox-notify/src/context/pbs.rs
index a91215488..f484f90c8 100644
--- a/proxmox-notify/src/context/pbs.rs
+++ b/proxmox-notify/src/context/pbs.rs
@@ -6,8 +6,8 @@ use tracing::error;
 use proxmox_schema::{ObjectSchema, Schema, StringSchema};
 use proxmox_section_config::{SectionConfig, SectionConfigPlugin};
 
-use crate::Error;
 use crate::context::{Context, common};
+use crate::error::BoxedError;
 use crate::renderer::TemplateSource;
 
 const PBS_USER_CFG_FILENAME: &str = "/etc/proxmox-backup/user.cfg";
@@ -111,7 +111,7 @@ impl Context for PBSContext {
         filename: &str,
         namespace: Option<&str>,
         source: TemplateSource,
-    ) -> Result<Option<String>, Error> {
+    ) -> Result<Option<String>, BoxedError> {
         let path = match source {
             TemplateSource::Vendor => "/usr/share/proxmox-backup/templates",
             TemplateSource::Override => "/etc/proxmox-backup/notification-templates",
@@ -121,8 +121,8 @@ impl Context for PBSContext {
             .join(namespace.unwrap_or("default"))
             .join(filename);
 
-        let template_string = proxmox_sys::fs::file_read_optional_string(path)
-            .map_err(|err| Error::Generic(format!("could not load template: {err}")))?;
+        let template_string = proxmox_sys::fs::file_read_optional_string(path)?;
+
         Ok(template_string)
     }
 }
diff --git a/proxmox-notify/src/context/pve.rs b/proxmox-notify/src/context/pve.rs
index 3d9ff92e9..ba84da920 100644
--- a/proxmox-notify/src/context/pve.rs
+++ b/proxmox-notify/src/context/pve.rs
@@ -1,8 +1,9 @@
-use crate::Error;
-use crate::context::{Context, common};
-use crate::renderer::TemplateSource;
 use std::path::Path;
 
+use crate::context::{Context, common};
+use crate::error::BoxedError;
+use crate::renderer::TemplateSource;
+
 fn lookup_mail_address(content: &str, user: &str) -> Option<String> {
     common::normalize_for_return(content.lines().find_map(|line| {
         let fields: Vec<&str> = line.split(':').collect();
@@ -60,7 +61,7 @@ impl Context for PVEContext {
         filename: &str,
         namespace: Option<&str>,
         source: TemplateSource,
-    ) -> Result<Option<String>, Error> {
+    ) -> Result<Option<String>, BoxedError> {
         let path = match source {
             TemplateSource::Vendor => "/usr/share/pve-manager/templates",
             TemplateSource::Override => "/etc/pve/notification-templates",
@@ -70,8 +71,8 @@ impl Context for PVEContext {
             .join(namespace.unwrap_or("default"))
             .join(filename);
 
-        let template_string = proxmox_sys::fs::file_read_optional_string(path)
-            .map_err(|err| Error::Generic(format!("could not load template: {err}")))?;
+        let template_string = proxmox_sys::fs::file_read_optional_string(path)?;
+
         Ok(template_string)
     }
 }
diff --git a/proxmox-notify/src/context/test.rs b/proxmox-notify/src/context/test.rs
index 22da38d3e..7380a0545 100644
--- a/proxmox-notify/src/context/test.rs
+++ b/proxmox-notify/src/context/test.rs
@@ -1,5 +1,5 @@
-use crate::Error;
 use crate::context::Context;
+use crate::error::BoxedError;
 use crate::renderer::TemplateSource;
 
 #[derive(Debug)]
@@ -37,7 +37,7 @@ impl Context for TestContext {
         _filename: &str,
         _namespace: Option<&str>,
         _source: TemplateSource,
-    ) -> Result<Option<String>, Error> {
+    ) -> Result<Option<String>, BoxedError> {
         Ok(Some(String::new()))
     }
 }
diff --git a/proxmox-notify/src/endpoints/gotify.rs b/proxmox-notify/src/endpoints/gotify.rs
index 7d0f5cdc6..5ef82fd01 100644
--- a/proxmox-notify/src/endpoints/gotify.rs
+++ b/proxmox-notify/src/endpoints/gotify.rs
@@ -129,7 +129,8 @@ impl Endpoint for GotifyEndpoint {
         });
 
         let body = serde_json::to_vec(&body)
-            .map_err(|err| Error::NotifyFailed(self.name().to_string(), err.into()))?;
+            .map_err(|err| Error::other_with_source("could not serialize JSON body", err))?;
+
         let extra_headers = HashMap::from([
             (
                 http::header::AUTHORIZATION.to_string(),
@@ -146,7 +147,7 @@ impl Endpoint for GotifyEndpoint {
             .http_proxy_config()
             .map(|url| ProxyConfig::parse_proxy_url(&url))
             .transpose()
-            .map_err(|err| Error::NotifyFailed(self.name().to_string(), err.into()))?;
+            .map_err(|err| Error::invalid_config_with_source("invalid proxy configuration", err))?;
 
         let options = HttpOptions {
             proxy_config,
@@ -163,7 +164,7 @@ impl Endpoint for GotifyEndpoint {
                 Some("application/json"),
                 Some(&extra_headers),
             )
-            .map_err(|err| Error::NotifyFailed(self.name().to_string(), err.into()))?;
+            .map_err(Error::http_request_failed)?;
 
         Ok(())
     }
diff --git a/proxmox-notify/src/endpoints/sendmail.rs b/proxmox-notify/src/endpoints/sendmail.rs
index 4f26a1214..70f37eced 100644
--- a/proxmox-notify/src/endpoints/sendmail.rs
+++ b/proxmox-notify/src/endpoints/sendmail.rs
@@ -141,13 +141,15 @@ impl Endpoint for SendmailEndpoint {
 
                 recipients_str.iter().for_each(|r| mail.add_recipient(r));
 
-                mail.send()
-                    .map_err(|err| Error::NotifyFailed(self.config.name.clone(), err.into()))
+                mail.send().map_err(|err| {
+                    Error::other_with_source("could not send mail via sendmail", err)
+                })
             }
             #[cfg(feature = "mail-forwarder")]
             Content::ForwardedMail { raw, uid, .. } => {
-                Mail::forward(&recipients_str, &mailfrom, raw, *uid)
-                    .map_err(|err| Error::NotifyFailed(self.config.name.clone(), err.into()))
+                Mail::forward(&recipients_str, &mailfrom, raw, *uid).map_err(|err| {
+                    Error::other_with_source("could not forward mail via sendmail", err)
+                })
             }
         }
     }
diff --git a/proxmox-notify/src/endpoints/smtp.rs b/proxmox-notify/src/endpoints/smtp.rs
index b3d6e103c..49617e70c 100644
--- a/proxmox-notify/src/endpoints/smtp.rs
+++ b/proxmox-notify/src/endpoints/smtp.rs
@@ -160,7 +160,7 @@ pub struct SmtpEndpoint {
 impl Endpoint for SmtpEndpoint {
     fn send(&self, notification: &Notification) -> Result<(), Error> {
         let tls_parameters = TlsParameters::new(self.config.server.clone())
-            .map_err(|err| Error::NotifyFailed(self.name().into(), Box::new(err)))?;
+            .map_err(|err| Error::invalid_config_with_source("invalid smtp server URL", err))?;
 
         let (port, tls) = match self.config.mode.unwrap_or_default() {
             SmtpMode::Insecure => {
@@ -186,11 +186,8 @@ impl Endpoint for SmtpEndpoint {
             if let Some(password) = self.private_config.password.as_deref() {
                 transport_builder = transport_builder.credentials((username, password).into());
             } else {
-                return Err(Error::NotifyFailed(
-                    self.name().into(),
-                    Box::new(Error::Generic(
-                        "username is set but no password was provided".to_owned(),
-                    )),
+                return Err(Error::invalid_config(
+                    "username is set but no password was provided",
                 ));
             }
         }
@@ -204,8 +201,12 @@ impl Endpoint for SmtpEndpoint {
         let mail_from = self.config.from_address.clone();
 
         let parse_address = |addr: &str| -> Result<Mailbox, Error> {
-            addr.parse()
-                .map_err(|err| Error::NotifyFailed(self.name().into(), Box::new(err)))
+            addr.parse().map_err(|err| {
+                Error::invalid_config_with_source(
+                    format!("could not parse email address '{addr}'"),
+                    err,
+                )
+            })
         };
 
         let author = self
@@ -251,12 +252,12 @@ impl Endpoint for SmtpEndpoint {
                                     .body(html_part),
                             ),
                     )
-                    .map_err(|err| Error::NotifyFailed(self.name().into(), Box::new(err)))?
+                    .map_err(|err| {
+                        Error::invalid_config_with_source("could not build email message", err)
+                    })?
             }
             #[cfg(feature = "mail-forwarder")]
-            Content::ForwardedMail { raw, .. } => {
-                build_forwarded_message(email_builder, self.name(), raw)?
-            }
+            Content::ForwardedMail { raw, .. } => build_forwarded_message(email_builder, raw)?,
         };
 
         // `Auto-Submitted` is defined in RFC 5436 and describes how
@@ -268,9 +269,7 @@ impl Endpoint for SmtpEndpoint {
             "auto-generated;".into(),
         ));
 
-        transport
-            .send(&email)
-            .map_err(|err| Error::NotifyFailed(self.name().into(), err.into()))?;
+        transport.send(&email).map_err(Error::smtp_error)?;
 
         Ok(())
     }
@@ -289,7 +288,6 @@ impl Endpoint for SmtpEndpoint {
 #[cfg(feature = "mail-forwarder")]
 fn build_forwarded_message(
     email_builder: lettre::message::MessageBuilder,
-    endpoint_name: &str,
     raw: &[u8],
 ) -> Result<Message, Error> {
     use lettre::message::Body;
@@ -298,11 +296,11 @@ fn build_forwarded_message(
 
     let parsed_message = mail_parser::MessageParser::default()
         .parse(raw)
-        .ok_or_else(|| Error::Generic("could not parse forwarded email".to_string()))?;
+        .ok_or_else(|| Error::invalid_forwarded_message("could not parse forwarded email"))?;
 
     let root_part = parsed_message
         .part(0)
-        .ok_or_else(|| Error::Generic("root message part not present".to_string()))?;
+        .ok_or_else(|| Error::invalid_forwarded_message("root message part not present"))?;
 
     let raw_body = &parsed_message.raw_message()
         [root_part.offset_body as usize..root_part.offset_end as usize];
@@ -320,11 +318,13 @@ fn build_forwarded_message(
         proxmox_sendmail::normalize_line_endings(raw_body),
         ContentTransferEncoding::Binary,
     )
-    .map_err(|_| Error::Generic("could not create body".into()))?;
+    .map_err(|_| Error::invalid_forwarded_message("could not create body from raw bytes"))?;
     let mut message = email_builder
         .subject(parsed_message.subject().unwrap_or_default())
         .body(body)
-        .map_err(|err| Error::NotifyFailed(endpoint_name.into(), Box::new(err)))?;
+        .map_err(|err| {
+            Error::invalid_forwarded_message_with_source("could not build email message", err)
+        })?;
     message
         .headers_mut()
         .remove_raw("Content-Transfer-Encoding");
@@ -450,7 +450,7 @@ mod tests {
         email_builder = email_builder.to("Recipient <recipient@example.com>".parse().unwrap());
 
         let raw_mail = std::fs::read(input).unwrap();
-        let mut message = build_forwarded_message(email_builder, "test", &raw_mail).unwrap();
+        let mut message = build_forwarded_message(email_builder, &raw_mail).unwrap();
 
         // The Date header contains the current time, let's just remove it
         // for this test.
diff --git a/proxmox-notify/src/endpoints/webhook.rs b/proxmox-notify/src/endpoints/webhook.rs
index f0fd5b6ab..cbb3b1299 100644
--- a/proxmox-notify/src/endpoints/webhook.rs
+++ b/proxmox-notify/src/endpoints/webhook.rs
@@ -215,13 +215,13 @@ impl KeyAndBase64Val {
     pub fn decode_value(&self) -> Result<String, Error> {
         let value = self.value.as_deref().unwrap_or_default();
         let bytes = proxmox_base64::decode(value).map_err(|_| {
-            Error::Generic(format!(
+            Error::invalid_config(format!(
                 "could not decode base64 value with key '{}'",
                 self.name
             ))
         })?;
         let value = String::from_utf8(bytes).map_err(|_| {
-            Error::Generic(format!(
+            Error::invalid_config(format!(
                 "could not decode UTF8 string from base64, key '{}'",
                 self.name
             ))
@@ -245,7 +245,8 @@ impl Endpoint for WebhookEndpoint {
 
         self.create_client()?
             .request(request)
-            .map_err(|err| self.mask_secret_in_error(err))?;
+            .map_err(|err| self.mask_secret_in_error(err))
+            .map_err(Error::http_request_failed)?;
 
         Ok(())
     }
@@ -267,7 +268,7 @@ impl WebhookEndpoint {
             .http_proxy_config()
             .map(|url| ProxyConfig::parse_proxy_url(&url))
             .transpose()
-            .map_err(|err| Error::NotifyFailed(self.name().to_string(), err.into()))?;
+            .map_err(|err| Error::invalid_config_with_source("invalid proxy configuration", err))?;
 
         let options = HttpOptions {
             proxy_config,
@@ -322,12 +323,14 @@ impl WebhookEndpoint {
         let body = handlebars
             .render_template(&body_template, &data)
             .map_err(|err| self.mask_secret_in_error(err))
-            .map_err(|err| Error::Generic(format!("failed to render webhook body: {err}")))?;
+            .map_err(|err| {
+                Error::invalid_config(format!("failed to render webhook body: {err}"))
+            })?;
 
         let url = handlebars
             .render_template(&self.config.url, &data)
             .map_err(|err| self.mask_secret_in_error(err))
-            .map_err(|err| Error::Generic(format!("failed to render webhook url: {err}")))?;
+            .map_err(|err| Error::invalid_config(format!("failed to render webhook url: {err}")))?;
 
         let method: &str = self.config.method.into();
         let mut builder = http::Request::builder().uri(url).method(method);
@@ -339,7 +342,7 @@ impl WebhookEndpoint {
                 .render_template(&value, &data)
                 .map_err(|err| self.mask_secret_in_error(err))
                 .map_err(|err| {
-                    Error::Generic(format!(
+                    Error::invalid_config(format!(
                         "failed to render header value template: {value}: {err}"
                     ))
                 })?;
@@ -367,20 +370,21 @@ impl WebhookEndpoint {
         let request = builder
             .body(body)
             .map_err(|err| self.mask_secret_in_error(err))
-            .map_err(|err| Error::Generic(format!("failed to build http request: {err}")))?;
+            .map_err(|err| Error::invalid_config(format!("failed to build http request: {err}")))?;
 
         Ok(request)
     }
 
     fn base64_decode(&self, s: &str) -> Result<String, Error> {
-        // Also here, TODO: revisit Error variants for the *whole* crate.
-        let s = proxmox_base64::decode(s)
-            .map_err(|err| Error::Generic(format!("could not decode base64 value: {err}")))?;
+        let s = proxmox_base64::decode(s).map_err(|err| {
+            Error::invalid_config_with_source("could not decode base64 value", err)
+        })?;
 
         String::from_utf8(s).map_err(|err| {
-            Error::Generic(format!(
-                "base64 encoded value did not contain valid utf8: {err}"
-            ))
+            Error::invalid_config_with_source(
+                "base64 encoded value did not contain valid utf8",
+                err,
+            )
         })
     }
 
@@ -393,17 +397,17 @@ impl WebhookEndpoint {
     ///
     /// This function will only mask exact matches, but this should suffice
     /// for the majority of cases.
-    fn mask_secret_in_error(&self, error: impl std::fmt::Display) -> Error {
+    fn mask_secret_in_error(&self, error: impl std::fmt::Display) -> String {
         let mut s = error.to_string();
 
         for secret_value in &self.private_config.secret {
             match secret_value.decode_value() {
                 Ok(value) => s = s.replace(&value, "<masked>"),
-                Err(e) => return e,
+                Err(e) => return format!("could not decode secret while masking error: {e}"),
             }
         }
 
-        Error::Generic(s)
+        s
     }
 }
 
@@ -508,7 +512,7 @@ mod tests {
     use crate::Severity;
 
     #[test]
-    fn test_build_request() -> Result<(), Error> {
+    fn test_build_request() {
         let data = HashMap::from_iter([
             ("hello".into(), "hello world".into()),
             ("test".into(), "escaped\nstring".into()),
@@ -560,14 +564,12 @@ hello%20world
 
         let notification = Notification::from_template(Severity::Info, "foo", json!({}), data);
 
-        let request = endpoint.build_request(&notification)?;
+        let request = endpoint.build_request(&notification).unwrap();
 
         assert_eq!(request.uri(), "http://localhost/hello%20world");
         assert_eq!(request.body(), expected_body);
         assert_eq!(request.method(), "POST");
 
         assert_eq!(request.headers().get("X-Severity").unwrap(), "info");
-
-        Ok(())
     }
 }
diff --git a/proxmox-notify/src/error.rs b/proxmox-notify/src/error.rs
new file mode 100644
index 000000000..9655a02de
--- /dev/null
+++ b/proxmox-notify/src/error.rs
@@ -0,0 +1,165 @@
+#![allow(dead_code)]
+
+use std::borrow::Cow;
+
+/// Boxed, type-erased error that can be sent and shared across threads.
+pub type BoxedError = Box<dyn std::error::Error + Send + Sync>;
+
+#[derive(Debug, thiserror::Error)]
+#[non_exhaustive]
+/// Error type for `proxmox_notify`.
+pub enum Error {
+    /// The notification target with the given name does not exist.
+    #[error("target '{0}' does not exist")]
+    TargetDoesNotExist(String),
+
+    /// A notification template could not be rendered.
+    #[error("could not render notification template: {0}")]
+    TemplateRendering(String),
+
+    /// A notification template could not be loaded.
+    #[error("could not load notification template: {0}")]
+    TemplateCouldNotBeRead(#[source] BoxedError),
+
+    /// The notification configuration is invalid.
+    #[error("invalid configuration: {err}", err = print_optional_error(.message, .source))]
+    InvalidConfig {
+        /// Description of the error.
+        message: String,
+        /// Underlying error, if any.
+        source: Option<BoxedError>,
+    },
+
+    /// An HTTP request to a notification endpoint failed.
+    #[error("HTTP request failed: {0}")]
+    HttpRequestFailed(#[source] BoxedError),
+
+    /// Sending a mail via SMTP failed.
+    #[error("SMTP request failed: {0}")]
+    SmtpError(#[source] BoxedError),
+
+    /// A mail message to be forwarded could not be parsed or rebuilt.
+    #[error("forwarded email message is invalid: {err}", err = print_optional_error(.message, .source))]
+    InvalidForwardedMessage {
+        /// Description of the error.
+        message: String,
+        /// Underlying error, if any.
+        source: Option<BoxedError>,
+    },
+
+    /// The notification configuration could not be serialized.
+    #[error("could not serialize config: {0}")]
+    ConfigSerialization(#[source] BoxedError),
+
+    /// The notification configuration could not be deserialized.
+    #[error("could not deserialize config: {0}")]
+    ConfigDeserialization(#[source] BoxedError),
+
+    /// Any other error.
+    #[error("{err}", err = print_optional_error(.message, .source))]
+    Other {
+        /// Description of the error.
+        message: String,
+        /// Underlying error, if any.
+        source: Option<BoxedError>,
+    },
+}
+
+fn print_optional_error<'a>(message: &'a str, err: &Option<BoxedError>) -> Cow<'a, str> {
+    if let Some(err) = err {
+        Cow::Owned(format!("{message}: {err}"))
+    } else {
+        Cow::Borrowed(message)
+    }
+}
+
+impl Error {
+    /// Create an [`Error::InvalidForwardedMessage`] without an underlying error.
+    pub(crate) fn invalid_forwarded_message(s: impl Into<String>) -> Self {
+        Self::InvalidForwardedMessage {
+            message: s.into(),
+            source: None,
+        }
+    }
+
+    /// Create an [`Error::HttpRequestFailed`] from the given error.
+    pub(crate) fn http_request_failed(err: impl Into<BoxedError>) -> Self {
+        Self::HttpRequestFailed(err.into())
+    }
+
+    /// Create an [`Error::SmtpError`] from the given error.
+    pub(crate) fn smtp_error(err: impl Into<BoxedError>) -> Self {
+        Self::SmtpError(err.into())
+    }
+
+    /// Create an [`Error::InvalidForwardedMessage`] with an underlying error.
+    pub(crate) fn invalid_forwarded_message_with_source(
+        s: impl Into<String>,
+        source: impl Into<BoxedError>,
+    ) -> Self {
+        Self::InvalidForwardedMessage {
+            message: s.into(),
+            source: Some(source.into()),
+        }
+    }
+
+    /// Create an [`Error::TemplateCouldNotBeRead`] from the given error.
+    pub(crate) fn template_could_not_be_read(err: impl Into<BoxedError>) -> Self {
+        Self::TemplateCouldNotBeRead(err.into())
+    }
+
+    /// Create an [`Error::InvalidConfig`] without an underlying error.
+    pub(crate) fn invalid_config(s: impl Into<String>) -> Self {
+        Self::InvalidConfig {
+            message: s.into(),
+            source: None,
+        }
+    }
+
+    /// Create an [`Error::InvalidConfig`] with an underlying error.
+    pub(crate) fn invalid_config_with_source(
+        s: impl Into<String>,
+        source: impl Into<BoxedError>,
+    ) -> Self {
+        Self::InvalidConfig {
+            message: s.into(),
+            source: Some(source.into()),
+        }
+    }
+
+    /// Create an [`Error::ConfigDeserialization`] from the given error.
+    pub(crate) fn config_deserialization(err: impl Into<BoxedError>) -> Self {
+        Self::ConfigDeserialization(err.into())
+    }
+
+    /// Create an [`Error::ConfigSerialization`] from the given error.
+    pub(crate) fn config_serialization(err: impl Into<BoxedError>) -> Self {
+        Self::ConfigSerialization(err.into())
+    }
+
+    /// Create an [`Error::TargetDoesNotExist`] for the given target name.
+    pub(crate) fn target_does_not_exist(target: impl Into<String>) -> Self {
+        Self::TargetDoesNotExist(target.into())
+    }
+
+    /// Create an [`Error::TemplateRendering`] with the given message.
+    pub(crate) fn template_rendering(message: impl Into<String>) -> Self {
+        Self::TemplateRendering(message.into())
+    }
+
+    /// Create an [`Error::Other`].
+    pub(crate) fn other(s: impl Into<String>) -> Self {
+        Self::Other {
+            message: s.into(),
+            source: None,
+        }
+    }
+
+    /// Create an [`Error::Other`] with an underlying error.
+    pub(crate) fn other_with_source(s: impl Into<String>, source: impl Into<BoxedError>) -> Self {
+        Self::Other {
+            message: s.into(),
+            source: Some(source.into()),
+        }
+    }
+}
diff --git a/proxmox-notify/src/lib.rs b/proxmox-notify/src/lib.rs
index 1ce6f89e6..270087ffc 100644
--- a/proxmox-notify/src/lib.rs
+++ b/proxmox-notify/src/lib.rs
@@ -2,7 +2,6 @@
 #![deny(unsafe_code)]
 
 use std::collections::HashMap;
-use std::error::Error as StdError;
 use std::fmt::Display;
 use std::str::FromStr;
 
@@ -26,71 +25,9 @@ pub mod endpoints;
 pub mod renderer;
 pub mod schema;
 
-#[derive(Debug)]
-pub enum Error {
-    /// There was an error serializing the config
-    ConfigSerialization(Box<dyn StdError + Send + Sync>),
-    /// There was an error deserializing the config
-    ConfigDeserialization(Box<dyn StdError + Send + Sync>),
-    /// An endpoint failed to send a notification
-    NotifyFailed(String, Box<dyn StdError + Send + Sync>),
-    /// A target does not exist
-    TargetDoesNotExist(String),
-    /// Testing one or more notification targets failed
-    TargetTestFailed(Vec<Box<dyn StdError + Send + Sync>>),
-    /// A filter could not be applied
-    FilterFailed(String),
-    /// The notification's template string could not be rendered
-    RenderError(Box<dyn StdError + Send + Sync>),
-    /// Generic error for anything else
-    Generic(String),
-}
+mod error;
+pub use error::Error;
 
-impl Display for Error {
-    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        match self {
-            Error::ConfigSerialization(err) => {
-                write!(f, "could not serialize configuration: {err}")
-            }
-            Error::ConfigDeserialization(err) => {
-                write!(f, "could not deserialize configuration: {err}")
-            }
-            Error::NotifyFailed(endpoint, err) => {
-                write!(f, "could not notify via endpoint(s): {endpoint}: {err}")
-            }
-            Error::TargetDoesNotExist(target) => {
-                write!(f, "notification target '{target}' does not exist")
-            }
-            Error::TargetTestFailed(errs) => {
-                for err in errs {
-                    writeln!(f, "{err}")?;
-                }
-
-                Ok(())
-            }
-            Error::FilterFailed(message) => {
-                write!(f, "could not apply filter: {message}")
-            }
-            Error::RenderError(err) => write!(f, "could not render notification template: {err}"),
-            Error::Generic(message) => f.write_str(message),
-        }
-    }
-}
-
-impl StdError for Error {
-    fn source(&self) -> Option<&(dyn StdError + 'static)> {
-        match self {
-            Error::ConfigSerialization(err) => Some(&**err),
-            Error::ConfigDeserialization(err) => Some(&**err),
-            Error::NotifyFailed(_, err) => Some(&**err),
-            Error::TargetDoesNotExist(_) => None,
-            Error::TargetTestFailed(errs) => Some(&*errs[0]),
-            Error::FilterFailed(_) => None,
-            Error::RenderError(err) => Some(&**err),
-            Error::Generic(_) => None,
-        }
-    }
-}
 
 #[api()]
 #[derive(Clone, Debug, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd)]
@@ -123,14 +60,14 @@ impl Display for Severity {
 
 impl FromStr for Severity {
     type Err = Error;
-    fn from_str(s: &str) -> Result<Self, Error> {
+    fn from_str(s: &str) -> Result<Self, Self::Err> {
         match s {
             "info" => Ok(Self::Info),
             "notice" => Ok(Self::Notice),
             "warning" => Ok(Self::Warning),
             "error" => Ok(Self::Error),
             "unknown" => Ok(Self::Unknown),
-            _ => Err(Error::Generic(format!("invalid severity {s}"))),
+            _ => Err(Error::invalid_config(format!("invalid severity {s}"))),
         }
     }
 }
@@ -233,7 +170,7 @@ impl Notification {
     pub fn new_forwarded_mail(raw_mail: &[u8], uid: Option<u32>) -> Result<Self, Error> {
         let message = mail_parser::MessageParser::default()
             .parse(raw_mail)
-            .ok_or_else(|| Error::Generic("could not parse forwarded email".to_string()))?;
+            .ok_or_else(|| Error::invalid_forwarded_message("could not parse forwarded email"))?;
 
         let title = message.subject().unwrap_or_default().into();
         let body = message.body_text(0).unwrap_or_default().into();
@@ -589,7 +526,7 @@ impl Bus {
         if let Some(endpoint) = self.endpoints.get(target) {
             endpoint.send(&notification)?;
         } else {
-            return Err(Error::TargetDoesNotExist(target.to_string()));
+            return Err(Error::target_does_not_exist(target));
         }
 
         Ok(())
diff --git a/proxmox-notify/src/matcher/calendar.rs b/proxmox-notify/src/matcher/calendar.rs
index a0377259a..72af94102 100644
--- a/proxmox-notify/src/matcher/calendar.rs
+++ b/proxmox-notify/src/matcher/calendar.rs
@@ -29,7 +29,7 @@ impl FromStr for DailyDurationWrapper {
 
     fn from_str(s: &str) -> Result<Self, Error> {
         let daily_duration = proxmox_time::parse_daily_duration(s)
-            .map_err(|e| Error::Generic(format!("could not parse schedule: {e}")))?;
+            .map_err(|err| Error::invalid_config_with_source("could not parse schedule", err))?;
 
         Ok(Self {
             daily_duration,
@@ -65,7 +65,7 @@ impl MatchDirective for CalendarMatcher {
         self.schedule
             .daily_duration
             .time_match(notification.metadata.timestamp, false)
-            .map_err(|err| Error::Generic(format!("could not match timestamp: {err}")))
+            .map_err(|err| Error::invalid_config_with_source("could not match timestamp", err))
     }
 
     fn validate(&self) -> Result<(), Error> {
diff --git a/proxmox-notify/src/matcher/field.rs b/proxmox-notify/src/matcher/field.rs
index e0d362383..0e145f81b 100644
--- a/proxmox-notify/src/matcher/field.rs
+++ b/proxmox-notify/src/matcher/field.rs
@@ -59,21 +59,21 @@ impl MatchDirective for FieldMatcher {
         match self {
             FieldMatcher::Exact { field, values } => {
                 if values.is_empty() {
-                    return Err(Error::Generic(
-                        "field matcher must contain values to match".to_string(),
+                    return Err(Error::invalid_config(
+                        "field matcher must contain values to match",
                     ));
                 }
                 if !SAFE_ID_REGEX.is_match(field) {
-                    return Err(Error::Generic(
-                        "field name does not match regex pattern".to_string(),
-                    ));
+                    return Err(Error::invalid_config(format!(
+                        "field name '{field}' does not match regex pattern",
+                    )));
                 }
             }
             FieldMatcher::Regex { field, .. } => {
                 if !SAFE_ID_REGEX.is_match(field) {
-                    return Err(Error::Generic(
-                        "field name does not match regex pattern".to_string(),
-                    ));
+                    return Err(Error::invalid_config(format!(
+                        "field name '{field}' does not match regex pattern",
+                    )));
                 }
             }
         }
@@ -156,19 +156,20 @@ pub mod inline {
         type Err = Error;
         fn from_str(s: &str) -> Result<Self, Error> {
             if !MATCH_FIELD_ENTRY_REGEX.is_match(s) {
-                return Err(Error::FilterFailed(format!(
+                return Err(Error::invalid_config(format!(
                     "invalid match-field statement: {s}"
                 )));
             }
 
             if let Some(remaining) = s.strip_prefix("regex:") {
                 match remaining.split_once('=') {
-                    None => Err(Error::FilterFailed(format!(
+                    None => Err(Error::invalid_config(format!(
                         "invalid match-field statement: {s}"
                     ))),
                     Some((field, expected_value_regex)) => {
-                        let regex = Regex::new(expected_value_regex)
-                            .map_err(|err| Error::FilterFailed(format!("invalid regex: {err}")))?;
+                        let regex = Regex::new(expected_value_regex).map_err(|err| {
+                            Error::invalid_config_with_source("invalid regex", err)
+                        })?;
 
                         Ok(Self(FieldMatcher::Regex {
                             field: field.into(),
@@ -178,7 +179,7 @@ pub mod inline {
                 }
             } else if let Some(remaining) = s.strip_prefix("exact:") {
                 match remaining.split_once('=') {
-                    None => Err(Error::FilterFailed(format!(
+                    None => Err(Error::invalid_config(format!(
                         "invalid match-field statement: {s}"
                     ))),
                     Some((field, expected_values)) => {
@@ -194,7 +195,7 @@ pub mod inline {
                     }
                 }
             } else {
-                Err(Error::FilterFailed(format!(
+                Err(Error::invalid_config(format!(
                     "invalid match-field statement: {s}"
                 )))
             }
diff --git a/proxmox-notify/src/matcher/mod.rs b/proxmox-notify/src/matcher/mod.rs
index af87a4ef3..59baeae4e 100644
--- a/proxmox-notify/src/matcher/mod.rs
+++ b/proxmox-notify/src/matcher/mod.rs
@@ -155,7 +155,10 @@ impl MatcherConfig {
         let expression: Expression<NotificationMatcher> = {
             if let Some(expression_str) = &self.expression {
                 serde_json::from_str(expression_str).map_err(|err| {
-                    Error::FilterFailed(format!("could not deserialize filter expression: {err:#}"))
+                    Error::invalid_config_with_source(
+                        "could not deserialize matcher expression",
+                        err,
+                    )
                 })?
             } else {
                 #[cfg(feature = "legacy-matchers")]
@@ -234,7 +237,7 @@ impl MatcherConfig {
 
             if !conflicting_properties.is_empty() {
                 let joined = conflicting_properties.join(", ");
-                return Err(Error::Generic(format!(
+                return Err(Error::invalid_config(format!(
                     "'expression' property is mutually exclusive with: {joined}"
                 )));
             }
@@ -252,13 +255,14 @@ impl MatcherConfig {
                     // Storing the *serialized* expression makes sure that
                     // we have a minified, single-line JSON string
                     self.expression = Some(serde_json::to_string(&expr).map_err(|err| {
-                        Error::Generic(format!("could not serialize expression: {err:#}"))
+                        Error::other_with_source("could not serialize expression", err)
                     })?);
                 }
                 Err(err) => {
-                    return Err(Error::Generic(format!(
-                        "'expression' is not valid: {err:#}"
-                    )));
+                    return Err(Error::invalid_config_with_source(
+                        "'expression' is not valid",
+                        err,
+                    ));
                 }
             }
         }
@@ -277,21 +281,21 @@ impl MatcherConfig {
         match expr {
             Expression::AllOf(expressions) => {
                 if expressions.is_empty() {
-                    return Err(Error::Generic(
+                    return Err(Error::invalid_config(
                         "'expression' may not contain an empty 'all-of' rule".to_string(),
                     ));
                 }
             }
             Expression::AnyOf(expressions) => {
                 if expressions.is_empty() {
-                    return Err(Error::Generic(
+                    return Err(Error::invalid_config(
                         "'expression' may not contain an empty 'any-of' rule".to_string(),
                     ));
                 }
             }
             Expression::OneOf(expressions) => {
                 if expressions.is_empty() {
-                    return Err(Error::Generic(
+                    return Err(Error::invalid_config(
                         "'expression' may not contain an empty 'one-of' rule".to_string(),
                     ));
                 }
diff --git a/proxmox-notify/src/matcher/severity.rs b/proxmox-notify/src/matcher/severity.rs
index b867d8b74..6818e5c22 100644
--- a/proxmox-notify/src/matcher/severity.rs
+++ b/proxmox-notify/src/matcher/severity.rs
@@ -25,8 +25,8 @@ impl MatchDirective for SeverityMatcher {
 
     fn validate(&self) -> Result<(), Error> {
         if self.severities.is_empty() {
-            return Err(Error::Generic(
-                "severity matcher must contain severities to match".to_string(),
+            return Err(Error::invalid_config(
+                "severity matcher must contain severities to match",
             ));
         }
 
@@ -75,7 +75,9 @@ pub mod inline {
 
             for element in s.split(',') {
                 let element = element.trim();
-                let severity: Severity = element.parse()?;
+                let severity: Severity = element
+                    .parse()
+                    .map_err(|err| Error::invalid_config_with_source("invalid severity", err))?;
 
                 severities.push(severity)
             }
diff --git a/proxmox-notify/src/renderer/mod.rs b/proxmox-notify/src/renderer/mod.rs
index a0b7df7bc..1bccf75bf 100644
--- a/proxmox-notify/src/renderer/mod.rs
+++ b/proxmox-notify/src/renderer/mod.rs
@@ -272,7 +272,9 @@ fn render_template_impl(
     filename: &str,
     source: TemplateSource,
 ) -> Result<Option<String>, Error> {
-    let template_string = context::context().lookup_template(filename, None, source)?;
+    let template_string = context::context()
+        .lookup_template(filename, None, source)
+        .map_err(Error::template_could_not_be_read)?;
 
     if let Some(template_string) = template_string {
         let mut handlebars = Handlebars::new();
@@ -290,7 +292,7 @@ fn render_template_impl(
 
         let rendered_template = handlebars
             .render_template(&template_string, data)
-            .map_err(|err| Error::RenderError(err.into()))?;
+            .map_err(|err| Error::template_rendering(err.to_string()))?;
 
         let rendered_template = renderer.postprocess(rendered_template);
 
@@ -357,9 +359,8 @@ pub fn render_template(
         }
     }
 
-    Err(Error::Generic(
-        "failed to render notification template, all template candidates are erroneous or missing"
-            .into(),
+    Err(Error::template_rendering(
+        "all template candidates are erroneous or missing",
     ))
 }
 
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 03/63] notify: move `Endpoint` trait to endpoint module as pub(crate)
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
  2026-11-18  9:42 ` [PATCH proxmox v2 01/63] notify: disallow `unsafe` code Lukas Wagner
  2026-11-18  9:42 ` [PATCH proxmox v2 02/63] notify: refactor error type Lukas Wagner
@ 2026-11-18  9:42 ` Lukas Wagner
  2026-11-18  9:42 ` [PATCH proxmox v2 04/63] notify: use ConfigDigest instead of raw byte arrays Lukas Wagner
                   ` (60 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:42 UTC (permalink / raw)
  To: pve-devel

This trait belongs in the endpoint module and is not supposed to be used
externally.

Fixed a typo in the doc comments along the way, no functional change
whatsoever.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/endpoints/gotify.rs   |  4 +++-
 proxmox-notify/src/endpoints/mod.rs      | 14 ++++++++++++++
 proxmox-notify/src/endpoints/sendmail.rs |  4 +++-
 proxmox-notify/src/endpoints/smtp.rs     |  4 +++-
 proxmox-notify/src/endpoints/webhook.rs  |  4 +++-
 proxmox-notify/src/lib.rs                | 16 +++-------------
 6 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/proxmox-notify/src/endpoints/gotify.rs b/proxmox-notify/src/endpoints/gotify.rs
index 5ef82fd01..6b8499827 100644
--- a/proxmox-notify/src/endpoints/gotify.rs
+++ b/proxmox-notify/src/endpoints/gotify.rs
@@ -12,7 +12,9 @@ use proxmox_schema::{Updater, api};
 use crate::context::context;
 use crate::renderer::TemplateType;
 use crate::schema::ENTITY_NAME_SCHEMA;
-use crate::{Content, Endpoint, Error, Notification, Origin, Severity, renderer};
+use crate::{Content, Error, Notification, Origin, Severity, renderer};
+
+use super::Endpoint;
 
 const HTTP_TIMEOUT: Duration = Duration::from_secs(10);
 
diff --git a/proxmox-notify/src/endpoints/mod.rs b/proxmox-notify/src/endpoints/mod.rs
index f20bee21f..757b251c1 100644
--- a/proxmox-notify/src/endpoints/mod.rs
+++ b/proxmox-notify/src/endpoints/mod.rs
@@ -1,3 +1,5 @@
+use crate::{Error, Notification};
+
 #[cfg(feature = "gotify")]
 pub mod gotify;
 #[cfg(feature = "sendmail")]
@@ -8,3 +10,15 @@ pub mod smtp;
 pub mod webhook;
 
 mod common;
+
+/// Notification endpoint trait, implemented by all endpoint plugins
+pub(crate) trait Endpoint {
+    /// Send a notification to this endpoint.
+    fn send(&self, notification: &Notification) -> Result<(), Error>;
+
+    /// The name/identifier for this endpoint
+    fn name(&self) -> &str;
+
+    /// Check if the endpoint is disabled
+    fn disabled(&self) -> bool;
+}
diff --git a/proxmox-notify/src/endpoints/sendmail.rs b/proxmox-notify/src/endpoints/sendmail.rs
index 70f37eced..3f5f66db6 100644
--- a/proxmox-notify/src/endpoints/sendmail.rs
+++ b/proxmox-notify/src/endpoints/sendmail.rs
@@ -8,7 +8,9 @@ use crate::context;
 use crate::endpoints::common::mail;
 use crate::renderer::TemplateType;
 use crate::schema::{EMAIL_SCHEMA, ENTITY_NAME_SCHEMA, USER_SCHEMA};
-use crate::{Content, Endpoint, Error, Notification, Origin, renderer};
+use crate::{Content, Error, Notification, Origin, renderer};
+
+use super::Endpoint;
 
 pub(crate) const SENDMAIL_TYPENAME: &str = "sendmail";
 
diff --git a/proxmox-notify/src/endpoints/smtp.rs b/proxmox-notify/src/endpoints/smtp.rs
index 49617e70c..e73151797 100644
--- a/proxmox-notify/src/endpoints/smtp.rs
+++ b/proxmox-notify/src/endpoints/smtp.rs
@@ -14,7 +14,9 @@ use crate::context::context;
 use crate::endpoints::common::mail;
 use crate::renderer::TemplateType;
 use crate::schema::{EMAIL_SCHEMA, ENTITY_NAME_SCHEMA, USER_SCHEMA};
-use crate::{Content, Endpoint, Error, Notification, Origin, renderer};
+use crate::{Content, Error, Notification, Origin, renderer};
+
+use super::Endpoint;
 
 pub(crate) const SMTP_TYPENAME: &str = "smtp";
 
diff --git a/proxmox-notify/src/endpoints/webhook.rs b/proxmox-notify/src/endpoints/webhook.rs
index cbb3b1299..47d9e0586 100644
--- a/proxmox-notify/src/endpoints/webhook.rs
+++ b/proxmox-notify/src/endpoints/webhook.rs
@@ -27,7 +27,9 @@ use proxmox_schema::{ApiStringFormat, ApiType, Schema, StringSchema, Updater, ap
 use crate::context::context;
 use crate::renderer::TemplateType;
 use crate::schema::ENTITY_NAME_SCHEMA;
-use crate::{Content, Endpoint, Error, Notification, Origin, renderer};
+use crate::{Content, Error, Notification, Origin, renderer};
+
+use super::Endpoint;
 
 /// This will be used as a section type in the public/private configuration file.
 pub(crate) const WEBHOOK_TYPENAME: &str = "webhook";
diff --git a/proxmox-notify/src/lib.rs b/proxmox-notify/src/lib.rs
index 270087ffc..846e8315e 100644
--- a/proxmox-notify/src/lib.rs
+++ b/proxmox-notify/src/lib.rs
@@ -28,6 +28,8 @@ pub mod schema;
 mod error;
 pub use error::Error;
 
+use endpoints::Endpoint;
+
 
 #[api()]
 #[derive(Clone, Debug, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd)]
@@ -85,18 +87,6 @@ pub enum Origin {
     ModifiedBuiltin,
 }
 
-/// Notification endpoint trait, implemented by all endpoint plugins
-pub trait Endpoint {
-    /// Send a documentation
-    fn send(&self, notification: &Notification) -> Result<(), Error>;
-
-    /// The name/identifier for this endpoint
-    fn name(&self) -> &str;
-
-    /// Check if the endpoint is disabled
-    fn disabled(&self) -> bool;
-}
-
 #[derive(Debug, Clone, Serialize, Deserialize)]
 #[serde(rename_all = "kebab-case")]
 pub enum Content {
@@ -463,7 +453,7 @@ impl Bus {
     }
 
     #[cfg(test)]
-    pub fn add_endpoint(&mut self, endpoint: Box<dyn Endpoint>) {
+    pub(crate) fn add_endpoint(&mut self, endpoint: Box<dyn Endpoint>) {
         self.endpoints.insert(endpoint.name().to_string(), endpoint);
     }
 
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 04/63] notify: use ConfigDigest instead of raw byte arrays
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (2 preceding siblings ...)
  2026-11-18  9:42 ` [PATCH proxmox v2 03/63] notify: move `Endpoint` trait to endpoint module as pub(crate) Lukas Wagner
@ 2026-11-18  9:42 ` Lukas Wagner
  2026-11-18  9:42 ` [PATCH proxmox v2 05/63] notify: remove static context and pass context as parameter Lukas Wagner
                   ` (59 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:42 UTC (permalink / raw)
  To: pve-devel

The proxmox-config-digest crate did not exist when proxmox-notify was
written, hence it used raw byte slices for checking the digest.

This is a breaking change; users of proxmox-notify need to be adapted.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---

Notes:
    Changes since v1:
      - use ConfigDigest::detect_motification

 proxmox-notify/Cargo.toml          |  2 +-
 proxmox-notify/src/api/gotify.rs   |  9 ++++---
 proxmox-notify/src/api/matcher.rs  | 43 +++++++++++++++++-------------
 proxmox-notify/src/api/mod.rs      | 17 +++++-------
 proxmox-notify/src/api/sendmail.rs |  9 ++++---
 proxmox-notify/src/api/smtp.rs     |  9 ++++---
 proxmox-notify/src/api/webhook.rs  |  9 ++++---
 proxmox-notify/src/config.rs       |  9 ++++---
 proxmox-notify/src/lib.rs          |  5 ++--
 9 files changed, 60 insertions(+), 52 deletions(-)

diff --git a/proxmox-notify/Cargo.toml b/proxmox-notify/Cargo.toml
index 6796c2915..8968a14f8 100644
--- a/proxmox-notify/Cargo.toml
+++ b/proxmox-notify/Cargo.toml
@@ -19,7 +19,6 @@ http = { workspace = true, optional = true }
 lettre = { workspace = true, optional = true }
 tracing.workspace = true
 mail-parser = { workspace = true, optional = true }
-openssl.workspace = true
 percent-encoding = { workspace = true, optional = true }
 regex.workspace = true
 serde = { workspace = true, features = ["derive"] }
@@ -29,6 +28,7 @@ thiserror.workspace = true
 
 proxmox-api-macro.workspace = true
 proxmox-base64 = { workspace = true, optional = true }
+proxmox-config-digest = { workspace = true, features = ["openssl"] }
 proxmox-http = { workspace = true, features = ["client-sync"], optional = true }
 proxmox-http-error.workspace = true
 proxmox-human-byte.workspace = true
diff --git a/proxmox-notify/src/api/gotify.rs b/proxmox-notify/src/api/gotify.rs
index 5155fd2c8..c3149c152 100644
--- a/proxmox-notify/src/api/gotify.rs
+++ b/proxmox-notify/src/api/gotify.rs
@@ -1,3 +1,4 @@
+use proxmox_config_digest::ConfigDigest;
 use proxmox_http_error::HttpError;
 
 use crate::Config;
@@ -78,7 +79,7 @@ pub fn update_endpoint(
     endpoint_config_updater: GotifyConfigUpdater,
     private_endpoint_config_updater: GotifyPrivateConfigUpdater,
     delete: Option<&[DeleteableGotifyProperty]>,
-    digest: Option<&[u8]>,
+    digest: Option<ConfigDigest>,
 ) -> Result<(), HttpError> {
     super::verify_digest(config, digest)?;
 
@@ -220,7 +221,7 @@ mod tests {
                 Default::default(),
                 Default::default(),
                 None,
-                Some(&[0; 32])
+                Some(ConfigDigest::from([0; 32]))
             )
             .is_err()
         );
@@ -233,7 +234,7 @@ mod tests {
         let mut config = empty_config();
         add_default_gotify_endpoint(&mut config)?;
 
-        let digest = config.digest;
+        let digest = config.digest.clone();
 
         update_endpoint(
             &mut config,
@@ -247,7 +248,7 @@ mod tests {
                 token: Some("changedtoken".into()),
             },
             None,
-            Some(&digest),
+            Some(digest),
         )?;
 
         let endpoint = get_endpoint(&config, "gotify-endpoint")?;
diff --git a/proxmox-notify/src/api/matcher.rs b/proxmox-notify/src/api/matcher.rs
index 84131be3c..3302c2c31 100644
--- a/proxmox-notify/src/api/matcher.rs
+++ b/proxmox-notify/src/api/matcher.rs
@@ -1,3 +1,4 @@
+use proxmox_config_digest::ConfigDigest;
 use proxmox_http_error::HttpError;
 
 use crate::Config;
@@ -105,7 +106,7 @@ pub fn update_matcher(
     name: &str,
     matcher_updater: MatcherConfigUpdater,
     delete: Option<&[DeleteableMatcherProperty]>,
-    digest: Option<&[u8]>,
+    digest: Option<ConfigDigest>,
 ) -> Result<(), HttpError> {
     super::verify_digest(config, digest)?;
 
@@ -251,7 +252,7 @@ matcher: matcher2
                 "matcher1",
                 Default::default(),
                 None,
-                Some(&[0u8; 32])
+                Some(ConfigDigest::from([0u8; 32]))
             )
             .is_err()
         );
@@ -266,7 +267,7 @@ matcher: matcher2
 
         let mut config = config_with_two_matchers();
 
-        let digest = config.digest;
+        let digest = config.digest.clone();
 
         update_matcher(
             &mut config,
@@ -282,7 +283,7 @@ matcher: matcher2
                 ..Default::default()
             },
             None,
-            Some(&digest),
+            Some(digest.clone()),
         )?;
 
         let matcher = get_matcher(&config, "matcher1")?;
@@ -303,7 +304,7 @@ matcher: matcher2
                 DeleteableMatcherProperty::Target,
                 DeleteableMatcherProperty::Comment,
             ]),
-            Some(&digest),
+            Some(digest),
         )?;
 
         let matcher = get_matcher(&config, "matcher1")?;
@@ -323,7 +324,7 @@ matcher: matcher2
     fn test_matcher_update() -> Result<(), HttpError> {
         let mut config = config_with_two_matchers();
 
-        let digest = config.digest;
+        let digest = config.digest.clone();
 
         update_matcher(
             &mut config,
@@ -335,7 +336,7 @@ matcher: matcher2
                 ..Default::default()
             },
             None,
-            Some(&digest),
+            Some(digest.clone()),
         )?;
 
         let matcher = get_matcher(&config, "matcher1")?;
@@ -352,7 +353,7 @@ matcher: matcher2
                 DeleteableMatcherProperty::Comment,
                 DeleteableMatcherProperty::Expression,
             ]),
-            Some(&digest),
+            Some(digest),
         )?;
 
         let matcher = get_matcher(&config, "matcher1")?;
@@ -378,7 +379,7 @@ matcher: matcher2
     #[cfg(feature = "legacy-matchers")]
     fn test_update_matcher_mutually_exclusive_with_expression() -> Result<(), HttpError> {
         let mut config = config_with_two_matchers();
-        let digest = config.digest;
+        let digest = config.digest.clone();
 
         let proto = MatcherConfigUpdater {
             expression: Some(valid_expression_string()),
@@ -388,17 +389,23 @@ matcher: matcher2
         let mut updater = proto.clone();
         updater.match_field = Some(vec!["exact:foo=bar".parse().unwrap()]);
 
-        assert!(update_matcher(&mut config, "matcher1", updater, None, Some(&digest),).is_err());
+        assert!(
+            update_matcher(&mut config, "matcher1", updater, None, Some(digest.clone()),).is_err()
+        );
 
         let mut updater = proto.clone();
         updater.match_calendar = Some(vec!["mon..sun 12-13".parse().unwrap()]);
 
-        assert!(update_matcher(&mut config, "matcher1", updater, None, Some(&digest),).is_err());
+        assert!(
+            update_matcher(&mut config, "matcher1", updater, None, Some(digest.clone()),).is_err()
+        );
 
         let mut updater = proto.clone();
         updater.match_severity = Some(vec!["info,warning".parse().unwrap()]);
 
-        assert!(update_matcher(&mut config, "matcher1", updater, None, Some(&digest),).is_err());
+        assert!(
+            update_matcher(&mut config, "matcher1", updater, None, Some(digest.clone()),).is_err()
+        );
 
         Ok(())
     }
@@ -406,7 +413,7 @@ matcher: matcher2
     #[test]
     fn test_update_invalid_expression() -> Result<(), HttpError> {
         let mut config = config_with_two_matchers();
-        let digest = config.digest;
+        let digest = config.digest.clone();
 
         assert!(
             update_matcher(
@@ -417,7 +424,7 @@ matcher: matcher2
                     ..Default::default()
                 },
                 None,
-                Some(&digest),
+                Some(digest),
             )
             .is_err()
         );
@@ -437,7 +444,7 @@ matcher: matcher2
     #[test]
     fn test_update_minifies_pretty_printed_expression() -> Result<(), HttpError> {
         let mut config = config_with_two_matchers();
-        let digest = config.digest;
+        let digest = config.digest.clone();
 
         let expr = nested_expression();
         let pretty = serde_json::to_string_pretty(&expr).unwrap();
@@ -451,7 +458,7 @@ matcher: matcher2
                 ..Default::default()
             },
             None,
-            Some(&digest),
+            Some(digest),
         )?;
 
         let matcher = get_matcher(&config, "matcher1")?;
@@ -466,7 +473,7 @@ matcher: matcher2
     #[test]
     fn test_update_normalizes_expression_with_extra_whitespace() -> Result<(), HttpError> {
         let mut config = config_with_two_matchers();
-        let digest = config.digest;
+        let digest = config.digest.clone();
 
         // Same expression as `nested_expression`, but handwritten, with all sorts of
         // odd whitespace characters.
@@ -481,7 +488,7 @@ matcher: matcher2
                 ..Default::default()
             },
             None,
-            Some(&digest),
+            Some(digest),
         )?;
 
         let matcher = get_matcher(&config, "matcher1")?;
diff --git a/proxmox-notify/src/api/mod.rs b/proxmox-notify/src/api/mod.rs
index 7f823bc7c..9697f9f17 100644
--- a/proxmox-notify/src/api/mod.rs
+++ b/proxmox-notify/src/api/mod.rs
@@ -2,6 +2,7 @@ use std::collections::HashSet;
 
 use serde::{Deserialize, Serialize};
 
+use proxmox_config_digest::ConfigDigest;
 use proxmox_http_error::HttpError;
 use proxmox_schema::api;
 
@@ -132,17 +133,11 @@ pub fn get_targets(config: &Config) -> Result<Vec<Target>, HttpError> {
     Ok(targets)
 }
 
-fn verify_digest(config: &Config, digest: Option<&[u8]>) -> Result<(), HttpError> {
-    if let Some(digest) = digest {
-        if config.digest != *digest {
-            http_bail!(
-                BAD_REQUEST,
-                "detected modified configuration - file changed by other user? Try again."
-            );
-        }
-    }
-
-    Ok(())
+fn verify_digest(config: &Config, digest: Option<ConfigDigest>) -> Result<(), HttpError> {
+    config
+        .digest()
+        .detect_modification(digest.as_ref())
+        .map_err(|err| http_err!(BAD_REQUEST, "{err}"))
 }
 
 fn ensure_endpoint_exists(#[allow(unused)] config: &Config, name: &str) -> Result<(), HttpError> {
diff --git a/proxmox-notify/src/api/sendmail.rs b/proxmox-notify/src/api/sendmail.rs
index eaafd0012..2d54608cd 100644
--- a/proxmox-notify/src/api/sendmail.rs
+++ b/proxmox-notify/src/api/sendmail.rs
@@ -1,3 +1,4 @@
+use proxmox_config_digest::ConfigDigest;
 use proxmox_http_error::HttpError;
 
 use crate::Config;
@@ -71,7 +72,7 @@ pub fn update_endpoint(
     name: &str,
     updater: SendmailConfigUpdater,
     delete: Option<&[DeleteableSendmailProperty]>,
-    digest: Option<&[u8]>,
+    digest: Option<ConfigDigest>,
 ) -> Result<(), HttpError> {
     super::verify_digest(config, digest)?;
 
@@ -216,7 +217,7 @@ pub mod tests {
                     ..Default::default()
                 },
                 None,
-                Some(&[0; 32]),
+                Some(ConfigDigest::from([0; 32])),
             )
             .is_err()
         );
@@ -229,7 +230,7 @@ pub mod tests {
         let mut config = empty_config();
         add_sendmail_endpoint_for_test(&mut config, "sendmail-endpoint")?;
 
-        let digest = config.digest;
+        let digest = config.digest.clone();
 
         update_endpoint(
             &mut config,
@@ -243,7 +244,7 @@ pub mod tests {
                 ..Default::default()
             },
             None,
-            Some(&digest),
+            Some(digest),
         )?;
 
         let endpoint = get_endpoint(&config, "sendmail-endpoint")?;
diff --git a/proxmox-notify/src/api/smtp.rs b/proxmox-notify/src/api/smtp.rs
index 41a94581b..456cbc31e 100644
--- a/proxmox-notify/src/api/smtp.rs
+++ b/proxmox-notify/src/api/smtp.rs
@@ -1,3 +1,4 @@
+use proxmox_config_digest::ConfigDigest;
 use proxmox_http_error::HttpError;
 
 use crate::Config;
@@ -89,7 +90,7 @@ pub fn update_endpoint(
     updater: SmtpConfigUpdater,
     private_endpoint_config_updater: SmtpPrivateConfigUpdater,
     delete: Option<&[DeleteableSmtpProperty]>,
-    digest: Option<&[u8]>,
+    digest: Option<ConfigDigest>,
 ) -> Result<(), HttpError> {
     super::verify_digest(config, digest)?;
 
@@ -276,7 +277,7 @@ pub mod tests {
                 Default::default(),
                 Default::default(),
                 None,
-                Some(&[0; 32]),
+                Some(ConfigDigest::from([0; 32])),
             )
             .is_err()
         );
@@ -289,7 +290,7 @@ pub mod tests {
         let mut config = empty_config();
         add_smtp_endpoint_for_test(&mut config, "smtp-endpoint")?;
 
-        let digest = config.digest;
+        let digest = config.digest.clone();
 
         update_endpoint(
             &mut config,
@@ -308,7 +309,7 @@ pub mod tests {
             },
             Default::default(),
             None,
-            Some(&digest),
+            Some(digest),
         )?;
 
         let endpoint = get_endpoint(&config, "smtp-endpoint")?;
diff --git a/proxmox-notify/src/api/webhook.rs b/proxmox-notify/src/api/webhook.rs
index 1d29dcc89..e79eeb7e9 100644
--- a/proxmox-notify/src/api/webhook.rs
+++ b/proxmox-notify/src/api/webhook.rs
@@ -2,6 +2,7 @@
 //!
 //! All methods assume that the caller has already done any required permission checks.
 
+use proxmox_config_digest::ConfigDigest;
 use proxmox_http_error::HttpError;
 use proxmox_schema::property_string::PropertyString;
 
@@ -136,7 +137,7 @@ pub fn update_endpoint(
     name: &str,
     config_updater: WebhookConfigUpdater,
     delete: Option<&[DeleteableWebhookProperty]>,
-    digest: Option<&[u8]>,
+    digest: Option<ConfigDigest>,
 ) -> Result<(), HttpError> {
     super::verify_digest(config, digest)?;
 
@@ -337,7 +338,7 @@ mod tests {
                 "webhook-endpoint",
                 Default::default(),
                 None,
-                Some(&[0; 32])
+                Some(ConfigDigest::from([0; 32]))
             )
             .is_err()
         );
@@ -350,7 +351,7 @@ mod tests {
         let mut config = empty_config();
         add_default_webhook_endpoint(&mut config)?;
 
-        let digest = config.digest;
+        let digest = config.digest.clone();
 
         update_endpoint(
             &mut config,
@@ -371,7 +372,7 @@ mod tests {
                 ..Default::default()
             },
             None,
-            Some(&digest),
+            Some(digest),
         )?;
 
         let endpoint = get_endpoint(&config, "webhook-endpoint")?;
diff --git a/proxmox-notify/src/config.rs b/proxmox-notify/src/config.rs
index c280e8285..176bc46b7 100644
--- a/proxmox-notify/src/config.rs
+++ b/proxmox-notify/src/config.rs
@@ -1,5 +1,6 @@
 use std::sync::OnceLock;
 
+use proxmox_config_digest::ConfigDigest;
 use proxmox_schema::{ApiType, ObjectSchema};
 use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin};
 
@@ -120,8 +121,8 @@ fn private_config_init() -> SectionConfig {
     config
 }
 
-pub fn config(raw_config: &str) -> Result<(SectionConfigData, [u8; 32]), Error> {
-    let digest = openssl::sha::sha256(raw_config.as_bytes());
+pub fn config(raw_config: &str) -> Result<(SectionConfigData, ConfigDigest), Error> {
+    let digest = ConfigDigest::from_slice(raw_config.as_bytes());
     let data = config_parser()
         .parse("notifications.cfg", raw_config)
         .map_err(Error::config_deserialization)?;
@@ -129,8 +130,8 @@ pub fn config(raw_config: &str) -> Result<(SectionConfigData, [u8; 32]), Error>
     Ok((data, digest))
 }
 
-pub fn private_config(raw_config: &str) -> Result<(SectionConfigData, [u8; 32]), Error> {
-    let digest = openssl::sha::sha256(raw_config.as_bytes());
+pub fn private_config(raw_config: &str) -> Result<(SectionConfigData, ConfigDigest), Error> {
+    let digest = ConfigDigest::from_slice(raw_config.as_bytes());
     let data = private_config_parser()
         .parse("priv/notifications.cfg", raw_config)
         .map_err(Error::config_deserialization)?;
diff --git a/proxmox-notify/src/lib.rs b/proxmox-notify/src/lib.rs
index 846e8315e..0a851239d 100644
--- a/proxmox-notify/src/lib.rs
+++ b/proxmox-notify/src/lib.rs
@@ -11,6 +11,7 @@ use serde_json::Value;
 use serde_json::json;
 use tracing::{error, info};
 
+use proxmox_config_digest::ConfigDigest;
 use proxmox_schema::api;
 use proxmox_section_config::SectionConfigData;
 use proxmox_uuid::Uuid;
@@ -204,7 +205,7 @@ impl Notification {
 pub struct Config {
     config: SectionConfigData,
     private_config: SectionConfigData,
-    digest: [u8; 32],
+    digest: ConfigDigest,
 }
 
 impl Config {
@@ -292,7 +293,7 @@ impl Config {
 
     /// Returns the SHA256 digest of the configuration.
     /// The digest is only computed once when the configuration deserialized.
-    pub fn digest(&self) -> &[u8; 32] {
+    pub fn digest(&self) -> &ConfigDigest {
         &self.digest
     }
 }
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 05/63] notify: remove static context and pass context as parameter
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (3 preceding siblings ...)
  2026-11-18  9:42 ` [PATCH proxmox v2 04/63] notify: use ConfigDigest instead of raw byte arrays Lukas Wagner
@ 2026-11-18  9:42 ` Lukas Wagner
  2026-11-18  9:42 ` [PATCH proxmox v2 06/63] notify: matcher: drop unused field matcher verifiers Lukas Wagner
                   ` (58 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:42 UTC (permalink / raw)
  To: pve-devel

Having static state in library code is not really a great practice for
various reasons, such as less clear concurrency semantics, worse
testability and the possibility to forget to initialize context before
first use.

Instead of injecting the context once via set_context as an
initialization step, we now pass it as a &dyn Context parameter at the
API level when sending notifications. As a result, the context object
now effectively lives in the application code instead of proxmox_notify.

The context is now hidden behind a thin wrapper around the actual trait
object. The trait was renamed to `ContextImpl`, with the wrapper taking
the old name of `Context`. This makes the trait object easier to use and
prepares for injecting the context to API handlers via #[state].

This is a breaking change; callers need to be adapted.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/api/common.rs            | 25 ++++++-----
 proxmox-notify/src/api/matcher.rs           | 10 +++--
 proxmox-notify/src/api/mod.rs               |  5 ++-
 proxmox-notify/src/context/mod.rs           | 47 ++++++++++++---------
 proxmox-notify/src/context/pbs.rs           |  4 +-
 proxmox-notify/src/context/pve.rs           |  4 +-
 proxmox-notify/src/context/test.rs          | 11 +++--
 proxmox-notify/src/endpoints/common/mail.rs | 16 +++++--
 proxmox-notify/src/endpoints/gotify.rs      | 17 +++++---
 proxmox-notify/src/endpoints/mod.rs         |  6 ++-
 proxmox-notify/src/endpoints/sendmail.rs    | 28 +++++++-----
 proxmox-notify/src/endpoints/smtp.rs        | 26 ++++++++----
 proxmox-notify/src/endpoints/webhook.rs     | 35 +++++++++------
 proxmox-notify/src/lib.rs                   | 44 ++++++++++++-------
 proxmox-notify/src/renderer/mod.rs          | 15 ++++---
 15 files changed, 183 insertions(+), 110 deletions(-)

diff --git a/proxmox-notify/src/api/common.rs b/proxmox-notify/src/api/common.rs
index bc89695f8..56a9797a9 100644
--- a/proxmox-notify/src/api/common.rs
+++ b/proxmox-notify/src/api/common.rs
@@ -1,13 +1,17 @@
 use proxmox_http_error::HttpError;
 
 use super::http_err;
-use crate::{Bus, Config, Error, Notification};
+use crate::{Bus, Config, Context, Error, Notification};
 
 /// Send a notification to a given target.
 ///
 /// The caller is responsible for any needed permission checks.
 /// Returns an `anyhow::Error` in case of an error.
-pub fn send(config: &Config, notification: &Notification) -> Result<(), HttpError> {
+pub fn send(
+    context: &Context,
+    config: &Config,
+    notification: &Notification,
+) -> Result<(), HttpError> {
     let bus = Bus::from_config(config).map_err(|err| {
         http_err!(
             INTERNAL_SERVER_ERROR,
@@ -15,7 +19,7 @@ pub fn send(config: &Config, notification: &Notification) -> Result<(), HttpErro
         )
     })?;
 
-    bus.send(notification);
+    bus.send(context, notification);
 
     Ok(())
 }
@@ -24,7 +28,7 @@ pub fn send(config: &Config, notification: &Notification) -> Result<(), HttpErro
 ///
 /// The caller is responsible for any needed permission checks.
 /// Returns an `anyhow::Error` if sending via the endpoint failed.
-pub fn test_target(config: &Config, endpoint: &str) -> Result<(), HttpError> {
+pub fn test_target(context: &Context, config: &Config, endpoint: &str) -> Result<(), HttpError> {
     let bus = Bus::from_config(config).map_err(|err| {
         http_err!(
             INTERNAL_SERVER_ERROR,
@@ -32,12 +36,13 @@ pub fn test_target(config: &Config, endpoint: &str) -> Result<(), HttpError> {
         )
     })?;
 
-    bus.test_target(endpoint).map_err(|err| match err {
-        Error::TargetDoesNotExist(endpoint) => {
-            http_err!(NOT_FOUND, "endpoint '{endpoint}' does not exist")
-        }
-        _ => http_err!(INTERNAL_SERVER_ERROR, "Could not test target: {err}"),
-    })?;
+    bus.test_target(context, endpoint)
+        .map_err(|err| match err {
+            Error::TargetDoesNotExist(endpoint) => {
+                http_err!(NOT_FOUND, "endpoint '{endpoint}' does not exist")
+            }
+            _ => http_err!(INTERNAL_SERVER_ERROR, "Could not test target: {err}"),
+        })?;
 
     Ok(())
 }
diff --git a/proxmox-notify/src/api/matcher.rs b/proxmox-notify/src/api/matcher.rs
index 3302c2c31..4600063e2 100644
--- a/proxmox-notify/src/api/matcher.rs
+++ b/proxmox-notify/src/api/matcher.rs
@@ -210,14 +210,17 @@ mod tests {
 
     use super::*;
 
-    use crate::matcher::expression::NotificationMatcher;
+    use crate::{context::test::test_context, matcher::expression::NotificationMatcher};
 
     fn empty_config() -> Config {
-        Config::new("", "").unwrap()
+        let context = test_context();
+        Config::new(&context, "", "").unwrap()
     }
 
     fn config_with_two_matchers() -> Config {
+        let context = test_context();
         Config::new(
+            &context,
             "
 sendmail: foo
     mailto test@example.com
@@ -499,7 +502,8 @@ matcher: matcher2
         // The normalized expression should stay the same after
         // a read/write cycle of the config
         let (raw_config, raw_private_config) = config.write().unwrap();
-        let config = Config::new(&raw_config, &raw_private_config).unwrap();
+        let context = test_context();
+        let config = Config::new(&context, &raw_config, &raw_private_config).unwrap();
         let matcher = get_matcher(&config, "matcher1")?;
 
         assert_eq!(matcher.expression, Some(stored));
diff --git a/proxmox-notify/src/api/mod.rs b/proxmox-notify/src/api/mod.rs
index 9697f9f17..dc84fbb10 100644
--- a/proxmox-notify/src/api/mod.rs
+++ b/proxmox-notify/src/api/mod.rs
@@ -285,11 +285,12 @@ fn remove_private_config_entry(config: &mut Config, name: &str) -> Result<(), Ht
 
 #[cfg(test)]
 mod test_helpers {
-    use crate::Config;
+    use crate::{Config, context::test};
 
     #[allow(unused)]
     pub fn empty_config() -> Config {
-        Config::new("", "").unwrap()
+        let context = test::test_context();
+        Config::new(&context, "", "").unwrap()
     }
 }
 
diff --git a/proxmox-notify/src/context/mod.rs b/proxmox-notify/src/context/mod.rs
index a81a35caa..71d94c6e3 100644
--- a/proxmox-notify/src/context/mod.rs
+++ b/proxmox-notify/src/context/mod.rs
@@ -1,5 +1,6 @@
 use std::fmt::Debug;
-use std::sync::Mutex;
+use std::ops::Deref;
+use std::sync::Arc;
 
 use crate::error::BoxedError;
 use crate::renderer::TemplateSource;
@@ -11,7 +12,29 @@ pub mod pbs;
 #[cfg(feature = "pve-context")]
 pub mod pve;
 #[cfg(test)]
-mod test;
+pub(crate) mod test;
+
+/// Product-specific context.
+///
+/// This is a thin convenience wrapper around the actual [`ContextImpl`] trait object.
+#[derive(Clone)]
+pub struct Context(Arc<dyn ContextImpl>);
+
+impl Context {
+    /// Create notification context by wrapping the product-specific context
+    /// implementation.
+    pub fn new(context_impl: impl ContextImpl + 'static) -> Self {
+        Self(Arc::new(context_impl))
+    }
+}
+
+impl Deref for Context {
+    type Target = dyn ContextImpl;
+
+    fn deref(&self) -> &Self::Target {
+        self.0.as_ref()
+    }
+}
 
 // NOTE: Don't use proxmox_notify::Error in this trait, rather return a [`BoxedError`]. You
 // may wrap the boxed error into an appropriate variant of proxmox_notify::Error at
@@ -19,7 +42,7 @@ mod test;
 // not have to instantiate proxmox_notify::Error themselves.
 
 /// Product-specific context
-pub trait Context: Send + Sync + Debug {
+pub trait ContextImpl: Send + Sync + Debug {
     /// Look up a user's email address from users.cfg
     fn lookup_email_for_user(&self, user: &str) -> Option<String>;
     /// Default mail author for mail-based targets
@@ -38,21 +61,3 @@ pub trait Context: Send + Sync + Debug {
         source: TemplateSource,
     ) -> Result<Option<String>, BoxedError>;
 }
-
-#[cfg(not(test))]
-static CONTEXT: Mutex<Option<&'static dyn Context>> = Mutex::new(None);
-#[cfg(test)]
-static CONTEXT: Mutex<Option<&'static dyn Context>> = Mutex::new(Some(&test::TestContext));
-
-/// Set the product-specific context
-pub fn set_context(context: &'static dyn Context) {
-    *CONTEXT.lock().unwrap() = Some(context);
-}
-
-/// Get product-specific context.
-///
-/// Panics if the context has not been set yet.
-#[allow(unused)] // context is not used if all endpoint features are disabled
-pub(crate) fn context() -> &'static dyn Context {
-    (*CONTEXT.lock().unwrap()).expect("context for proxmox-notify has not been set yet")
-}
diff --git a/proxmox-notify/src/context/pbs.rs b/proxmox-notify/src/context/pbs.rs
index f484f90c8..a979f25d6 100644
--- a/proxmox-notify/src/context/pbs.rs
+++ b/proxmox-notify/src/context/pbs.rs
@@ -6,7 +6,7 @@ use tracing::error;
 use proxmox_schema::{ObjectSchema, Schema, StringSchema};
 use proxmox_section_config::{SectionConfig, SectionConfigPlugin};
 
-use crate::context::{Context, common};
+use crate::context::{ContextImpl, common};
 use crate::error::BoxedError;
 use crate::renderer::TemplateSource;
 
@@ -80,7 +80,7 @@ pub struct PBSContext;
 
 pub static PBS_CONTEXT: PBSContext = PBSContext;
 
-impl Context for PBSContext {
+impl ContextImpl for PBSContext {
     fn lookup_email_for_user(&self, user: &str) -> Option<String> {
         let content = common::attempt_file_read(PBS_USER_CFG_FILENAME);
         content.and_then(|content| lookup_mail_address(&content, user))
diff --git a/proxmox-notify/src/context/pve.rs b/proxmox-notify/src/context/pve.rs
index ba84da920..b2d08acc2 100644
--- a/proxmox-notify/src/context/pve.rs
+++ b/proxmox-notify/src/context/pve.rs
@@ -1,6 +1,6 @@
 use std::path::Path;
 
-use crate::context::{Context, common};
+use crate::context::{ContextImpl, common};
 use crate::error::BoxedError;
 use crate::renderer::TemplateSource;
 
@@ -30,7 +30,7 @@ matcher: default-matcher
 #[derive(Debug)]
 pub struct PVEContext;
 
-impl Context for PVEContext {
+impl ContextImpl for PVEContext {
     fn lookup_email_for_user(&self, user: &str) -> Option<String> {
         let content = common::attempt_file_read("/etc/pve/user.cfg");
         content.and_then(|content| lookup_mail_address(&content, user))
diff --git a/proxmox-notify/src/context/test.rs b/proxmox-notify/src/context/test.rs
index 7380a0545..b959cb929 100644
--- a/proxmox-notify/src/context/test.rs
+++ b/proxmox-notify/src/context/test.rs
@@ -1,11 +1,12 @@
-use crate::context::Context;
+use crate::Context;
+use crate::context::ContextImpl;
 use crate::error::BoxedError;
 use crate::renderer::TemplateSource;
 
 #[derive(Debug)]
-pub struct TestContext;
+pub(crate) struct TestContext;
 
-impl Context for TestContext {
+impl ContextImpl for TestContext {
     fn lookup_email_for_user(&self, user: &str) -> Option<String> {
         user.split_once('@').and_then(|(user, realm)| {
             if realm == "pve" {
@@ -41,3 +42,7 @@ impl Context for TestContext {
         Ok(Some(String::new()))
     }
 }
+
+pub(crate) fn test_context() -> Context {
+    Context::new(TestContext)
+}
diff --git a/proxmox-notify/src/endpoints/common/mail.rs b/proxmox-notify/src/endpoints/common/mail.rs
index 074712cff..736f2ac66 100644
--- a/proxmox-notify/src/endpoints/common/mail.rs
+++ b/proxmox-notify/src/endpoints/common/mail.rs
@@ -1,11 +1,15 @@
-use crate::context;
+use crate::Context;
 
 /// Get list of email recipients from a list of email addresses and users.
 ///
 /// Any user passed in the user list will be looked up in the user configuration to
 /// obtain this user's email address. The list of returned email addresses does
 /// not contain any duplicates.
-pub(crate) fn get_recipients(email_addrs: &[String], users: &[String]) -> Vec<String> {
+pub(crate) fn get_recipients(
+    context: &Context,
+    email_addrs: &[String],
+    users: &[String],
+) -> Vec<String> {
     let mut recipients = Vec::new();
 
     for addr in email_addrs {
@@ -15,7 +19,7 @@ pub(crate) fn get_recipients(email_addrs: &[String], users: &[String]) -> Vec<St
     }
 
     for user in users {
-        match context::context().lookup_email_for_user(user) {
+        match context.lookup_email_for_user(user) {
             Some(address) => {
                 if !recipients.contains(&address) {
                     recipients.push(address);
@@ -32,6 +36,8 @@ pub(crate) fn get_recipients(email_addrs: &[String], users: &[String]) -> Vec<St
 
 #[cfg(test)]
 mod tests {
+    use crate::context::test;
+
     use super::*;
 
     #[test]
@@ -54,7 +60,9 @@ mod tests {
             "user2@example.com",
         ];
 
-        let addrs = get_recipients(&emails, &users);
+        let context = test::test_context();
+
+        let addrs = get_recipients(&context, &emails, &users);
 
         assert_eq!(addrs, expected);
     }
diff --git a/proxmox-notify/src/endpoints/gotify.rs b/proxmox-notify/src/endpoints/gotify.rs
index 6b8499827..7fe74f862 100644
--- a/proxmox-notify/src/endpoints/gotify.rs
+++ b/proxmox-notify/src/endpoints/gotify.rs
@@ -9,10 +9,9 @@ use proxmox_http::{HttpClient, HttpOptions, ProxyConfig};
 use proxmox_schema::api_types::COMMENT_SCHEMA;
 use proxmox_schema::{Updater, api};
 
-use crate::context::context;
 use crate::renderer::TemplateType;
 use crate::schema::ENTITY_NAME_SCHEMA;
-use crate::{Content, Error, Notification, Origin, Severity, renderer};
+use crate::{Content, Context, Error, Notification, Origin, Severity, renderer};
 
 use super::Endpoint;
 
@@ -98,16 +97,20 @@ pub enum DeleteableGotifyProperty {
 }
 
 impl Endpoint for GotifyEndpoint {
-    fn send(&self, notification: &Notification) -> Result<(), Error> {
+    fn send(&self, context: &Context, notification: &Notification) -> Result<(), Error> {
         let (title, message) = match &notification.content {
             Content::Template {
                 template_name,
                 data,
             } => {
                 let rendered_title =
-                    renderer::render_template(TemplateType::Subject, template_name, data)?;
-                let rendered_message =
-                    renderer::render_template(TemplateType::PlaintextBody, template_name, data)?;
+                    renderer::render_template(context, TemplateType::Subject, template_name, data)?;
+                let rendered_message = renderer::render_template(
+                    context,
+                    TemplateType::PlaintextBody,
+                    template_name,
+                    data,
+                )?;
 
                 (rendered_title, rendered_message)
             }
@@ -145,7 +148,7 @@ impl Endpoint for GotifyEndpoint {
             ),
         ]);
 
-        let proxy_config = context()
+        let proxy_config = context
             .http_proxy_config()
             .map(|url| ProxyConfig::parse_proxy_url(&url))
             .transpose()
diff --git a/proxmox-notify/src/endpoints/mod.rs b/proxmox-notify/src/endpoints/mod.rs
index 757b251c1..ea77d4243 100644
--- a/proxmox-notify/src/endpoints/mod.rs
+++ b/proxmox-notify/src/endpoints/mod.rs
@@ -1,4 +1,6 @@
-use crate::{Error, Notification};
+use crate::Context;
+use crate::Error;
+use crate::Notification;
 
 #[cfg(feature = "gotify")]
 pub mod gotify;
@@ -14,7 +16,7 @@ mod common;
 /// Notification endpoint trait, implemented by all endpoint plugins
 pub(crate) trait Endpoint {
     /// Send a notification to this endpoint.
-    fn send(&self, notification: &Notification) -> Result<(), Error>;
+    fn send(&self, context: &Context, notification: &Notification) -> Result<(), Error>;
 
     /// The name/identifier for this endpoint
     fn name(&self) -> &str;
diff --git a/proxmox-notify/src/endpoints/sendmail.rs b/proxmox-notify/src/endpoints/sendmail.rs
index 3f5f66db6..0d60308d2 100644
--- a/proxmox-notify/src/endpoints/sendmail.rs
+++ b/proxmox-notify/src/endpoints/sendmail.rs
@@ -4,11 +4,10 @@ use serde::{Deserialize, Serialize};
 use proxmox_schema::api_types::COMMENT_SCHEMA;
 use proxmox_schema::{Updater, api};
 
-use crate::context;
 use crate::endpoints::common::mail;
 use crate::renderer::TemplateType;
 use crate::schema::{EMAIL_SCHEMA, ENTITY_NAME_SCHEMA, USER_SCHEMA};
-use crate::{Content, Error, Notification, Origin, renderer};
+use crate::{Content, Context, Error, Notification, Origin, renderer};
 
 use super::Endpoint;
 
@@ -106,8 +105,9 @@ pub struct SendmailEndpoint {
 }
 
 impl Endpoint for SendmailEndpoint {
-    fn send(&self, notification: &Notification) -> Result<(), Error> {
+    fn send(&self, context: &Context, notification: &Notification) -> Result<(), Error> {
         let recipients = mail::get_recipients(
+            context,
             self.config.mailto.as_slice(),
             self.config.mailto_user.as_slice(),
         );
@@ -117,7 +117,7 @@ impl Endpoint for SendmailEndpoint {
             .config
             .from_address
             .clone()
-            .unwrap_or_else(|| context().default_sendmail_from());
+            .unwrap_or_else(|| context.default_sendmail_from());
 
         match &notification.content {
             Content::Template {
@@ -125,17 +125,25 @@ impl Endpoint for SendmailEndpoint {
                 data,
             } => {
                 let subject =
-                    renderer::render_template(TemplateType::Subject, template_name, data)?;
-                let html_part =
-                    renderer::render_template(TemplateType::HtmlBody, template_name, data)?;
-                let text_part =
-                    renderer::render_template(TemplateType::PlaintextBody, template_name, data)?;
+                    renderer::render_template(context, TemplateType::Subject, template_name, data)?;
+                let html_part = renderer::render_template(
+                    context,
+                    TemplateType::HtmlBody,
+                    template_name,
+                    data,
+                )?;
+                let text_part = renderer::render_template(
+                    context,
+                    TemplateType::PlaintextBody,
+                    template_name,
+                    data,
+                )?;
 
                 let author = self
                     .config
                     .author
                     .clone()
-                    .unwrap_or_else(|| context().default_sendmail_author());
+                    .unwrap_or_else(|| context.default_sendmail_author());
 
                 let mut mail = Mail::new(&author, &mailfrom, &subject, &text_part)
                     .with_html_alt(&html_part)
diff --git a/proxmox-notify/src/endpoints/smtp.rs b/proxmox-notify/src/endpoints/smtp.rs
index e73151797..b64bb5596 100644
--- a/proxmox-notify/src/endpoints/smtp.rs
+++ b/proxmox-notify/src/endpoints/smtp.rs
@@ -10,11 +10,10 @@ use serde::{Deserialize, Serialize};
 use proxmox_schema::api_types::COMMENT_SCHEMA;
 use proxmox_schema::{Updater, api};
 
-use crate::context::context;
 use crate::endpoints::common::mail;
 use crate::renderer::TemplateType;
 use crate::schema::{EMAIL_SCHEMA, ENTITY_NAME_SCHEMA, USER_SCHEMA};
-use crate::{Content, Error, Notification, Origin, renderer};
+use crate::{Content, Context, Error, Notification, Origin, renderer};
 
 use super::Endpoint;
 
@@ -160,7 +159,7 @@ pub struct SmtpEndpoint {
 }
 
 impl Endpoint for SmtpEndpoint {
-    fn send(&self, notification: &Notification) -> Result<(), Error> {
+    fn send(&self, context: &Context, notification: &Notification) -> Result<(), Error> {
         let tls_parameters = TlsParameters::new(self.config.server.clone())
             .map_err(|err| Error::invalid_config_with_source("invalid smtp server URL", err))?;
 
@@ -197,6 +196,7 @@ impl Endpoint for SmtpEndpoint {
         let transport = transport_builder.build();
 
         let recipients = mail::get_recipients(
+            context,
             self.config.mailto.as_slice(),
             self.config.mailto_user.as_slice(),
         );
@@ -215,7 +215,7 @@ impl Endpoint for SmtpEndpoint {
             .config
             .author
             .clone()
-            .unwrap_or_else(|| context().default_sendmail_author());
+            .unwrap_or_else(|| context.default_sendmail_author());
 
         let quoted_author = quote_name_if_needed(&author);
 
@@ -232,11 +232,19 @@ impl Endpoint for SmtpEndpoint {
                 data,
             } => {
                 let subject =
-                    renderer::render_template(TemplateType::Subject, template_name, data)?;
-                let html_part =
-                    renderer::render_template(TemplateType::HtmlBody, template_name, data)?;
-                let text_part =
-                    renderer::render_template(TemplateType::PlaintextBody, template_name, data)?;
+                    renderer::render_template(context, TemplateType::Subject, template_name, data)?;
+                let html_part = renderer::render_template(
+                    context,
+                    TemplateType::HtmlBody,
+                    template_name,
+                    data,
+                )?;
+                let text_part = renderer::render_template(
+                    context,
+                    TemplateType::PlaintextBody,
+                    template_name,
+                    data,
+                )?;
 
                 email_builder = email_builder.subject(subject);
 
diff --git a/proxmox-notify/src/endpoints/webhook.rs b/proxmox-notify/src/endpoints/webhook.rs
index 47d9e0586..e3ec9e5ef 100644
--- a/proxmox-notify/src/endpoints/webhook.rs
+++ b/proxmox-notify/src/endpoints/webhook.rs
@@ -24,10 +24,9 @@ use proxmox_http::{HttpClient, HttpOptions, ProxyConfig};
 use proxmox_schema::api_types::{COMMENT_SCHEMA, HTTP_URL_SCHEMA};
 use proxmox_schema::{ApiStringFormat, ApiType, Schema, StringSchema, Updater, api};
 
-use crate::context::context;
 use crate::renderer::TemplateType;
 use crate::schema::ENTITY_NAME_SCHEMA;
-use crate::{Content, Error, Notification, Origin, renderer};
+use crate::{Content, Context, Error, Notification, Origin, renderer};
 
 use super::Endpoint;
 
@@ -242,10 +241,10 @@ pub const KEY_AND_BASE64_VALUE_SCHEMA: Schema =
 
 impl Endpoint for WebhookEndpoint {
     /// Send a notification to a webhook endpoint.
-    fn send(&self, notification: &Notification) -> Result<(), Error> {
-        let request = self.build_request(notification)?;
+    fn send(&self, context: &Context, notification: &Notification) -> Result<(), Error> {
+        let request = self.build_request(context, notification)?;
 
-        self.create_client()?
+        self.create_client(context)?
             .request(request)
             .map_err(|err| self.mask_secret_in_error(err))
             .map_err(Error::http_request_failed)?;
@@ -265,8 +264,8 @@ impl Endpoint for WebhookEndpoint {
 }
 
 impl WebhookEndpoint {
-    fn create_client(&self) -> Result<Client, Error> {
-        let proxy_config = context()
+    fn create_client(&self, context: &Context) -> Result<Client, Error> {
+        let proxy_config = context
             .http_proxy_config()
             .map(|url| ProxyConfig::parse_proxy_url(&url))
             .transpose()
@@ -280,16 +279,24 @@ impl WebhookEndpoint {
         Ok(Client::new_with_timeout(options, HTTP_TIMEOUT))
     }
 
-    fn build_request(&self, notification: &Notification) -> Result<Request<String>, Error> {
+    fn build_request(
+        &self,
+        context: &Context,
+        notification: &Notification,
+    ) -> Result<Request<String>, Error> {
         let (title, message) = match &notification.content {
             Content::Template {
                 template_name,
                 data,
             } => {
                 let rendered_title =
-                    renderer::render_template(TemplateType::Subject, template_name, data)?;
-                let rendered_message =
-                    renderer::render_template(TemplateType::PlaintextBody, template_name, data)?;
+                    renderer::render_template(context, TemplateType::Subject, template_name, data)?;
+                let rendered_message = renderer::render_template(
+                    context,
+                    TemplateType::PlaintextBody,
+                    template_name,
+                    data,
+                )?;
 
                 (rendered_title, rendered_message)
             }
@@ -511,7 +518,7 @@ mod tests {
     use std::collections::HashMap;
 
     use super::*;
-    use crate::Severity;
+    use crate::{Severity, context::test};
 
     #[test]
     fn test_build_request() {
@@ -566,7 +573,9 @@ hello%20world
 
         let notification = Notification::from_template(Severity::Info, "foo", json!({}), data);
 
-        let request = endpoint.build_request(&notification).unwrap();
+        let context = test::test_context();
+
+        let request = endpoint.build_request(&context, &notification).unwrap();
 
         assert_eq!(request.uri(), "http://localhost/hello%20world");
         assert_eq!(request.body(), expected_body);
diff --git a/proxmox-notify/src/lib.rs b/proxmox-notify/src/lib.rs
index 0a851239d..6675a9f76 100644
--- a/proxmox-notify/src/lib.rs
+++ b/proxmox-notify/src/lib.rs
@@ -5,7 +5,6 @@ use std::collections::HashMap;
 use std::fmt::Display;
 use std::str::FromStr;
 
-use context::context;
 use serde::{Deserialize, Serialize};
 use serde_json::Value;
 use serde_json::json;
@@ -29,8 +28,10 @@ pub mod schema;
 mod error;
 pub use error::Error;
 
-use endpoints::Endpoint;
+pub use context::Context;
+pub use context::ContextImpl;
 
+use endpoints::Endpoint;
 
 #[api()]
 #[derive(Clone, Debug, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd)]
@@ -210,11 +211,15 @@ pub struct Config {
 
 impl Config {
     /// Parse raw config
-    pub fn new(raw_config: &str, raw_private_config: &str) -> Result<Self, Error> {
+    pub fn new(
+        context: &Context,
+        raw_config: &str,
+        raw_private_config: &str,
+    ) -> Result<Self, Error> {
         let (mut config, digest) = config::config(raw_config)?;
         let (private_config, _) = config::private_config(raw_private_config)?;
 
-        let default_config = context().default_config();
+        let default_config = context.default_config();
 
         let builtin_config = config::config_parser()
             .parse("<builtin>", default_config)
@@ -467,7 +472,7 @@ impl Bus {
     /// the notification.
     ///
     /// Any errors will not be returned but only logged.
-    pub fn send(&self, notification: &Notification) {
+    pub fn send(&self, context: &Context, notification: &Notification) {
         let targets = matcher::check_matches(self.matchers.as_slice(), notification);
 
         for target in targets {
@@ -480,7 +485,7 @@ impl Bus {
                     continue;
                 }
 
-                match endpoint.send(notification) {
+                match endpoint.send(context, notification) {
                     Ok(_) => {
                         info!("notified via target `{name}`");
                     }
@@ -499,7 +504,7 @@ impl Bus {
     ///
     /// In contrast to the `send` function, this function will return
     /// any errors to the caller.
-    pub fn test_target(&self, target: &str) -> Result<(), Error> {
+    pub fn test_target(&self, context: &Context, target: &str) -> Result<(), Error> {
         let notification = Notification {
             metadata: Metadata {
                 severity: Severity::Info,
@@ -515,7 +520,7 @@ impl Bus {
         };
 
         if let Some(endpoint) = self.endpoints.get(target) {
-            endpoint.send(&notification)?;
+            endpoint.send(context, &notification)?;
         } else {
             return Err(Error::target_does_not_exist(target));
         }
@@ -530,6 +535,7 @@ mod tests {
 
     use proxmox_match_expression::Expression;
 
+    use crate::context::test;
     use crate::matcher::{expression::NotificationMatcher, severity::SeverityMatcher};
 
     use super::*;
@@ -543,7 +549,7 @@ mod tests {
     }
 
     impl Endpoint for MockEndpoint {
-        fn send(&self, message: &Notification) -> Result<(), Error> {
+        fn send(&self, _context: &Context, message: &Notification) -> Result<(), Error> {
             self.messages.borrow_mut().push(message.clone());
 
             Ok(())
@@ -577,6 +583,7 @@ mod tests {
 
     #[test]
     fn test_add_mock_endpoint() -> Result<(), Error> {
+        let context = test::test_context();
         let mock = MockEndpoint::new("endpoint");
 
         let mut bus = Bus::default();
@@ -591,12 +598,15 @@ mod tests {
         bus.add_matcher(matcher);
 
         // Send directly to endpoint
-        bus.send(&Notification::from_template(
-            Severity::Info,
-            "test",
-            Default::default(),
-            Default::default(),
-        ));
+        bus.send(
+            &context,
+            &Notification::from_template(
+                Severity::Info,
+                "test",
+                Default::default(),
+                Default::default(),
+            ),
+        );
         let messages = mock.messages();
         assert_eq!(messages.len(), 1);
 
@@ -605,6 +615,8 @@ mod tests {
 
     #[test]
     fn test_multiple_endpoints_with_different_matchers() -> Result<(), Error> {
+        let context = test::test_context();
+
         let endpoint1 = MockEndpoint::new("mock1");
         let endpoint2 = MockEndpoint::new("mock2");
 
@@ -645,7 +657,7 @@ mod tests {
                 Default::default(),
             );
 
-            bus.send(&notification);
+            bus.send(&context, &notification);
         };
 
         send_with_severity(Severity::Info);
diff --git a/proxmox-notify/src/renderer/mod.rs b/proxmox-notify/src/renderer/mod.rs
index 1bccf75bf..da6279a1d 100644
--- a/proxmox-notify/src/renderer/mod.rs
+++ b/proxmox-notify/src/renderer/mod.rs
@@ -2,8 +2,9 @@
 
 use std::{fmt::Display, time::Duration};
 
+use handlebars::Context as HandlebarsContext;
 use handlebars::{
-    Context, Handlebars, Helper, HelperDef, HelperResult, Output, RenderContext, RenderErrorReason,
+    Handlebars, Helper, HelperDef, HelperResult, Output, RenderContext, RenderErrorReason,
 };
 use serde::{Deserialize, Serialize};
 use serde_json::Value;
@@ -12,7 +13,7 @@ use tracing::error;
 use proxmox_human_byte::HumanByte;
 use proxmox_time::TimeSpan;
 
-use crate::{Error, context};
+use crate::{Context, Error};
 
 mod html;
 mod plaintext;
@@ -76,7 +77,7 @@ fn value_to_timestamp(val: &Value) -> Option<String> {
 fn handlebars_relative_percentage_helper(
     h: &Helper,
     _: &Handlebars,
-    _: &Context,
+    _: &HandlebarsContext,
     _rc: &mut RenderContext,
     out: &mut dyn Output,
 ) -> HelperResult {
@@ -159,7 +160,7 @@ impl ValueRenderFunction {
             Box::new(
                 move |h: &Helper,
                       _r: &Handlebars,
-                      _: &Context,
+                      _: &HandlebarsContext,
                       _rc: &mut RenderContext,
                       out: &mut dyn Output|
                       -> HelperResult {
@@ -267,12 +268,13 @@ impl BlockRenderFunctions {
 }
 
 fn render_template_impl(
+    context: &Context,
     data: &Value,
     renderer: TemplateType,
     filename: &str,
     source: TemplateSource,
 ) -> Result<Option<String>, Error> {
-    let template_string = context::context()
+    let template_string = context
         .lookup_template(filename, None, source)
         .map_err(Error::template_could_not_be_read)?;
 
@@ -310,6 +312,7 @@ fn render_template_impl(
 /// HTML template is found or renderable, it falls back to use a plaintext
 /// template encapsulated in a pre-formatted HTML block (<pre>).
 pub fn render_template(
+    context: &Context,
     mut ty: TemplateType,
     template: &str,
     data: &Value,
@@ -318,7 +321,7 @@ pub fn render_template(
 
     loop {
         let filename = format!("{template}-{suffix}", suffix = ty.file_suffix());
-        let result = render_template_impl(data, ty, &filename, source);
+        let result = render_template_impl(context, data, ty, &filename, source);
 
         match result {
             Ok(Some(s)) => {
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 06/63] notify: matcher: drop unused field matcher verifiers
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (4 preceding siblings ...)
  2026-11-18  9:42 ` [PATCH proxmox v2 05/63] notify: remove static context and pass context as parameter Lukas Wagner
@ 2026-11-18  9:42 ` Lukas Wagner
  2026-11-18  9:42 ` [PATCH proxmox v2 07/63] notify: introduce 'send-impl', 'api-impl' and 'api-types' features Lukas Wagner
                   ` (57 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:42 UTC (permalink / raw)
  To: pve-devel

These were never used, so they can be dropped. The schema is enforced
during deserialization using a regex, and when serializing, the value is
constructed from Rust types, so it is bound to be valid.

This change also lets us drop the anyhow dependency completely.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/Cargo.toml           |  1 -
 proxmox-notify/src/matcher/field.rs | 18 +-----------------
 2 files changed, 1 insertion(+), 18 deletions(-)

diff --git a/proxmox-notify/Cargo.toml b/proxmox-notify/Cargo.toml
index 8968a14f8..2c085ae68 100644
--- a/proxmox-notify/Cargo.toml
+++ b/proxmox-notify/Cargo.toml
@@ -12,7 +12,6 @@ repository.workspace = true
 rust-version.workspace = true
 
 [dependencies]
-anyhow.workspace = true
 const_format.workspace = true
 handlebars = { workspace = true }
 http = { workspace = true, optional = true }
diff --git a/proxmox-notify/src/matcher/field.rs b/proxmox-notify/src/matcher/field.rs
index 0e145f81b..f609421ce 100644
--- a/proxmox-notify/src/matcher/field.rs
+++ b/proxmox-notify/src/matcher/field.rs
@@ -88,9 +88,7 @@ pub mod inline {
 
     use const_format::concatcp;
 
-    use proxmox_schema::{
-        ApiStringFormat, Schema, StringSchema, api_types::SAFE_ID_REGEX_STR, const_regex,
-    };
+    use proxmox_schema::{api_types::SAFE_ID_REGEX_STR, const_regex};
 
     use super::*;
 
@@ -98,20 +96,6 @@ pub mod inline {
         pub MATCH_FIELD_ENTRY_REGEX = concatcp!(r"^(?:(exact|regex):)?(", SAFE_ID_REGEX_STR, r")=(.*)$");
     }
 
-    pub const MATCH_FIELD_ENTRY_FORMAT: ApiStringFormat =
-        ApiStringFormat::VerifyFn(verify_inline_field_matcher);
-
-    fn verify_inline_field_matcher(s: &str) -> Result<(), anyhow::Error> {
-        let _: InlineFieldMatcher = s.parse()?;
-        Ok(())
-    }
-
-    pub const MATCH_FIELD_ENTRY_SCHEMA: Schema = StringSchema::new("Match metadata field.")
-        .format(&MATCH_FIELD_ENTRY_FORMAT)
-        .min_length(1)
-        .max_length(1024)
-        .schema();
-
     /// Check if the notification metadata fields match
     /// This is a wrapper that serializes into an inline format that can be used
     /// in a section config key-value pair.
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 07/63] notify: introduce 'send-impl', 'api-impl' and 'api-types' features
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (5 preceding siblings ...)
  2026-11-18  9:42 ` [PATCH proxmox v2 06/63] notify: matcher: drop unused field matcher verifiers Lukas Wagner
@ 2026-11-18  9:42 ` Lukas Wagner
  2026-11-18  9:42 ` [PATCH proxmox v2 08/63] notify: matcher: make matcher validation methods public Lukas Wagner
                   ` (56 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:42 UTC (permalink / raw)
  To: pve-devel

The old per-endpoint-type features turned out to be not super useful
(all products support all endpoints), so they were merged into a
single 'send-impl' feature.

In anticipation of a Rust-based UI for changing notification
configuration, a new 'api-types' feature was introduced and the config
types for endpoints and matchers moved to a new 'api_types' module.

Furthermore, the existing API method implementation is now gated behind
the 'api-impl' feature.

This change only moves existing code and modifies feature gates. It is
inherently a breaking change, but does not change functionality.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/Cargo.toml                     |  51 +++--
 proxmox-notify/src/api/gotify.rs              |   2 +-
 proxmox-notify/src/api/matcher.rs             |   8 +-
 proxmox-notify/src/api/mod.rs                 |  45 +---
 proxmox-notify/src/api/sendmail.rs            |   2 +-
 proxmox-notify/src/api/smtp.rs                |   5 +-
 proxmox-notify/src/api/webhook.rs             |   4 +-
 proxmox-notify/src/api_types/gotify.rs        |  68 ++++++
 .../src/{ => api_types}/matcher/calendar.rs   |   4 +-
 .../src/{ => api_types}/matcher/expression.rs |   2 +-
 .../src/{ => api_types}/matcher/field.rs      |   2 +-
 .../src/{ => api_types}/matcher/mod.rs        |   4 +-
 .../src/{ => api_types}/matcher/severity.rs   |   2 +-
 proxmox-notify/src/api_types/mod.rs           |  21 ++
 proxmox-notify/src/api_types/sendmail.rs      |  96 ++++++++
 proxmox-notify/src/api_types/smtp.rs          | 136 +++++++++++
 proxmox-notify/src/api_types/webhook.rs       | 208 +++++++++++++++++
 proxmox-notify/src/config.rs                  |  70 ++----
 proxmox-notify/src/context/pbs.rs             |   3 +-
 proxmox-notify/src/context/pve.rs             |   3 +-
 proxmox-notify/src/endpoints/common/mod.rs    |   1 -
 proxmox-notify/src/endpoints/gotify.rs        |  72 +-----
 proxmox-notify/src/endpoints/mod.rs           |   4 -
 proxmox-notify/src/endpoints/sendmail.rs      |  96 +-------
 proxmox-notify/src/endpoints/smtp.rs          | 138 +-----------
 proxmox-notify/src/endpoints/webhook.rs       | 213 +-----------------
 proxmox-notify/src/lib.rs                     | 139 ++++++------
 27 files changed, 694 insertions(+), 705 deletions(-)
 create mode 100644 proxmox-notify/src/api_types/gotify.rs
 rename proxmox-notify/src/{ => api_types}/matcher/calendar.rs (96%)
 rename proxmox-notify/src/{ => api_types}/matcher/expression.rs (98%)
 rename proxmox-notify/src/{ => api_types}/matcher/field.rs (99%)
 rename proxmox-notify/src/{ => api_types}/matcher/mod.rs (99%)
 rename proxmox-notify/src/{ => api_types}/matcher/severity.rs (97%)
 create mode 100644 proxmox-notify/src/api_types/mod.rs
 create mode 100644 proxmox-notify/src/api_types/sendmail.rs
 create mode 100644 proxmox-notify/src/api_types/smtp.rs
 create mode 100644 proxmox-notify/src/api_types/webhook.rs

diff --git a/proxmox-notify/Cargo.toml b/proxmox-notify/Cargo.toml
index 2c085ae68..6bb4871f7 100644
--- a/proxmox-notify/Cargo.toml
+++ b/proxmox-notify/Cargo.toml
@@ -13,27 +13,27 @@ rust-version.workspace = true
 
 [dependencies]
 const_format.workspace = true
-handlebars = { workspace = true }
+handlebars = { workspace = true, optional = true }
 http = { workspace = true, optional = true }
 lettre = { workspace = true, optional = true }
 tracing.workspace = true
 mail-parser = { workspace = true, optional = true }
 percent-encoding = { workspace = true, optional = true }
-regex.workspace = true
+regex = { workspace = true, optional = true }
 serde = { workspace = true, features = ["derive"] }
 serde_json.workspace = true
-serde_regex.workspace = true
+serde_regex = { workspace = true, optional = true }
 thiserror.workspace = true
 
-proxmox-api-macro.workspace = true
+proxmox-api-macro = { workspace = true, optional = true }
 proxmox-base64 = { workspace = true, optional = true }
-proxmox-config-digest = { workspace = true, features = ["openssl"] }
+proxmox-config-digest = { workspace = true, features = ["openssl"], optional = true }
 proxmox-http = { workspace = true, features = ["client-sync"], optional = true }
-proxmox-http-error.workspace = true
-proxmox-human-byte.workspace = true
-proxmox-match-expression.workspace = true
+proxmox-http-error = { workspace = true, optional = true }
+proxmox-human-byte = { workspace = true, optional = true }
+proxmox-match-expression = { workspace = true, optional = true }
 proxmox-schema = { workspace = true, features = ["api-macro", "api-types"] }
-proxmox-section-config = { workspace = true }
+proxmox-section-config = { workspace = true, optional = true }
 proxmox-serde.workspace = true
 proxmox-sendmail = { workspace = true, optional = true }
 proxmox-sys = { workspace = true, optional = true }
@@ -41,12 +41,35 @@ proxmox-time.workspace = true
 proxmox-uuid = { workspace = true, features = ["serde"] }
 
 [features]
-default = ["sendmail", "gotify", "smtp", "webhook"]
+default = ["send-impl", "api-types"]
+api-impl = [
+    "api-types",
+    "dep:proxmox-config-digest",
+    "dep:proxmox-http-error",
+    "dep:proxmox-section-config",
+]
+api-types = [
+    "dep:proxmox-api-macro",
+    "dep:proxmox-base64",
+    "dep:proxmox-match-expression",
+    "dep:regex",
+    "dep:serde_regex",
+]
+send-impl = [
+    "api-types",
+    "dep:http",
+    "dep:lettre",
+    "dep:handlebars",
+    "dep:proxmox-config-digest",
+    "dep:percent-encoding",
+    "dep:proxmox-base64",
+    "dep:proxmox-http",
+    "dep:proxmox-human-byte",
+    "dep:proxmox-section-config",
+    "dep:proxmox-sendmail",
+    "dep:proxmox-sys",
+]
 mail-forwarder = ["dep:mail-parser", "dep:proxmox-sys", "proxmox-sendmail/mail-forwarder"]
-sendmail = ["dep:proxmox-sys", "dep:proxmox-sendmail"]
-gotify = ["dep:proxmox-http", "dep:http"]
 pve-context = ["dep:proxmox-sys", "legacy-matchers"]
 pbs-context = ["dep:proxmox-sys", "legacy-matchers"]
-smtp = ["dep:lettre"]
-webhook = ["dep:http", "dep:percent-encoding", "dep:proxmox-base64", "dep:proxmox-http"]
 legacy-matchers = []
diff --git a/proxmox-notify/src/api/gotify.rs b/proxmox-notify/src/api/gotify.rs
index c3149c152..fc56d250b 100644
--- a/proxmox-notify/src/api/gotify.rs
+++ b/proxmox-notify/src/api/gotify.rs
@@ -3,7 +3,7 @@ use proxmox_http_error::HttpError;
 
 use crate::Config;
 use crate::api::http_err;
-use crate::endpoints::gotify::{
+use crate::api_types::{
     DeleteableGotifyProperty, GOTIFY_TYPENAME, GotifyConfig, GotifyConfigUpdater,
     GotifyPrivateConfig, GotifyPrivateConfigUpdater,
 };
diff --git a/proxmox-notify/src/api/matcher.rs b/proxmox-notify/src/api/matcher.rs
index 4600063e2..1994cb65c 100644
--- a/proxmox-notify/src/api/matcher.rs
+++ b/proxmox-notify/src/api/matcher.rs
@@ -3,7 +3,7 @@ use proxmox_http_error::HttpError;
 
 use crate::Config;
 use crate::api::http_err;
-use crate::matcher::{
+use crate::api_types::{
     DeleteableMatcherProperty, MATCHER_TYPENAME, MatcherConfig, MatcherConfigUpdater,
 };
 
@@ -204,13 +204,13 @@ pub fn delete_matcher(config: &mut Config, name: &str) -> Result<(), HttpError>
     Ok(())
 }
 
-#[cfg(all(test, feature = "sendmail"))]
+#[cfg(all(test, feature = "send-impl"))]
 mod tests {
     use proxmox_match_expression::Expression;
 
     use super::*;
 
-    use crate::{context::test::test_context, matcher::expression::NotificationMatcher};
+    use crate::{api_types::expression::NotificationMatcher, context::test::test_context};
 
     fn empty_config() -> Config {
         let context = test_context();
@@ -266,7 +266,7 @@ matcher: matcher2
     #[test]
     #[cfg(feature = "legacy-matchers")]
     fn test_matcher_update() -> Result<(), HttpError> {
-        use crate::matcher::MatchModeOperator;
+        use crate::api_types::MatchModeOperator;
 
         let mut config = config_with_two_matchers();
 
diff --git a/proxmox-notify/src/api/mod.rs b/proxmox-notify/src/api/mod.rs
index dc84fbb10..63185fd55 100644
--- a/proxmox-notify/src/api/mod.rs
+++ b/proxmox-notify/src/api/mod.rs
@@ -9,14 +9,10 @@ use proxmox_schema::api;
 use crate::{Config, Origin};
 
 pub mod common;
-#[cfg(feature = "gotify")]
 pub mod gotify;
 pub mod matcher;
-#[cfg(feature = "sendmail")]
 pub mod sendmail;
-#[cfg(feature = "smtp")]
 pub mod smtp;
-#[cfg(feature = "webhook")]
 pub mod webhook;
 
 // We have our own, local versions of http_err and http_bail, because
@@ -49,16 +45,12 @@ pub use http_err;
 /// Type of the endpoint.
 pub enum EndpointType {
     /// Sendmail endpoint
-    #[cfg(feature = "sendmail")]
     Sendmail,
     /// SMTP endpoint
-    #[cfg(feature = "smtp")]
     Smtp,
     /// Gotify endpoint
-    #[cfg(feature = "gotify")]
     Gotify,
     /// Webhook endpoint
-    #[cfg(feature = "webhook")]
     Webhook,
 }
 
@@ -86,7 +78,6 @@ pub struct Target {
 pub fn get_targets(config: &Config) -> Result<Vec<Target>, HttpError> {
     let mut targets = Vec::new();
 
-    #[cfg(feature = "gotify")]
     for endpoint in gotify::get_endpoints(config)? {
         targets.push(Target {
             name: endpoint.name,
@@ -97,7 +88,6 @@ pub fn get_targets(config: &Config) -> Result<Vec<Target>, HttpError> {
         })
     }
 
-    #[cfg(feature = "sendmail")]
     for endpoint in sendmail::get_endpoints(config)? {
         targets.push(Target {
             name: endpoint.name,
@@ -108,7 +98,6 @@ pub fn get_targets(config: &Config) -> Result<Vec<Target>, HttpError> {
         })
     }
 
-    #[cfg(feature = "smtp")]
     for endpoint in smtp::get_endpoints(config)? {
         targets.push(Target {
             name: endpoint.name,
@@ -119,7 +108,6 @@ pub fn get_targets(config: &Config) -> Result<Vec<Target>, HttpError> {
         })
     }
 
-    #[cfg(feature = "webhook")]
     for endpoint in webhook::get_endpoints(config)? {
         targets.push(Target {
             name: endpoint.name,
@@ -140,26 +128,11 @@ fn verify_digest(config: &Config, digest: Option<ConfigDigest>) -> Result<(), Ht
         .map_err(|err| http_err!(BAD_REQUEST, "{err}"))
 }
 
-fn ensure_endpoint_exists(#[allow(unused)] config: &Config, name: &str) -> Result<(), HttpError> {
-    #[allow(unused_mut)]
-    let mut exists = false;
-
-    #[cfg(feature = "sendmail")]
-    {
-        exists = exists || sendmail::get_endpoint(config, name).is_ok();
-    }
-    #[cfg(feature = "gotify")]
-    {
-        exists = exists || gotify::get_endpoint(config, name).is_ok();
-    }
-    #[cfg(feature = "smtp")]
-    {
-        exists = exists || smtp::get_endpoint(config, name).is_ok();
-    }
-    #[cfg(feature = "webhook")]
-    {
-        exists = exists || webhook::get_endpoint(config, name).is_ok();
-    }
+fn ensure_endpoint_exists(config: &Config, name: &str) -> Result<(), HttpError> {
+    let mut exists = sendmail::get_endpoint(config, name).is_ok();
+    exists = exists || gotify::get_endpoint(config, name).is_ok();
+    exists = exists || smtp::get_endpoint(config, name).is_ok();
+    exists = exists || webhook::get_endpoint(config, name).is_ok();
 
     if !exists {
         http_bail!(NOT_FOUND, "endpoint '{name}' does not exist")
@@ -258,7 +231,6 @@ fn get_referenced_entities(config: &Config, entity: &str) -> HashSet<String> {
     expanded
 }
 
-#[allow(unused)]
 fn set_private_config_entry<T: Serialize>(
     config: &mut Config,
     private_config: T,
@@ -277,7 +249,6 @@ fn set_private_config_entry<T: Serialize>(
         })
 }
 
-#[allow(unused)]
 fn remove_private_config_entry(config: &mut Config, name: &str) -> Result<(), HttpError> {
     config.private_config.sections.remove(name);
     Ok(())
@@ -294,12 +265,10 @@ mod test_helpers {
     }
 }
 
-#[cfg(all(test, feature = "gotify", feature = "sendmail"))]
+#[cfg(test)]
 mod tests {
     use super::*;
-    use crate::endpoints::gotify::{GotifyConfig, GotifyPrivateConfig};
-    use crate::endpoints::sendmail::SendmailConfig;
-    use crate::matcher::MatcherConfig;
+    use crate::api_types::{GotifyConfig, GotifyPrivateConfig, MatcherConfig, SendmailConfig};
 
     fn prepare_config() -> Result<Config, HttpError> {
         let mut config = test_helpers::empty_config();
diff --git a/proxmox-notify/src/api/sendmail.rs b/proxmox-notify/src/api/sendmail.rs
index 2d54608cd..aecc69b38 100644
--- a/proxmox-notify/src/api/sendmail.rs
+++ b/proxmox-notify/src/api/sendmail.rs
@@ -3,7 +3,7 @@ use proxmox_http_error::HttpError;
 
 use crate::Config;
 use crate::api::{http_bail, http_err};
-use crate::endpoints::sendmail::{
+use crate::api_types::{
     DeleteableSendmailProperty, SENDMAIL_TYPENAME, SendmailConfig, SendmailConfigUpdater,
 };
 
diff --git a/proxmox-notify/src/api/smtp.rs b/proxmox-notify/src/api/smtp.rs
index 456cbc31e..f36a51e8c 100644
--- a/proxmox-notify/src/api/smtp.rs
+++ b/proxmox-notify/src/api/smtp.rs
@@ -3,7 +3,7 @@ use proxmox_http_error::HttpError;
 
 use crate::Config;
 use crate::api::{http_bail, http_err};
-use crate::endpoints::smtp::{
+use crate::api_types::{
     DeleteableSmtpProperty, SMTP_TYPENAME, SmtpConfig, SmtpConfigUpdater, SmtpPrivateConfig,
     SmtpPrivateConfigUpdater,
 };
@@ -204,8 +204,7 @@ pub fn delete_endpoint(config: &mut Config, name: &str) -> Result<(), HttpError>
 #[cfg(test)]
 pub mod tests {
     use super::*;
-    use crate::api::test_helpers::*;
-    use crate::endpoints::smtp::SmtpMode;
+    use crate::{api::test_helpers::*, api_types::SmtpMode};
 
     pub fn add_smtp_endpoint_for_test(config: &mut Config, name: &str) -> Result<(), HttpError> {
         add_endpoint(
diff --git a/proxmox-notify/src/api/webhook.rs b/proxmox-notify/src/api/webhook.rs
index e79eeb7e9..8755eb291 100644
--- a/proxmox-notify/src/api/webhook.rs
+++ b/proxmox-notify/src/api/webhook.rs
@@ -7,7 +7,7 @@ use proxmox_http_error::HttpError;
 use proxmox_schema::property_string::PropertyString;
 
 use crate::api::http_err;
-use crate::endpoints::webhook::{
+use crate::api_types::{
     DeleteableWebhookProperty, KeyAndBase64Val, WEBHOOK_TYPENAME, WebhookConfig,
     WebhookConfigUpdater, WebhookPrivateConfig,
 };
@@ -293,7 +293,7 @@ pub fn delete_endpoint(config: &mut Config, name: &str) -> Result<(), HttpError>
 #[cfg(test)]
 mod tests {
     use super::*;
-    use crate::{api::test_helpers::empty_config, endpoints::webhook::HttpMethod};
+    use crate::{api::test_helpers::empty_config, api_types::HttpMethod};
 
     pub fn add_default_webhook_endpoint(config: &mut Config) -> Result<(), HttpError> {
         add_endpoint(
diff --git a/proxmox-notify/src/api_types/gotify.rs b/proxmox-notify/src/api_types/gotify.rs
new file mode 100644
index 000000000..7c6e897e8
--- /dev/null
+++ b/proxmox-notify/src/api_types/gotify.rs
@@ -0,0 +1,68 @@
+use serde::{Deserialize, Serialize};
+
+use proxmox_schema::{Updater, api, api_types::COMMENT_SCHEMA};
+
+use crate::{Origin, schema::ENTITY_NAME_SCHEMA};
+
+pub const GOTIFY_TYPENAME: &str = "gotify";
+
+#[api(
+    properties: {
+        name: {
+            schema: ENTITY_NAME_SCHEMA,
+        },
+        comment: {
+            optional: true,
+            schema: COMMENT_SCHEMA,
+        },
+    }
+)]
+#[derive(Serialize, Deserialize, Updater, Default)]
+#[serde(rename_all = "kebab-case")]
+/// Config for Gotify notification endpoints
+pub struct GotifyConfig {
+    /// Name of the endpoint.
+    #[updater(skip)]
+    pub name: String,
+    /// Gotify Server URL.
+    pub server: String,
+    /// Comment.
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub comment: Option<String>,
+    /// Deprecated.
+    #[serde(skip_serializing)]
+    #[updater(skip)]
+    pub filter: Option<String>,
+    /// Disable this target.
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub disable: Option<bool>,
+    /// Origin of this config entry.
+    #[serde(skip_serializing_if = "Option::is_none")]
+    #[updater(skip)]
+    pub origin: Option<Origin>,
+}
+
+#[api]
+#[derive(Serialize, Deserialize, Clone, Updater)]
+#[serde(rename_all = "kebab-case")]
+/// Private configuration for Gotify notification endpoints.
+/// This config will be saved to a separate configuration file with stricter
+/// permissions (root:root 0600)
+pub struct GotifyPrivateConfig {
+    /// Name of the endpoint
+    #[updater(skip)]
+    pub name: String,
+    /// Authentication token
+    pub token: String,
+}
+
+#[api]
+#[derive(Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case")]
+/// The set of properties that can be deleted from a gotify endpoint configuration.
+pub enum DeleteableGotifyProperty {
+    /// Delete `comment`
+    Comment,
+    /// Delete `disable`
+    Disable,
+}
diff --git a/proxmox-notify/src/matcher/calendar.rs b/proxmox-notify/src/api_types/matcher/calendar.rs
similarity index 96%
rename from proxmox-notify/src/matcher/calendar.rs
rename to proxmox-notify/src/api_types/matcher/calendar.rs
index 72af94102..0a8d31e7a 100644
--- a/proxmox-notify/src/matcher/calendar.rs
+++ b/proxmox-notify/src/api_types/matcher/calendar.rs
@@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
 
 use proxmox_time::DailyDuration;
 
-use crate::{Error, Notification, matcher::expression::NotificationMatcher};
+use crate::{Error, Notification, api_types::expression::NotificationMatcher};
 
 use super::MatchDirective;
 
@@ -127,7 +127,7 @@ pub use inline::*;
 mod test {
     use serde_json::Value;
 
-    use crate::{Notification, Severity, matcher::MatchDirective as _};
+    use crate::{Notification, Severity};
 
     use super::*;
 
diff --git a/proxmox-notify/src/matcher/expression.rs b/proxmox-notify/src/api_types/matcher/expression.rs
similarity index 98%
rename from proxmox-notify/src/matcher/expression.rs
rename to proxmox-notify/src/api_types/matcher/expression.rs
index df9fe439d..4c062caeb 100644
--- a/proxmox-notify/src/matcher/expression.rs
+++ b/proxmox-notify/src/api_types/matcher/expression.rs
@@ -35,7 +35,7 @@ impl MatchExpression for NotificationMatcher {
 impl NotificationMatcher {
     /// Validate any additional constraints that cannot be expressed in the type system.
     pub(crate) fn validate(&self) -> Result<(), Error> {
-        use crate::matcher::MatchDirective;
+        use crate::api_types::matcher::MatchDirective;
 
         match self {
             NotificationMatcher::Field(field_matcher) => field_matcher.validate(),
diff --git a/proxmox-notify/src/matcher/field.rs b/proxmox-notify/src/api_types/matcher/field.rs
similarity index 99%
rename from proxmox-notify/src/matcher/field.rs
rename to proxmox-notify/src/api_types/matcher/field.rs
index f609421ce..b1ea25302 100644
--- a/proxmox-notify/src/matcher/field.rs
+++ b/proxmox-notify/src/api_types/matcher/field.rs
@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
 use proxmox_match_expression::Expression;
 use proxmox_schema::api_types::SAFE_ID_REGEX;
 
-use crate::{Error, Notification, matcher::expression::NotificationMatcher};
+use crate::{Error, Notification, api_types::expression::NotificationMatcher};
 
 use super::MatchDirective;
 
diff --git a/proxmox-notify/src/matcher/mod.rs b/proxmox-notify/src/api_types/matcher/mod.rs
similarity index 99%
rename from proxmox-notify/src/matcher/mod.rs
rename to proxmox-notify/src/api_types/matcher/mod.rs
index 59baeae4e..8f0bc7405 100644
--- a/proxmox-notify/src/matcher/mod.rs
+++ b/proxmox-notify/src/api_types/matcher/mod.rs
@@ -9,7 +9,6 @@ use proxmox_api_macro::api;
 use proxmox_schema::Updater;
 use proxmox_schema::api_types::COMMENT_SCHEMA;
 
-use crate::matcher::expression::NotificationMatcher;
 use crate::schema::ENTITY_NAME_SCHEMA;
 use crate::{Error, Notification, Origin};
 
@@ -18,9 +17,12 @@ pub mod expression;
 pub mod field;
 pub mod severity;
 
+use expression::NotificationMatcher;
+
 pub const MATCHER_TYPENAME: &str = "matcher";
 
 #[api]
+#[cfg(feature = "legacy-matchers")]
 #[derive(Debug, Serialize, Deserialize, Default, Clone, Copy)]
 #[serde(rename_all = "kebab-case")]
 /// The mode in which the results of matches are combined.
diff --git a/proxmox-notify/src/matcher/severity.rs b/proxmox-notify/src/api_types/matcher/severity.rs
similarity index 97%
rename from proxmox-notify/src/matcher/severity.rs
rename to proxmox-notify/src/api_types/matcher/severity.rs
index 6818e5c22..2d68a46bb 100644
--- a/proxmox-notify/src/matcher/severity.rs
+++ b/proxmox-notify/src/api_types/matcher/severity.rs
@@ -1,7 +1,7 @@
 use proxmox_match_expression::Expression;
 use serde::{Deserialize, Serialize};
 
-use crate::{Error, Notification, Severity, matcher::expression::NotificationMatcher};
+use crate::{Error, Notification, Severity, api_types::expression::NotificationMatcher};
 
 use super::MatchDirective;
 
diff --git a/proxmox-notify/src/api_types/mod.rs b/proxmox-notify/src/api_types/mod.rs
new file mode 100644
index 000000000..443dea336
--- /dev/null
+++ b/proxmox-notify/src/api_types/mod.rs
@@ -0,0 +1,21 @@
+//! API types for the notification system.
+//!
+//! Contains the schema-annotated types used for
+//!   - endpoint and matcher configuration
+//!   - the generic target listing
+//!   - send receipts.
+
+mod gotify;
+pub use gotify::*;
+
+mod sendmail;
+pub use sendmail::*;
+
+mod webhook;
+pub use webhook::*;
+
+mod smtp;
+pub use smtp::*;
+
+mod matcher;
+pub use matcher::*;
diff --git a/proxmox-notify/src/api_types/sendmail.rs b/proxmox-notify/src/api_types/sendmail.rs
new file mode 100644
index 000000000..921970265
--- /dev/null
+++ b/proxmox-notify/src/api_types/sendmail.rs
@@ -0,0 +1,96 @@
+use serde::{Deserialize, Serialize};
+
+use proxmox_schema::{Updater, api, api_types::COMMENT_SCHEMA};
+
+use crate::{
+    Origin,
+    schema::{EMAIL_SCHEMA, ENTITY_NAME_SCHEMA, USER_SCHEMA},
+};
+
+pub const SENDMAIL_TYPENAME: &str = "sendmail";
+
+#[api(
+    properties: {
+        name: {
+            schema: ENTITY_NAME_SCHEMA,
+        },
+        mailto: {
+            type: Array,
+            items: {
+                schema: EMAIL_SCHEMA,
+            },
+            optional: true,
+        },
+        "mailto-user": {
+            type: Array,
+            items: {
+                schema: USER_SCHEMA,
+            },
+            optional: true,
+        },
+        comment: {
+            optional: true,
+            schema: COMMENT_SCHEMA,
+        },
+    },
+)]
+#[derive(Debug, Serialize, Deserialize, Updater, Default)]
+#[serde(rename_all = "kebab-case")]
+/// Config for Sendmail notification endpoints
+pub struct SendmailConfig {
+    /// Name of the endpoint
+    #[updater(skip)]
+    pub name: String,
+    /// Mail address to send a mail to.
+    #[serde(default, skip_serializing_if = "Vec::is_empty")]
+    #[updater(serde(skip_serializing_if = "Option::is_none"))]
+    pub mailto: Vec<String>,
+    /// Users to send a mail to. The email address of the user
+    /// will be looked up in users.cfg.
+    #[serde(default, skip_serializing_if = "Vec::is_empty")]
+    #[updater(serde(skip_serializing_if = "Option::is_none"))]
+    pub mailto_user: Vec<String>,
+    /// `From` address for sent E-Mails.
+    /// If the parameter is not set, the plugin will fall back to the
+    /// email-from setting from node.cfg (PBS).
+    /// If that is also not set, the plugin will default to root@$hostname,
+    /// where $hostname is the hostname of the node.
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub from_address: Option<String>,
+    /// Author of the mail. Defaults to 'Proxmox Backup Server ($hostname)'
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub author: Option<String>,
+    /// Comment.
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub comment: Option<String>,
+    /// Deprecated.
+    #[serde(skip_serializing)]
+    #[updater(skip)]
+    pub filter: Option<String>,
+    /// Disable this target.
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub disable: Option<bool>,
+    /// Origin of this config entry.
+    #[serde(skip_serializing_if = "Option::is_none")]
+    #[updater(skip)]
+    pub origin: Option<Origin>,
+}
+
+#[api]
+#[derive(Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case")]
+/// The set of properties that can be deleted from a sendmail endpoint configuration.
+pub enum DeleteableSendmailProperty {
+    /// Delete `author`
+    Author,
+    /// Delete `comment`
+    Comment,
+    /// Delete `disable`
+    Disable,
+    /// Delete `from-address`
+    FromAddress,
+    /// Delete `mailto`
+    Mailto,
+    /// Delete `mailto-user`
+    MailtoUser,
+}
diff --git a/proxmox-notify/src/api_types/smtp.rs b/proxmox-notify/src/api_types/smtp.rs
new file mode 100644
index 000000000..9ab26700f
--- /dev/null
+++ b/proxmox-notify/src/api_types/smtp.rs
@@ -0,0 +1,136 @@
+use serde::{Deserialize, Serialize};
+
+use proxmox_schema::{Updater, api, api_types::COMMENT_SCHEMA};
+
+use crate::Origin;
+use crate::schema::{EMAIL_SCHEMA, ENTITY_NAME_SCHEMA, USER_SCHEMA};
+
+pub const SMTP_TYPENAME: &str = "smtp";
+
+#[api]
+#[derive(Debug, Serialize, Deserialize, Default, Clone, Copy)]
+#[serde(rename_all = "kebab-case")]
+/// Connection security
+pub enum SmtpMode {
+    /// No encryption (insecure), plain SMTP
+    Insecure,
+    /// Upgrade to TLS after connecting
+    #[serde(rename = "starttls")]
+    StartTls,
+    /// Use TLS-secured connection
+    #[default]
+    Tls,
+}
+
+#[api(
+    properties: {
+        name: {
+            schema: ENTITY_NAME_SCHEMA,
+        },
+        mailto: {
+            type: Array,
+            items: {
+                schema: EMAIL_SCHEMA,
+            },
+            optional: true,
+        },
+        "mailto-user": {
+            type: Array,
+            items: {
+                schema: USER_SCHEMA,
+            },
+            optional: true,
+        },
+        comment: {
+            optional: true,
+            schema: COMMENT_SCHEMA,
+        },
+    },
+)]
+#[derive(Debug, Serialize, Deserialize, Updater, Default)]
+#[serde(rename_all = "kebab-case")]
+/// Config for SMTP notification endpoints
+pub struct SmtpConfig {
+    /// Name of the endpoint.
+    #[updater(skip)]
+    pub name: String,
+    /// Host name or IP of the SMTP relay.
+    pub server: String,
+    /// The port to connect to.
+    /// If not set, the used port defaults to 25 (insecure), 465 (tls)
+    /// or 587 (starttls), depending on the value of mode
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub port: Option<u16>,
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub mode: Option<SmtpMode>,
+    /// Username to use during authentication.
+    /// If no username is set, no authentication will be performed.
+    /// The PLAIN and LOGIN authentication methods are supported
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub username: Option<String>,
+    /// Mail address to send a mail to.
+    #[serde(default, skip_serializing_if = "Vec::is_empty")]
+    #[updater(serde(skip_serializing_if = "Option::is_none"))]
+    pub mailto: Vec<String>,
+    /// Users to send a mail to. The email address of the user
+    /// will be looked up in users.cfg.
+    #[serde(default, skip_serializing_if = "Vec::is_empty")]
+    #[updater(serde(skip_serializing_if = "Option::is_none"))]
+    pub mailto_user: Vec<String>,
+    /// `From` address for the mail.
+    /// SMTP relays might require that this address is owned by the user
+    /// in order to avoid spoofing. The `From` header in the email will be
+    /// set to `$author <$from-address>`.
+    pub from_address: String,
+    /// Author of the mail. Defaults to 'Proxmox Backup Server ($hostname)'
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub author: Option<String>,
+    /// Comment.
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub comment: Option<String>,
+    /// Disable this target.
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub disable: Option<bool>,
+    /// Origin of this config entry.
+    #[serde(skip_serializing_if = "Option::is_none")]
+    #[updater(skip)]
+    pub origin: Option<Origin>,
+}
+
+#[api]
+#[derive(Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case")]
+/// The set of properties that can be deleted from a smtp endpoint configuration.
+pub enum DeleteableSmtpProperty {
+    /// Delete `author`
+    Author,
+    /// Delete `comment`
+    Comment,
+    /// Delete `disable`
+    Disable,
+    /// Delete `mailto`
+    Mailto,
+    /// Delete `mailto-user`
+    MailtoUser,
+    /// Delete `password`
+    Password,
+    /// Delete `port`
+    Port,
+    /// Delete `username`
+    Username,
+}
+
+#[api]
+#[derive(Serialize, Deserialize, Clone, Updater, Debug)]
+#[serde(rename_all = "kebab-case")]
+/// Private configuration for SMTP notification endpoints.
+/// This config will be saved to a separate configuration file with stricter
+/// permissions (root:root 0600)
+pub struct SmtpPrivateConfig {
+    /// Name of the endpoint
+    #[updater(skip)]
+    pub name: String,
+    /// The password to use during authentication.
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub password: Option<String>,
+}
diff --git a/proxmox-notify/src/api_types/webhook.rs b/proxmox-notify/src/api_types/webhook.rs
new file mode 100644
index 000000000..7d51f0470
--- /dev/null
+++ b/proxmox-notify/src/api_types/webhook.rs
@@ -0,0 +1,208 @@
+use proxmox_schema::{
+    ApiStringFormat, ApiType, PropertyString, Schema, StringSchema, Updater, api,
+    api_types::{COMMENT_SCHEMA, HTTP_URL_SCHEMA},
+};
+use serde::{Deserialize, Serialize};
+
+use crate::{Error, Origin, schema::ENTITY_NAME_SCHEMA};
+
+/// This will be used as a section type in the public/private configuration file.
+pub const WEBHOOK_TYPENAME: &str = "webhook";
+
+pub const KEY_AND_BASE64_VALUE_SCHEMA: Schema =
+    StringSchema::new("String schema for pairs of keys and base64 encoded values")
+        .format(&ApiStringFormat::PropertyString(
+            &KeyAndBase64Val::API_SCHEMA,
+        ))
+        .schema();
+
+#[api]
+#[derive(Serialize, Deserialize, Clone, Copy, Default, PartialEq)]
+#[serde(rename_all = "kebab-case")]
+/// HTTP Method to use.
+pub enum HttpMethod {
+    /// HTTP POST
+    #[default]
+    Post,
+    /// HTTP PUT
+    Put,
+    /// HTTP GET
+    Get,
+}
+
+// We only ever need a &str, so we rather implement this
+// instead of Display.
+impl From<HttpMethod> for &str {
+    fn from(value: HttpMethod) -> Self {
+        match value {
+            HttpMethod::Post => "POST",
+            HttpMethod::Put => "PUT",
+            HttpMethod::Get => "GET",
+        }
+    }
+}
+
+#[api(
+    properties: {
+        name: {
+            schema: ENTITY_NAME_SCHEMA,
+        },
+        url: {
+            schema: HTTP_URL_SCHEMA,
+        },
+        comment: {
+            optional: true,
+            schema: COMMENT_SCHEMA,
+        },
+        header: {
+            type: Array,
+            items: {
+                schema: KEY_AND_BASE64_VALUE_SCHEMA,
+            },
+            optional: true,
+        },
+        secret: {
+            type: Array,
+            items: {
+                schema: KEY_AND_BASE64_VALUE_SCHEMA,
+            },
+            optional: true,
+        },
+    }
+)]
+#[derive(Serialize, Deserialize, Updater, Default, Clone)]
+#[serde(rename_all = "kebab-case")]
+/// Config for Webhook notification endpoints
+pub struct WebhookConfig {
+    /// Name of the endpoint.
+    #[updater(skip)]
+    pub name: String,
+
+    pub method: HttpMethod,
+
+    /// Webhook URL. Supports templating.
+    pub url: String,
+    /// Array of HTTP headers. Each entry is a property string with a name and a value.
+    /// The value property contains the header in base64 encoding. Supports templating.
+    #[serde(default, skip_serializing_if = "Vec::is_empty")]
+    #[updater(serde(skip_serializing_if = "Option::is_none"))]
+    pub header: Vec<PropertyString<KeyAndBase64Val>>,
+    /// The HTTP body to send. Supports templating.
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub body: Option<String>,
+
+    /// Comment.
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub comment: Option<String>,
+    /// Disable this target.
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub disable: Option<bool>,
+    /// Origin of this config entry.
+    #[serde(skip_serializing_if = "Option::is_none")]
+    #[updater(skip)]
+    pub origin: Option<Origin>,
+    /// Array of secrets. Each entry is a property string with a name and an optional value.
+    /// The value property contains the secret in base64 encoding.
+    /// For any API endpoints returning the endpoint config,
+    /// only the secret name but not the value will be returned.
+    /// When updating the config, also send all secrets that you want
+    /// to keep, setting only the name but not the value. Can be accessed from templates.
+    #[serde(default, skip_serializing_if = "Vec::is_empty")]
+    #[updater(serde(skip_serializing_if = "Option::is_none"))]
+    pub secret: Vec<PropertyString<KeyAndBase64Val>>,
+}
+
+#[api(
+    properties: {
+        name: {
+            schema: ENTITY_NAME_SCHEMA,
+        },
+        secret: {
+            type: Array,
+            items: {
+                schema: KEY_AND_BASE64_VALUE_SCHEMA,
+            },
+            optional: true,
+        },
+    }
+)]
+#[derive(Serialize, Deserialize, Clone, Updater, Default)]
+#[serde(rename_all = "kebab-case")]
+/// Private configuration for Webhook notification endpoints.
+/// This config will be saved to a separate configuration file with stricter
+/// permissions (root:root 0600).
+pub struct WebhookPrivateConfig {
+    /// Name of the endpoint
+    #[updater(skip)]
+    pub name: String,
+
+    #[serde(default, skip_serializing_if = "Vec::is_empty")]
+    #[updater(serde(skip_serializing_if = "Option::is_none"))]
+    /// Array of secrets. Each entry is a property string with a name,
+    /// and a value property. The value property contains the secret
+    /// in base64 encoding. Can be accessed from templates.
+    pub secret: Vec<PropertyString<KeyAndBase64Val>>,
+}
+
+#[api]
+#[derive(Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case")]
+/// Webhook configuration properties that can be deleted.
+pub enum DeleteableWebhookProperty {
+    /// Delete `comment`.
+    Comment,
+    /// Delete `disable`.
+    Disable,
+    /// Delete `header`.
+    Header,
+    /// Delete `body`.
+    Body,
+    /// Delete `secret`.
+    Secret,
+}
+
+#[api]
+#[derive(Serialize, Deserialize, Debug, Default, Clone)]
+/// Datatype used to represent key-value pairs, the value
+/// being encoded in base64.
+pub struct KeyAndBase64Val {
+    /// Name
+    pub name: String,
+    /// Base64 encoded value
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub value: Option<String>,
+}
+
+impl KeyAndBase64Val {
+    #[cfg(test)]
+    pub fn new_with_plain_value(name: &str, value: &str) -> Self {
+        let value = proxmox_base64::encode(value);
+
+        Self {
+            name: name.into(),
+            value: Some(value),
+        }
+    }
+
+    /// Decode the contained value, returning the plaintext value
+    ///
+    /// Returns an error if the contained value is not valid base64-encoded
+    /// text.
+    pub fn decode_value(&self) -> Result<String, Error> {
+        let value = self.value.as_deref().unwrap_or_default();
+        let bytes = proxmox_base64::decode(value).map_err(|_| {
+            Error::invalid_config(format!(
+                "could not decode base64 value with key '{}'",
+                self.name
+            ))
+        })?;
+        let value = String::from_utf8(bytes).map_err(|_| {
+            Error::invalid_config(format!(
+                "could not decode UTF8 string from base64, key '{}'",
+                self.name
+            ))
+        })?;
+
+        Ok(value)
+    }
+}
diff --git a/proxmox-notify/src/config.rs b/proxmox-notify/src/config.rs
index 176bc46b7..bf1469160 100644
--- a/proxmox-notify/src/config.rs
+++ b/proxmox-notify/src/config.rs
@@ -5,7 +5,11 @@ use proxmox_schema::{ApiType, ObjectSchema};
 use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin};
 
 use crate::Error;
-use crate::matcher::{MATCHER_TYPENAME, MatcherConfig};
+use crate::api_types::{
+    GOTIFY_TYPENAME, GotifyConfig, GotifyPrivateConfig, MATCHER_TYPENAME, MatcherConfig,
+    SENDMAIL_TYPENAME, SMTP_TYPENAME, SendmailConfig, SmtpConfig, SmtpPrivateConfig,
+    WEBHOOK_TYPENAME, WebhookConfig, WebhookPrivateConfig,
+};
 use crate::schema::BACKEND_NAME_SCHEMA;
 
 /// Section config schema for the public config file.
@@ -23,10 +27,7 @@ pub fn private_config_parser() -> &'static SectionConfig {
 fn config_init() -> SectionConfig {
     let mut config = SectionConfig::new(&BACKEND_NAME_SCHEMA);
 
-    #[cfg(feature = "sendmail")]
     {
-        use crate::endpoints::sendmail::{SENDMAIL_TYPENAME, SendmailConfig};
-
         const SENDMAIL_SCHEMA: &ObjectSchema = SendmailConfig::API_SCHEMA.unwrap_object_schema();
         config.register_plugin(SectionConfigPlugin::new(
             SENDMAIL_TYPENAME.to_string(),
@@ -34,10 +35,7 @@ fn config_init() -> SectionConfig {
             SENDMAIL_SCHEMA,
         ));
     }
-    #[cfg(feature = "smtp")]
     {
-        use crate::endpoints::smtp::{SMTP_TYPENAME, SmtpConfig};
-
         const SMTP_SCHEMA: &ObjectSchema = SmtpConfig::API_SCHEMA.unwrap_object_schema();
         config.register_plugin(SectionConfigPlugin::new(
             SMTP_TYPENAME.to_string(),
@@ -45,10 +43,7 @@ fn config_init() -> SectionConfig {
             SMTP_SCHEMA,
         ));
     }
-    #[cfg(feature = "gotify")]
     {
-        use crate::endpoints::gotify::{GOTIFY_TYPENAME, GotifyConfig};
-
         const GOTIFY_SCHEMA: &ObjectSchema = GotifyConfig::API_SCHEMA.unwrap_object_schema();
         config.register_plugin(SectionConfigPlugin::new(
             GOTIFY_TYPENAME.to_string(),
@@ -56,10 +51,7 @@ fn config_init() -> SectionConfig {
             GOTIFY_SCHEMA,
         ));
     }
-    #[cfg(feature = "webhook")]
     {
-        use crate::endpoints::webhook::{WEBHOOK_TYPENAME, WebhookConfig};
-
         const WEBHOOK_SCHEMA: &ObjectSchema = WebhookConfig::API_SCHEMA.unwrap_object_schema();
         config.register_plugin(SectionConfigPlugin::new(
             WEBHOOK_TYPENAME.to_string(),
@@ -79,45 +71,29 @@ fn config_init() -> SectionConfig {
 }
 
 fn private_config_init() -> SectionConfig {
-    #[allow(unused_mut)]
     let mut config = SectionConfig::new(&BACKEND_NAME_SCHEMA);
 
-    #[cfg(feature = "gotify")]
-    {
-        use crate::endpoints::gotify::{GOTIFY_TYPENAME, GotifyPrivateConfig};
+    const GOTIFY_SCHEMA: &ObjectSchema = GotifyPrivateConfig::API_SCHEMA.unwrap_object_schema();
+    config.register_plugin(SectionConfigPlugin::new(
+        GOTIFY_TYPENAME.to_string(),
+        Some(String::from("name")),
+        GOTIFY_SCHEMA,
+    ));
 
-        const GOTIFY_SCHEMA: &ObjectSchema = GotifyPrivateConfig::API_SCHEMA.unwrap_object_schema();
-        config.register_plugin(SectionConfigPlugin::new(
-            GOTIFY_TYPENAME.to_string(),
-            Some(String::from("name")),
-            GOTIFY_SCHEMA,
-        ));
-    }
+    const SMTP_SCHEMA: &ObjectSchema = SmtpPrivateConfig::API_SCHEMA.unwrap_object_schema();
+    config.register_plugin(SectionConfigPlugin::new(
+        SMTP_TYPENAME.to_string(),
+        Some(String::from("name")),
+        SMTP_SCHEMA,
+    ));
 
-    #[cfg(feature = "smtp")]
-    {
-        use crate::endpoints::smtp::{SMTP_TYPENAME, SmtpPrivateConfig};
+    const WEBHOOK_SCHEMA: &ObjectSchema = WebhookPrivateConfig::API_SCHEMA.unwrap_object_schema();
+    config.register_plugin(SectionConfigPlugin::new(
+        WEBHOOK_TYPENAME.to_string(),
+        Some(String::from("name")),
+        WEBHOOK_SCHEMA,
+    ));
 
-        const SMTP_SCHEMA: &ObjectSchema = SmtpPrivateConfig::API_SCHEMA.unwrap_object_schema();
-        config.register_plugin(SectionConfigPlugin::new(
-            SMTP_TYPENAME.to_string(),
-            Some(String::from("name")),
-            SMTP_SCHEMA,
-        ));
-    }
-
-    #[cfg(feature = "webhook")]
-    {
-        use crate::endpoints::webhook::{WEBHOOK_TYPENAME, WebhookPrivateConfig};
-
-        const WEBHOOK_SCHEMA: &ObjectSchema =
-            WebhookPrivateConfig::API_SCHEMA.unwrap_object_schema();
-        config.register_plugin(SectionConfigPlugin::new(
-            WEBHOOK_TYPENAME.to_string(),
-            Some(String::from("name")),
-            WEBHOOK_SCHEMA,
-        ));
-    }
     config
 }
 
diff --git a/proxmox-notify/src/context/pbs.rs b/proxmox-notify/src/context/pbs.rs
index a979f25d6..f16e9ebdd 100644
--- a/proxmox-notify/src/context/pbs.rs
+++ b/proxmox-notify/src/context/pbs.rs
@@ -6,9 +6,8 @@ use tracing::error;
 use proxmox_schema::{ObjectSchema, Schema, StringSchema};
 use proxmox_section_config::{SectionConfig, SectionConfigPlugin};
 
-use crate::context::{ContextImpl, common};
+use crate::context::{ContextImpl, TemplateSource, common};
 use crate::error::BoxedError;
-use crate::renderer::TemplateSource;
 
 const PBS_USER_CFG_FILENAME: &str = "/etc/proxmox-backup/user.cfg";
 const PBS_NODE_CFG_FILENAME: &str = "/etc/proxmox-backup/node.cfg";
diff --git a/proxmox-notify/src/context/pve.rs b/proxmox-notify/src/context/pve.rs
index b2d08acc2..bcfa0edff 100644
--- a/proxmox-notify/src/context/pve.rs
+++ b/proxmox-notify/src/context/pve.rs
@@ -1,8 +1,7 @@
 use std::path::Path;
 
-use crate::context::{ContextImpl, common};
+use crate::context::{ContextImpl, TemplateSource, common};
 use crate::error::BoxedError;
-use crate::renderer::TemplateSource;
 
 fn lookup_mail_address(content: &str, user: &str) -> Option<String> {
     common::normalize_for_return(content.lines().find_map(|line| {
diff --git a/proxmox-notify/src/endpoints/common/mod.rs b/proxmox-notify/src/endpoints/common/mod.rs
index 60e07619b..c2d0a8b7f 100644
--- a/proxmox-notify/src/endpoints/common/mod.rs
+++ b/proxmox-notify/src/endpoints/common/mod.rs
@@ -1,2 +1 @@
-#[cfg(any(feature = "sendmail", feature = "smtp"))]
 pub(crate) mod mail;
diff --git a/proxmox-notify/src/endpoints/gotify.rs b/proxmox-notify/src/endpoints/gotify.rs
index 7fe74f862..5341f822f 100644
--- a/proxmox-notify/src/endpoints/gotify.rs
+++ b/proxmox-notify/src/endpoints/gotify.rs
@@ -1,17 +1,14 @@
 use std::collections::HashMap;
 use std::time::Duration;
 
-use serde::{Deserialize, Serialize};
 use serde_json::json;
 
 use proxmox_http::client::sync::Client;
 use proxmox_http::{HttpClient, HttpOptions, ProxyConfig};
-use proxmox_schema::api_types::COMMENT_SCHEMA;
-use proxmox_schema::{Updater, api};
 
+use crate::api_types::{GotifyConfig, GotifyPrivateConfig};
 use crate::renderer::TemplateType;
-use crate::schema::ENTITY_NAME_SCHEMA;
-use crate::{Content, Context, Error, Notification, Origin, Severity, renderer};
+use crate::{Content, Context, Error, Notification, Severity, renderer};
 
 use super::Endpoint;
 
@@ -27,75 +24,12 @@ fn severity_to_priority(level: Severity) -> u32 {
     }
 }
 
-pub(crate) const GOTIFY_TYPENAME: &str = "gotify";
-
-#[api(
-    properties: {
-        name: {
-            schema: ENTITY_NAME_SCHEMA,
-        },
-        comment: {
-            optional: true,
-            schema: COMMENT_SCHEMA,
-        },
-    }
-)]
-#[derive(Serialize, Deserialize, Updater, Default)]
-#[serde(rename_all = "kebab-case")]
-/// Config for  Gotify notification endpoints
-pub struct GotifyConfig {
-    /// Name of the endpoint.
-    #[updater(skip)]
-    pub name: String,
-    /// Gotify Server URL.
-    pub server: String,
-    /// Comment.
-    #[serde(skip_serializing_if = "Option::is_none")]
-    pub comment: Option<String>,
-    /// Deprecated.
-    #[serde(skip_serializing)]
-    #[updater(skip)]
-    pub filter: Option<String>,
-    /// Disable this target.
-    #[serde(skip_serializing_if = "Option::is_none")]
-    pub disable: Option<bool>,
-    /// Origin of this config entry.
-    #[serde(skip_serializing_if = "Option::is_none")]
-    #[updater(skip)]
-    pub origin: Option<Origin>,
-}
-
-#[api()]
-#[derive(Serialize, Deserialize, Clone, Updater)]
-#[serde(rename_all = "kebab-case")]
-/// Private configuration for Gotify notification endpoints.
-/// This config will be saved to a separate configuration file with stricter
-/// permissions (root:root 0600)
-pub struct GotifyPrivateConfig {
-    /// Name of the endpoint
-    #[updater(skip)]
-    pub name: String,
-    /// Authentication token
-    pub token: String,
-}
-
 /// A Gotify notification endpoint.
-pub struct GotifyEndpoint {
+pub(crate) struct GotifyEndpoint {
     pub config: GotifyConfig,
     pub private_config: GotifyPrivateConfig,
 }
 
-#[api]
-#[derive(Serialize, Deserialize)]
-#[serde(rename_all = "kebab-case")]
-/// The set of properties that can be deleted from a gotify endpoint configuration.
-pub enum DeleteableGotifyProperty {
-    /// Delete `comment`
-    Comment,
-    /// Delete `disable`
-    Disable,
-}
-
 impl Endpoint for GotifyEndpoint {
     fn send(&self, context: &Context, notification: &Notification) -> Result<(), Error> {
         let (title, message) = match &notification.content {
diff --git a/proxmox-notify/src/endpoints/mod.rs b/proxmox-notify/src/endpoints/mod.rs
index ea77d4243..0bf7f9f60 100644
--- a/proxmox-notify/src/endpoints/mod.rs
+++ b/proxmox-notify/src/endpoints/mod.rs
@@ -2,13 +2,9 @@ use crate::Context;
 use crate::Error;
 use crate::Notification;
 
-#[cfg(feature = "gotify")]
 pub mod gotify;
-#[cfg(feature = "sendmail")]
 pub mod sendmail;
-#[cfg(feature = "smtp")]
 pub mod smtp;
-#[cfg(feature = "webhook")]
 pub mod webhook;
 
 mod common;
diff --git a/proxmox-notify/src/endpoints/sendmail.rs b/proxmox-notify/src/endpoints/sendmail.rs
index 0d60308d2..6ddee5161 100644
--- a/proxmox-notify/src/endpoints/sendmail.rs
+++ b/proxmox-notify/src/endpoints/sendmail.rs
@@ -1,104 +1,12 @@
 use proxmox_sendmail::Mail;
-use serde::{Deserialize, Serialize};
-
-use proxmox_schema::api_types::COMMENT_SCHEMA;
-use proxmox_schema::{Updater, api};
 
+use crate::api_types::SendmailConfig;
 use crate::endpoints::common::mail;
 use crate::renderer::TemplateType;
-use crate::schema::{EMAIL_SCHEMA, ENTITY_NAME_SCHEMA, USER_SCHEMA};
-use crate::{Content, Context, Error, Notification, Origin, renderer};
+use crate::{Content, Context, Error, Notification, renderer};
 
 use super::Endpoint;
 
-pub(crate) const SENDMAIL_TYPENAME: &str = "sendmail";
-
-#[api(
-    properties: {
-        name: {
-            schema: ENTITY_NAME_SCHEMA,
-        },
-        mailto: {
-            type: Array,
-            items: {
-                schema: EMAIL_SCHEMA,
-            },
-            optional: true,
-        },
-        "mailto-user": {
-            type: Array,
-            items: {
-                schema: USER_SCHEMA,
-            },
-            optional: true,
-        },
-        comment: {
-            optional: true,
-            schema: COMMENT_SCHEMA,
-        },
-    },
-)]
-#[derive(Debug, Serialize, Deserialize, Updater, Default)]
-#[serde(rename_all = "kebab-case")]
-/// Config for Sendmail notification endpoints
-pub struct SendmailConfig {
-    /// Name of the endpoint
-    #[updater(skip)]
-    pub name: String,
-    /// Mail address to send a mail to.
-    #[serde(default, skip_serializing_if = "Vec::is_empty")]
-    #[updater(serde(skip_serializing_if = "Option::is_none"))]
-    pub mailto: Vec<String>,
-    /// Users to send a mail to. The email address of the user
-    /// will be looked up in users.cfg.
-    #[serde(default, skip_serializing_if = "Vec::is_empty")]
-    #[updater(serde(skip_serializing_if = "Option::is_none"))]
-    pub mailto_user: Vec<String>,
-    /// `From` address for sent E-Mails.
-    /// If the parameter is not set, the plugin will fall back to the
-    /// email-from setting from node.cfg (PBS).
-    /// If that is also not set, the plugin will default to root@$hostname,
-    /// where $hostname is the hostname of the node.
-    #[serde(skip_serializing_if = "Option::is_none")]
-    pub from_address: Option<String>,
-    /// Author of the mail. Defaults to 'Proxmox Backup Server ($hostname)'
-    #[serde(skip_serializing_if = "Option::is_none")]
-    pub author: Option<String>,
-    /// Comment.
-    #[serde(skip_serializing_if = "Option::is_none")]
-    pub comment: Option<String>,
-    /// Deprecated.
-    #[serde(skip_serializing)]
-    #[updater(skip)]
-    pub filter: Option<String>,
-    /// Disable this target.
-    #[serde(skip_serializing_if = "Option::is_none")]
-    pub disable: Option<bool>,
-    /// Origin of this config entry.
-    #[serde(skip_serializing_if = "Option::is_none")]
-    #[updater(skip)]
-    pub origin: Option<Origin>,
-}
-
-#[api]
-#[derive(Serialize, Deserialize)]
-#[serde(rename_all = "kebab-case")]
-/// The set of properties that can be deleted from a sendmail endpoint configuration.
-pub enum DeleteableSendmailProperty {
-    /// Delete `author`
-    Author,
-    /// Delete `comment`
-    Comment,
-    /// Delete `disable`
-    Disable,
-    /// Delete `from-address`
-    FromAddress,
-    /// Delete `mailto`
-    Mailto,
-    /// Delete `mailto-user`
-    MailtoUser,
-}
-
 /// A sendmail notification endpoint.
 pub struct SendmailEndpoint {
     pub config: SendmailConfig,
diff --git a/proxmox-notify/src/endpoints/smtp.rs b/proxmox-notify/src/endpoints/smtp.rs
index b64bb5596..ccade1c8e 100644
--- a/proxmox-notify/src/endpoints/smtp.rs
+++ b/proxmox-notify/src/endpoints/smtp.rs
@@ -5,153 +5,19 @@ use lettre::message::header::{HeaderName, HeaderValue};
 use lettre::message::{Mailbox, MultiPart, SinglePart};
 use lettre::transport::smtp::client::{Tls, TlsParameters};
 use lettre::{Message, SmtpTransport, Transport, message::header::ContentType};
-use serde::{Deserialize, Serialize};
-
-use proxmox_schema::api_types::COMMENT_SCHEMA;
-use proxmox_schema::{Updater, api};
 
+use crate::api_types::{SmtpConfig, SmtpMode, SmtpPrivateConfig};
 use crate::endpoints::common::mail;
 use crate::renderer::TemplateType;
-use crate::schema::{EMAIL_SCHEMA, ENTITY_NAME_SCHEMA, USER_SCHEMA};
-use crate::{Content, Context, Error, Notification, Origin, renderer};
+use crate::{Content, Context, Error, Notification, renderer};
 
 use super::Endpoint;
 
-pub(crate) const SMTP_TYPENAME: &str = "smtp";
-
 const SMTP_PORT: u16 = 25;
 const SMTP_SUBMISSION_STARTTLS_PORT: u16 = 587;
 const SMTP_SUBMISSION_TLS_PORT: u16 = 465;
 const SMTP_TIMEOUT: u16 = 5;
 
-#[api]
-#[derive(Debug, Serialize, Deserialize, Default, Clone, Copy)]
-#[serde(rename_all = "kebab-case")]
-/// Connection security
-pub enum SmtpMode {
-    /// No encryption (insecure), plain SMTP
-    Insecure,
-    /// Upgrade to TLS after connecting
-    #[serde(rename = "starttls")]
-    StartTls,
-    /// Use TLS-secured connection
-    #[default]
-    Tls,
-}
-
-#[api(
-    properties: {
-        name: {
-            schema: ENTITY_NAME_SCHEMA,
-        },
-        mailto: {
-            type: Array,
-            items: {
-                schema: EMAIL_SCHEMA,
-            },
-            optional: true,
-        },
-        "mailto-user": {
-            type: Array,
-            items: {
-                schema: USER_SCHEMA,
-            },
-            optional: true,
-        },
-        comment: {
-            optional: true,
-            schema: COMMENT_SCHEMA,
-        },
-    },
-)]
-#[derive(Debug, Serialize, Deserialize, Updater, Default)]
-#[serde(rename_all = "kebab-case")]
-/// Config for Sendmail notification endpoints
-pub struct SmtpConfig {
-    /// Name of the endpoint.
-    #[updater(skip)]
-    pub name: String,
-    /// Host name or IP of the SMTP relay.
-    pub server: String,
-    /// The port to connect to.
-    /// If not set, the used port defaults to 25 (insecure), 465 (tls)
-    /// or 587 (starttls), depending on the value of mode
-    #[serde(skip_serializing_if = "Option::is_none")]
-    pub port: Option<u16>,
-    #[serde(skip_serializing_if = "Option::is_none")]
-    pub mode: Option<SmtpMode>,
-    /// Username to use during authentication.
-    /// If no username is set, no authentication will be performed.
-    /// The PLAIN and LOGIN authentication methods are supported
-    #[serde(skip_serializing_if = "Option::is_none")]
-    pub username: Option<String>,
-    /// Mail address to send a mail to.
-    #[serde(default, skip_serializing_if = "Vec::is_empty")]
-    #[updater(serde(skip_serializing_if = "Option::is_none"))]
-    pub mailto: Vec<String>,
-    /// Users to send a mail to. The email address of the user
-    /// will be looked up in users.cfg.
-    #[serde(default, skip_serializing_if = "Vec::is_empty")]
-    #[updater(serde(skip_serializing_if = "Option::is_none"))]
-    pub mailto_user: Vec<String>,
-    /// `From` address for the mail.
-    /// SMTP relays might require that this address is owned by the user
-    /// in order to avoid spoofing. The `From` header in the email will be
-    /// set to `$author <$from-address>`.
-    pub from_address: String,
-    /// Author of the mail. Defaults to 'Proxmox Backup Server ($hostname)'
-    #[serde(skip_serializing_if = "Option::is_none")]
-    pub author: Option<String>,
-    /// Comment.
-    #[serde(skip_serializing_if = "Option::is_none")]
-    pub comment: Option<String>,
-    /// Disable this target.
-    #[serde(skip_serializing_if = "Option::is_none")]
-    pub disable: Option<bool>,
-    /// Origin of this config entry.
-    #[serde(skip_serializing_if = "Option::is_none")]
-    #[updater(skip)]
-    pub origin: Option<Origin>,
-}
-
-#[api]
-#[derive(Serialize, Deserialize)]
-#[serde(rename_all = "kebab-case")]
-/// The set of properties that can be deleted from a smtp endpoint configuration.
-pub enum DeleteableSmtpProperty {
-    /// Delete `author`
-    Author,
-    /// Delete `comment`
-    Comment,
-    /// Delete `disable`
-    Disable,
-    /// Delete `mailto`
-    Mailto,
-    /// Delete `mailto-user`
-    MailtoUser,
-    /// Delete `password`
-    Password,
-    /// Delete `port`
-    Port,
-    /// Delete `username`
-    Username,
-}
-
-#[api]
-#[derive(Serialize, Deserialize, Clone, Updater, Debug)]
-#[serde(rename_all = "kebab-case")]
-/// Private configuration for SMTP notification endpoints.
-/// This config will be saved to a separate configuration file with stricter
-/// permissions (root:root 0600)
-pub struct SmtpPrivateConfig {
-    /// Name of the endpoint
-    #[updater(skip)]
-    pub name: String,
-    /// The password to use during authentication.
-    #[serde(skip_serializing_if = "Option::is_none")]
-    pub password: Option<String>,
-}
-
 /// A sendmail notification endpoint.
 pub struct SmtpEndpoint {
     pub config: SmtpConfig,
diff --git a/proxmox-notify/src/endpoints/webhook.rs b/proxmox-notify/src/endpoints/webhook.rs
index e3ec9e5ef..49ea29c1e 100644
--- a/proxmox-notify/src/endpoints/webhook.rs
+++ b/proxmox-notify/src/endpoints/webhook.rs
@@ -15,230 +15,25 @@ use handlebars::{
 };
 use http::Request;
 use percent_encoding::AsciiSet;
-use proxmox_schema::property_string::PropertyString;
-use serde::{Deserialize, Serialize};
 use serde_json::{Map, Value, json};
 
 use proxmox_http::client::sync::Client;
 use proxmox_http::{HttpClient, HttpOptions, ProxyConfig};
-use proxmox_schema::api_types::{COMMENT_SCHEMA, HTTP_URL_SCHEMA};
-use proxmox_schema::{ApiStringFormat, ApiType, Schema, StringSchema, Updater, api};
 
+use crate::api_types::{HttpMethod, WebhookConfig, WebhookPrivateConfig};
 use crate::renderer::TemplateType;
-use crate::schema::ENTITY_NAME_SCHEMA;
-use crate::{Content, Context, Error, Notification, Origin, renderer};
+use crate::{Content, Context, Error, Notification, renderer};
 
 use super::Endpoint;
 
-/// This will be used as a section type in the public/private configuration file.
-pub(crate) const WEBHOOK_TYPENAME: &str = "webhook";
-
 const HTTP_TIMEOUT: Duration = Duration::from_secs(10);
 
-#[api]
-#[derive(Serialize, Deserialize, Clone, Copy, Default, PartialEq)]
-#[serde(rename_all = "kebab-case")]
-/// HTTP Method to use.
-pub enum HttpMethod {
-    /// HTTP POST
-    #[default]
-    Post,
-    /// HTTP PUT
-    Put,
-    /// HTTP GET
-    Get,
-}
-
-// We only ever need a &str, so we rather implement this
-// instead of Display.
-impl From<HttpMethod> for &str {
-    fn from(value: HttpMethod) -> Self {
-        match value {
-            HttpMethod::Post => "POST",
-            HttpMethod::Put => "PUT",
-            HttpMethod::Get => "GET",
-        }
-    }
-}
-
-#[api(
-    properties: {
-        name: {
-            schema: ENTITY_NAME_SCHEMA,
-        },
-        url: {
-            schema: HTTP_URL_SCHEMA,
-        },
-        comment: {
-            optional: true,
-            schema: COMMENT_SCHEMA,
-        },
-        header: {
-            type: Array,
-            items: {
-                schema: KEY_AND_BASE64_VALUE_SCHEMA,
-            },
-            optional: true,
-        },
-        secret: {
-            type: Array,
-            items: {
-                schema: KEY_AND_BASE64_VALUE_SCHEMA,
-            },
-            optional: true,
-        },
-    }
-)]
-#[derive(Serialize, Deserialize, Updater, Default, Clone)]
-#[serde(rename_all = "kebab-case")]
-/// Config for  Webhook notification endpoints
-pub struct WebhookConfig {
-    /// Name of the endpoint.
-    #[updater(skip)]
-    pub name: String,
-
-    pub method: HttpMethod,
-
-    /// Webhook URL. Supports templating.
-    pub url: String,
-    /// Array of HTTP headers. Each entry is a property string with a name and a value.
-    /// The value property contains the header in base64 encoding. Supports templating.
-    #[serde(default, skip_serializing_if = "Vec::is_empty")]
-    #[updater(serde(skip_serializing_if = "Option::is_none"))]
-    pub header: Vec<PropertyString<KeyAndBase64Val>>,
-    /// The HTTP body to send. Supports templating.
-    #[serde(skip_serializing_if = "Option::is_none")]
-    pub body: Option<String>,
-
-    /// Comment.
-    #[serde(skip_serializing_if = "Option::is_none")]
-    pub comment: Option<String>,
-    /// Disable this target.
-    #[serde(skip_serializing_if = "Option::is_none")]
-    pub disable: Option<bool>,
-    /// Origin of this config entry.
-    #[serde(skip_serializing_if = "Option::is_none")]
-    #[updater(skip)]
-    pub origin: Option<Origin>,
-    /// Array of secrets. Each entry is a property string with a name and an optional value.
-    /// The value property contains the secret in base64 encoding.
-    /// For any API endpoints returning the endpoint config,
-    /// only the secret name but not the value will be returned.
-    /// When updating the config, also send all secrets that you want
-    /// to keep, setting only the name but not the value. Can be accessed from templates.
-    #[serde(default, skip_serializing_if = "Vec::is_empty")]
-    #[updater(serde(skip_serializing_if = "Option::is_none"))]
-    pub secret: Vec<PropertyString<KeyAndBase64Val>>,
-}
-
-#[api(
-    properties: {
-        name: {
-            schema: ENTITY_NAME_SCHEMA,
-        },
-        secret: {
-            type: Array,
-            items: {
-                schema: KEY_AND_BASE64_VALUE_SCHEMA,
-            },
-            optional: true,
-        },
-    }
-)]
-#[derive(Serialize, Deserialize, Clone, Updater, Default)]
-#[serde(rename_all = "kebab-case")]
-/// Private configuration for Webhook notification endpoints.
-/// This config will be saved to a separate configuration file with stricter
-/// permissions (root:root 0600).
-pub struct WebhookPrivateConfig {
-    /// Name of the endpoint
-    #[updater(skip)]
-    pub name: String,
-
-    #[serde(default, skip_serializing_if = "Vec::is_empty")]
-    #[updater(serde(skip_serializing_if = "Option::is_none"))]
-    /// Array of secrets. Each entry is a property string with a name,
-    /// and a value property. The value property contains the secret
-    /// in base64 encoding. Can be accessed from templates.
-    pub secret: Vec<PropertyString<KeyAndBase64Val>>,
-}
-
 /// A Webhook notification endpoint.
-pub struct WebhookEndpoint {
+pub(crate) struct WebhookEndpoint {
     pub config: WebhookConfig,
     pub private_config: WebhookPrivateConfig,
 }
 
-#[api]
-#[derive(Serialize, Deserialize)]
-#[serde(rename_all = "kebab-case")]
-/// Webhook configuration properties that can be deleted.
-pub enum DeleteableWebhookProperty {
-    /// Delete `comment`.
-    Comment,
-    /// Delete `disable`.
-    Disable,
-    /// Delete `header`.
-    Header,
-    /// Delete `body`.
-    Body,
-    /// Delete `secret`.
-    Secret,
-}
-
-#[api]
-#[derive(Serialize, Deserialize, Debug, Default, Clone)]
-/// Datatype used to represent key-value pairs, the value
-/// being encoded in base64.
-pub struct KeyAndBase64Val {
-    /// Name
-    pub name: String,
-    /// Base64 encoded value
-    #[serde(skip_serializing_if = "Option::is_none")]
-    pub value: Option<String>,
-}
-
-impl KeyAndBase64Val {
-    #[cfg(test)]
-    pub fn new_with_plain_value(name: &str, value: &str) -> Self {
-        let value = proxmox_base64::encode(value);
-
-        Self {
-            name: name.into(),
-            value: Some(value),
-        }
-    }
-
-    /// Decode the contained value, returning the plaintext value
-    ///
-    /// Returns an error if the contained value is not valid base64-encoded
-    /// text.
-    pub fn decode_value(&self) -> Result<String, Error> {
-        let value = self.value.as_deref().unwrap_or_default();
-        let bytes = proxmox_base64::decode(value).map_err(|_| {
-            Error::invalid_config(format!(
-                "could not decode base64 value with key '{}'",
-                self.name
-            ))
-        })?;
-        let value = String::from_utf8(bytes).map_err(|_| {
-            Error::invalid_config(format!(
-                "could not decode UTF8 string from base64, key '{}'",
-                self.name
-            ))
-        })?;
-
-        Ok(value)
-    }
-}
-
-pub const KEY_AND_BASE64_VALUE_SCHEMA: Schema =
-    StringSchema::new("String schema for pairs of keys and base64 encoded values")
-        .format(&ApiStringFormat::PropertyString(
-            &KeyAndBase64Val::API_SCHEMA,
-        ))
-        .schema();
-
 impl Endpoint for WebhookEndpoint {
     /// Send a notification to a webhook endpoint.
     fn send(&self, context: &Context, notification: &Notification) -> Result<(), Error> {
@@ -518,7 +313,7 @@ mod tests {
     use std::collections::HashMap;
 
     use super::*;
-    use crate::{Severity, context::test};
+    use crate::{Severity, api_types::KeyAndBase64Val, context::test};
 
     #[test]
     fn test_build_request() {
diff --git a/proxmox-notify/src/lib.rs b/proxmox-notify/src/lib.rs
index 6675a9f76..c74e7e1a9 100644
--- a/proxmox-notify/src/lib.rs
+++ b/proxmox-notify/src/lib.rs
@@ -15,16 +15,18 @@ use proxmox_schema::api;
 use proxmox_section_config::SectionConfigData;
 use proxmox_uuid::Uuid;
 
-pub mod matcher;
-use matcher::{MATCHER_TYPENAME, MatcherConfig};
-
+#[cfg(feature = "api-impl")]
 pub mod api;
+
 pub mod config;
 pub mod context;
 pub mod endpoints;
 pub mod renderer;
 pub mod schema;
 
+#[cfg(feature = "api-types")]
+pub mod api_types;
+
 mod error;
 pub use error::Error;
 
@@ -33,6 +35,9 @@ pub use context::ContextImpl;
 
 use endpoints::Endpoint;
 
+use crate::api_types::MATCHER_TYPENAME;
+use crate::api_types::MatcherConfig;
+
 #[api()]
 #[derive(Clone, Debug, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd)]
 #[serde(rename_all = "kebab-case")]
@@ -312,7 +317,6 @@ pub struct Bus {
     matchers: Vec<MatcherConfig>,
 }
 
-#[allow(unused_macros)]
 macro_rules! parse_endpoints_with_private_config {
     ($config:ident, $public_config:ty, $private_config:ty, $endpoint_type:ident, $type_name:expr) => {
         (|| -> Result<Vec<Box<dyn Endpoint>>, Error> {
@@ -354,7 +358,6 @@ macro_rules! parse_endpoints_with_private_config {
     };
 }
 
-#[allow(unused_macros)]
 macro_rules! parse_endpoints_without_private_config {
     ($config:ident, $public_config:ty, $endpoint_type:ident, $type_name:expr) => {
         (|| -> Result<Vec<Box<dyn Endpoint>>, Error> {
@@ -377,75 +380,65 @@ macro_rules! parse_endpoints_without_private_config {
 impl Bus {
     /// Instantiate notification bus from a given configuration.
     pub fn from_config(config: &Config) -> Result<Self, Error> {
-        #[allow(unused_mut)]
         let mut endpoints = HashMap::new();
 
         // Instantiate endpoints
-        #[cfg(feature = "sendmail")]
-        {
-            use endpoints::sendmail::SENDMAIL_TYPENAME;
-            use endpoints::sendmail::{SendmailConfig, SendmailEndpoint};
-            endpoints.extend(
-                parse_endpoints_without_private_config!(
-                    config,
-                    SendmailConfig,
-                    SendmailEndpoint,
-                    SENDMAIL_TYPENAME
-                )?
-                .into_iter()
-                .map(|e| (e.name().into(), e)),
-            );
-        }
+        use crate::api_types::{SENDMAIL_TYPENAME, SendmailConfig};
+        use endpoints::sendmail::SendmailEndpoint;
+        endpoints.extend(
+            parse_endpoints_without_private_config!(
+                config,
+                SendmailConfig,
+                SendmailEndpoint,
+                SENDMAIL_TYPENAME
+            )?
+            .into_iter()
+            .map(|e| (e.name().into(), e)),
+        );
 
-        #[cfg(feature = "gotify")]
-        {
-            use endpoints::gotify::GOTIFY_TYPENAME;
-            use endpoints::gotify::{GotifyConfig, GotifyEndpoint, GotifyPrivateConfig};
-            endpoints.extend(
-                parse_endpoints_with_private_config!(
-                    config,
-                    GotifyConfig,
-                    GotifyPrivateConfig,
-                    GotifyEndpoint,
-                    GOTIFY_TYPENAME
-                )?
-                .into_iter()
-                .map(|e| (e.name().into(), e)),
-            );
-        }
-        #[cfg(feature = "smtp")]
-        {
-            use endpoints::smtp::SMTP_TYPENAME;
-            use endpoints::smtp::{SmtpConfig, SmtpEndpoint, SmtpPrivateConfig};
-            endpoints.extend(
-                parse_endpoints_with_private_config!(
-                    config,
-                    SmtpConfig,
-                    SmtpPrivateConfig,
-                    SmtpEndpoint,
-                    SMTP_TYPENAME
-                )?
-                .into_iter()
-                .map(|e| (e.name().into(), e)),
-            );
-        }
+        use crate::api_types::{GOTIFY_TYPENAME, GotifyConfig, GotifyPrivateConfig};
+        use crate::endpoints::gotify::GotifyEndpoint;
 
-        #[cfg(feature = "webhook")]
-        {
-            use endpoints::webhook::WEBHOOK_TYPENAME;
-            use endpoints::webhook::{WebhookConfig, WebhookEndpoint, WebhookPrivateConfig};
-            endpoints.extend(
-                parse_endpoints_with_private_config!(
-                    config,
-                    WebhookConfig,
-                    WebhookPrivateConfig,
-                    WebhookEndpoint,
-                    WEBHOOK_TYPENAME
-                )?
-                .into_iter()
-                .map(|e| (e.name().into(), e)),
-            );
-        }
+        endpoints.extend(
+            parse_endpoints_with_private_config!(
+                config,
+                GotifyConfig,
+                GotifyPrivateConfig,
+                GotifyEndpoint,
+                GOTIFY_TYPENAME
+            )?
+            .into_iter()
+            .map(|e| (e.name().into(), e)),
+        );
+
+        use crate::api_types::{SMTP_TYPENAME, SmtpConfig, SmtpPrivateConfig};
+        use endpoints::smtp::SmtpEndpoint;
+
+        endpoints.extend(
+            parse_endpoints_with_private_config!(
+                config,
+                SmtpConfig,
+                SmtpPrivateConfig,
+                SmtpEndpoint,
+                SMTP_TYPENAME
+            )?
+            .into_iter()
+            .map(|e| (e.name().into(), e)),
+        );
+
+        use crate::api_types::{WEBHOOK_TYPENAME, WebhookConfig, WebhookPrivateConfig};
+        use endpoints::webhook::WebhookEndpoint;
+        endpoints.extend(
+            parse_endpoints_with_private_config!(
+                config,
+                WebhookConfig,
+                WebhookPrivateConfig,
+                WebhookEndpoint,
+                WEBHOOK_TYPENAME
+            )?
+            .into_iter()
+            .map(|e| (e.name().into(), e)),
+        );
 
         let matchers = config
             .config
@@ -473,7 +466,7 @@ impl Bus {
     ///
     /// Any errors will not be returned but only logged.
     pub fn send(&self, context: &Context, notification: &Notification) {
-        let targets = matcher::check_matches(self.matchers.as_slice(), notification);
+        let targets = api_types::check_matches(self.matchers.as_slice(), notification);
 
         for target in targets {
             if let Some(endpoint) = self.endpoints.get(target) {
@@ -535,8 +528,10 @@ mod tests {
 
     use proxmox_match_expression::Expression;
 
-    use crate::context::test;
-    use crate::matcher::{expression::NotificationMatcher, severity::SeverityMatcher};
+    use crate::{
+        api_types::{expression::NotificationMatcher, severity::SeverityMatcher},
+        context::{Context, test},
+    };
 
     use super::*;
 
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 08/63] notify: matcher: make matcher validation methods public
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (6 preceding siblings ...)
  2026-11-18  9:42 ` [PATCH proxmox v2 07/63] notify: introduce 'send-impl', 'api-impl' and 'api-types' features Lukas Wagner
@ 2026-11-18  9:42 ` Lukas Wagner
  2026-11-18  9:42 ` [PATCH proxmox v2 09/63] notify: matcher: stub CalendarMatcher::matches on wasm32 Lukas Wagner
                   ` (55 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:42 UTC (permalink / raw)
  To: pve-devel

These will be useful in GUI code.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/api_types/matcher/mod.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/proxmox-notify/src/api_types/matcher/mod.rs b/proxmox-notify/src/api_types/matcher/mod.rs
index 8f0bc7405..815c9e8ff 100644
--- a/proxmox-notify/src/api_types/matcher/mod.rs
+++ b/proxmox-notify/src/api_types/matcher/mod.rs
@@ -224,7 +224,7 @@ impl MatcherConfig {
     }
 
     /// Ensure the validity of this matcher.
-    pub(crate) fn ensure_valid(&mut self) -> Result<(), Error> {
+    pub fn ensure_valid(&mut self) -> Result<(), Error> {
         #[cfg(feature = "legacy-matchers")]
         self.ensure_no_ignored_properties()?;
         self.ensure_valid_expression()?;
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 09/63] notify: matcher: stub CalendarMatcher::matches on wasm32
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (7 preceding siblings ...)
  2026-11-18  9:42 ` [PATCH proxmox v2 08/63] notify: matcher: make matcher validation methods public Lukas Wagner
@ 2026-11-18  9:42 ` Lukas Wagner
  2026-11-18  9:42 ` [PATCH proxmox v2 10/63] notify: make SendmailEndpoint and SmtpEndpoint private types Lukas Wagner
                   ` (54 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:42 UTC (permalink / raw)
  To: pve-devel

The matching logic is part of the api_types module, since it will be
quite useful to test/validate matching in a Rust-based UI.

Unfortunately, the DailyDuration type does not implement the
`time_match` method on wasm32, which is why it is stubbed out for now.
The current implementation of DailyDuration relies on libc, but there is
no reason why we could not implement a wasm-friendly version of the same
behavior, which is why stubbing out seemed like the most appropriate
thing to do.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---

Notes:
    New in v2.

 proxmox-notify/src/api_types/matcher/calendar.rs | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/proxmox-notify/src/api_types/matcher/calendar.rs b/proxmox-notify/src/api_types/matcher/calendar.rs
index 0a8d31e7a..a0640b49a 100644
--- a/proxmox-notify/src/api_types/matcher/calendar.rs
+++ b/proxmox-notify/src/api_types/matcher/calendar.rs
@@ -15,6 +15,7 @@ use super::MatchDirective;
 #[derive(Clone, Debug)]
 struct DailyDurationWrapper {
     schedule: String,
+    #[cfg_attr(target_arch = "wasm32", allow(unused))]
     daily_duration: DailyDuration,
 }
 
@@ -61,6 +62,7 @@ impl From<CalendarMatcher> for Expression<NotificationMatcher> {
 }
 
 impl MatchDirective for CalendarMatcher {
+    #[cfg(not(target_arch = "wasm32"))]
     fn matches(&self, notification: &Notification) -> Result<bool, Error> {
         self.schedule
             .daily_duration
@@ -68,6 +70,13 @@ impl MatchDirective for CalendarMatcher {
             .map_err(|err| Error::invalid_config_with_source("could not match timestamp", err))
     }
 
+    #[cfg(target_arch = "wasm32")]
+    fn matches(&self, _notification: &Notification) -> Result<bool, Error> {
+        Err(Error::other(
+            "CalendarMatcher::matches not supported on wasm32",
+        ))
+    }
+
     fn validate(&self) -> Result<(), Error> {
         Ok(())
     }
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 10/63] notify: make SendmailEndpoint and SmtpEndpoint private types
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (8 preceding siblings ...)
  2026-11-18  9:42 ` [PATCH proxmox v2 09/63] notify: matcher: stub CalendarMatcher::matches on wasm32 Lukas Wagner
@ 2026-11-18  9:42 ` Lukas Wagner
  2026-11-18  9:42 ` [PATCH proxmox v2 11/63] notify: move `send`, `test_target` and `Bus` to new `send` module Lukas Wagner
                   ` (53 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:42 UTC (permalink / raw)
  To: pve-devel

These types should not be accessible by users of the crate.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/endpoints/sendmail.rs | 2 +-
 proxmox-notify/src/endpoints/smtp.rs     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/proxmox-notify/src/endpoints/sendmail.rs b/proxmox-notify/src/endpoints/sendmail.rs
index 6ddee5161..bbed31b4f 100644
--- a/proxmox-notify/src/endpoints/sendmail.rs
+++ b/proxmox-notify/src/endpoints/sendmail.rs
@@ -8,7 +8,7 @@ use crate::{Content, Context, Error, Notification, renderer};
 use super::Endpoint;
 
 /// A sendmail notification endpoint.
-pub struct SendmailEndpoint {
+pub(crate) struct SendmailEndpoint {
     pub config: SendmailConfig,
 }
 
diff --git a/proxmox-notify/src/endpoints/smtp.rs b/proxmox-notify/src/endpoints/smtp.rs
index ccade1c8e..fa0810fbb 100644
--- a/proxmox-notify/src/endpoints/smtp.rs
+++ b/proxmox-notify/src/endpoints/smtp.rs
@@ -19,7 +19,7 @@ const SMTP_SUBMISSION_TLS_PORT: u16 = 465;
 const SMTP_TIMEOUT: u16 = 5;
 
 /// A sendmail notification endpoint.
-pub struct SmtpEndpoint {
+pub(crate) struct SmtpEndpoint {
     pub config: SmtpConfig,
     pub private_config: SmtpPrivateConfig,
 }
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 11/63] notify: move `send`, `test_target` and `Bus` to new `send` module
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (9 preceding siblings ...)
  2026-11-18  9:42 ` [PATCH proxmox v2 10/63] notify: make SendmailEndpoint and SmtpEndpoint private types Lukas Wagner
@ 2026-11-18  9:42 ` Lukas Wagner
  2026-11-18  9:42 ` [PATCH proxmox v2 12/63] notify: move Origin type to api_types module Lukas Wagner
                   ` (52 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:42 UTC (permalink / raw)
  To: pve-devel

lib.rs has grown quite large, so moving functionality to smaller
submodules is appropriate. This also makes it easier to feature-gate
these functions/types with a single directive in lib.rs.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/api/common.rs |  47 +---
 proxmox-notify/src/lib.rs        | 374 +----------------------------
 proxmox-notify/src/send.rs       | 393 +++++++++++++++++++++++++++++++
 3 files changed, 398 insertions(+), 416 deletions(-)
 create mode 100644 proxmox-notify/src/send.rs

diff --git a/proxmox-notify/src/api/common.rs b/proxmox-notify/src/api/common.rs
index 56a9797a9..a31cbaea8 100644
--- a/proxmox-notify/src/api/common.rs
+++ b/proxmox-notify/src/api/common.rs
@@ -1,51 +1,6 @@
 use proxmox_http_error::HttpError;
 
-use super::http_err;
-use crate::{Bus, Config, Context, Error, Notification};
-
-/// Send a notification to a given target.
-///
-/// The caller is responsible for any needed permission checks.
-/// Returns an `anyhow::Error` in case of an error.
-pub fn send(
-    context: &Context,
-    config: &Config,
-    notification: &Notification,
-) -> Result<(), HttpError> {
-    let bus = Bus::from_config(config).map_err(|err| {
-        http_err!(
-            INTERNAL_SERVER_ERROR,
-            "Could not instantiate notification bus: {err}"
-        )
-    })?;
-
-    bus.send(context, notification);
-
-    Ok(())
-}
-
-/// Test target (group or single endpoint) identified by its `name`.
-///
-/// The caller is responsible for any needed permission checks.
-/// Returns an `anyhow::Error` if sending via the endpoint failed.
-pub fn test_target(context: &Context, config: &Config, endpoint: &str) -> Result<(), HttpError> {
-    let bus = Bus::from_config(config).map_err(|err| {
-        http_err!(
-            INTERNAL_SERVER_ERROR,
-            "Could not instantiate notification bus: {err}"
-        )
-    })?;
-
-    bus.test_target(context, endpoint)
-        .map_err(|err| match err {
-            Error::TargetDoesNotExist(endpoint) => {
-                http_err!(NOT_FOUND, "endpoint '{endpoint}' does not exist")
-            }
-            _ => http_err!(INTERNAL_SERVER_ERROR, "Could not test target: {err}"),
-        })?;
-
-    Ok(())
-}
+use crate::Config;
 
 /// Return all entities (targets, groups, filters) that are linked to the entity.
 /// For instance, if a group 'grp1' contains the targets 'a', 'b' and 'c',
diff --git a/proxmox-notify/src/lib.rs b/proxmox-notify/src/lib.rs
index c74e7e1a9..2061d9150 100644
--- a/proxmox-notify/src/lib.rs
+++ b/proxmox-notify/src/lib.rs
@@ -7,8 +7,7 @@ use std::str::FromStr;
 
 use serde::{Deserialize, Serialize};
 use serde_json::Value;
-use serde_json::json;
-use tracing::{error, info};
+use tracing::error;
 
 use proxmox_config_digest::ConfigDigest;
 use proxmox_schema::api;
@@ -24,6 +23,9 @@ pub mod endpoints;
 pub mod renderer;
 pub mod schema;
 
+#[cfg(feature = "send-impl")]
+pub mod send;
+
 #[cfg(feature = "api-types")]
 pub mod api_types;
 
@@ -33,11 +35,6 @@ pub use error::Error;
 pub use context::Context;
 pub use context::ContextImpl;
 
-use endpoints::Endpoint;
-
-use crate::api_types::MATCHER_TYPENAME;
-use crate::api_types::MatcherConfig;
-
 #[api()]
 #[derive(Clone, Debug, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd)]
 #[serde(rename_all = "kebab-case")]
@@ -307,366 +304,3 @@ impl Config {
         &self.digest
     }
 }
-
-/// Notification bus - distributes notifications to all registered endpoints
-// The reason for the split between `Config` and this struct is to make testing with mocked
-// endpoints a bit easier.
-#[derive(Default)]
-pub struct Bus {
-    endpoints: HashMap<String, Box<dyn Endpoint>>,
-    matchers: Vec<MatcherConfig>,
-}
-
-macro_rules! parse_endpoints_with_private_config {
-    ($config:ident, $public_config:ty, $private_config:ty, $endpoint_type:ident, $type_name:expr) => {
-        (|| -> Result<Vec<Box<dyn Endpoint>>, Error> {
-            let mut endpoints = Vec::<Box<dyn Endpoint>>::new();
-
-            let configs: Vec<$public_config> = $config
-                .config
-                .convert_to_typed_array($type_name)
-                .map_err(|err| Error::ConfigDeserialization(err.into()))?;
-
-            for config in configs {
-                match $config.private_config.sections.get(&config.name) {
-                    Some((section_type_name, private_config)) => {
-                        if $type_name != section_type_name {
-                            error!(
-                                "Could not instantiate endpoint '{name}': \
-                                private config has wrong type",
-                                name = config.name
-                            );
-                        }
-                        let private_config = <$private_config>::deserialize(private_config)
-                            .map_err(|err| Error::ConfigDeserialization(err.into()))?;
-
-                        endpoints.push(Box::new($endpoint_type {
-                            config,
-                            private_config: private_config.clone(),
-                        }));
-                    }
-                    None => error!(
-                        "Could not instantiate endpoint '{name}': \
-                            private config does not exist",
-                        name = config.name
-                    ),
-                }
-            }
-
-            Ok(endpoints)
-        })()
-    };
-}
-
-macro_rules! parse_endpoints_without_private_config {
-    ($config:ident, $public_config:ty, $endpoint_type:ident, $type_name:expr) => {
-        (|| -> Result<Vec<Box<dyn Endpoint>>, Error> {
-            let mut endpoints = Vec::<Box<dyn Endpoint>>::new();
-
-            let configs: Vec<$public_config> = $config
-                .config
-                .convert_to_typed_array($type_name)
-                .map_err(|err| Error::ConfigDeserialization(err.into()))?;
-
-            for config in configs {
-                endpoints.push(Box::new($endpoint_type { config }));
-            }
-
-            Ok(endpoints)
-        })()
-    };
-}
-
-impl Bus {
-    /// Instantiate notification bus from a given configuration.
-    pub fn from_config(config: &Config) -> Result<Self, Error> {
-        let mut endpoints = HashMap::new();
-
-        // Instantiate endpoints
-        use crate::api_types::{SENDMAIL_TYPENAME, SendmailConfig};
-        use endpoints::sendmail::SendmailEndpoint;
-        endpoints.extend(
-            parse_endpoints_without_private_config!(
-                config,
-                SendmailConfig,
-                SendmailEndpoint,
-                SENDMAIL_TYPENAME
-            )?
-            .into_iter()
-            .map(|e| (e.name().into(), e)),
-        );
-
-        use crate::api_types::{GOTIFY_TYPENAME, GotifyConfig, GotifyPrivateConfig};
-        use crate::endpoints::gotify::GotifyEndpoint;
-
-        endpoints.extend(
-            parse_endpoints_with_private_config!(
-                config,
-                GotifyConfig,
-                GotifyPrivateConfig,
-                GotifyEndpoint,
-                GOTIFY_TYPENAME
-            )?
-            .into_iter()
-            .map(|e| (e.name().into(), e)),
-        );
-
-        use crate::api_types::{SMTP_TYPENAME, SmtpConfig, SmtpPrivateConfig};
-        use endpoints::smtp::SmtpEndpoint;
-
-        endpoints.extend(
-            parse_endpoints_with_private_config!(
-                config,
-                SmtpConfig,
-                SmtpPrivateConfig,
-                SmtpEndpoint,
-                SMTP_TYPENAME
-            )?
-            .into_iter()
-            .map(|e| (e.name().into(), e)),
-        );
-
-        use crate::api_types::{WEBHOOK_TYPENAME, WebhookConfig, WebhookPrivateConfig};
-        use endpoints::webhook::WebhookEndpoint;
-        endpoints.extend(
-            parse_endpoints_with_private_config!(
-                config,
-                WebhookConfig,
-                WebhookPrivateConfig,
-                WebhookEndpoint,
-                WEBHOOK_TYPENAME
-            )?
-            .into_iter()
-            .map(|e| (e.name().into(), e)),
-        );
-
-        let matchers = config
-            .config
-            .convert_to_typed_array(MATCHER_TYPENAME)
-            .map_err(|err| Error::ConfigDeserialization(err.into()))?;
-
-        Ok(Bus {
-            endpoints,
-            matchers,
-        })
-    }
-
-    #[cfg(test)]
-    pub(crate) fn add_endpoint(&mut self, endpoint: Box<dyn Endpoint>) {
-        self.endpoints.insert(endpoint.name().to_string(), endpoint);
-    }
-
-    #[cfg(test)]
-    pub fn add_matcher(&mut self, filter: MatcherConfig) {
-        self.matchers.push(filter)
-    }
-
-    /// Send a notification. Notification matchers will determine which targets will receive
-    /// the notification.
-    ///
-    /// Any errors will not be returned but only logged.
-    pub fn send(&self, context: &Context, notification: &Notification) {
-        let targets = api_types::check_matches(self.matchers.as_slice(), notification);
-
-        for target in targets {
-            if let Some(endpoint) = self.endpoints.get(target) {
-                let name = endpoint.name();
-
-                if endpoint.disabled() {
-                    // Skip this target if it is disabled
-                    info!("skipping disabled target '{name}'");
-                    continue;
-                }
-
-                match endpoint.send(context, notification) {
-                    Ok(_) => {
-                        info!("notified via target `{name}`");
-                    }
-                    Err(e) => {
-                        // Only log on errors, do not propagate fail to the caller.
-                        error!("could not notify via target `{name}`: {e}");
-                    }
-                }
-            } else {
-                error!("could not notify via target '{target}', it does not exist");
-            }
-        }
-    }
-
-    /// Send a test notification to a target (endpoint or group).
-    ///
-    /// In contrast to the `send` function, this function will return
-    /// any errors to the caller.
-    pub fn test_target(&self, context: &Context, target: &str) -> Result<(), Error> {
-        let notification = Notification {
-            metadata: Metadata {
-                severity: Severity::Info,
-                // TODO: what fields would make sense for test notifications?
-                additional_fields: Default::default(),
-                timestamp: proxmox_time::epoch_i64(),
-            },
-            content: Content::Template {
-                template_name: "test".to_string(),
-                data: json!({ "target": target }),
-            },
-            id: Uuid::generate(),
-        };
-
-        if let Some(endpoint) = self.endpoints.get(target) {
-            endpoint.send(context, &notification)?;
-        } else {
-            return Err(Error::target_does_not_exist(target));
-        }
-
-        Ok(())
-    }
-}
-
-#[cfg(test)]
-mod tests {
-    use std::{cell::RefCell, rc::Rc};
-
-    use proxmox_match_expression::Expression;
-
-    use crate::{
-        api_types::{expression::NotificationMatcher, severity::SeverityMatcher},
-        context::{Context, test},
-    };
-
-    use super::*;
-
-    #[derive(Default, Clone)]
-    struct MockEndpoint {
-        name: &'static str,
-        // Needs to be an Rc so that we can clone MockEndpoint before
-        // passing it to Bus, while still retaining a handle to the Vec
-        messages: Rc<RefCell<Vec<Notification>>>,
-    }
-
-    impl Endpoint for MockEndpoint {
-        fn send(&self, _context: &Context, message: &Notification) -> Result<(), Error> {
-            self.messages.borrow_mut().push(message.clone());
-
-            Ok(())
-        }
-
-        fn name(&self) -> &str {
-            self.name
-        }
-
-        fn disabled(&self) -> bool {
-            false
-        }
-    }
-
-    impl MockEndpoint {
-        fn new(name: &'static str) -> Self {
-            Self {
-                name,
-                ..Default::default()
-            }
-        }
-
-        fn messages(&self) -> Vec<Notification> {
-            self.messages.borrow().clone()
-        }
-    }
-
-    fn expression_to_string(expression: Expression<NotificationMatcher>) -> String {
-        serde_json::to_string(&expression).unwrap()
-    }
-
-    #[test]
-    fn test_add_mock_endpoint() -> Result<(), Error> {
-        let context = test::test_context();
-        let mock = MockEndpoint::new("endpoint");
-
-        let mut bus = Bus::default();
-        bus.add_endpoint(Box::new(mock.clone()));
-
-        let matcher = MatcherConfig {
-            target: vec!["endpoint".into()],
-            expression: Some(expression_to_string(Expression::Constant(true))),
-            ..Default::default()
-        };
-
-        bus.add_matcher(matcher);
-
-        // Send directly to endpoint
-        bus.send(
-            &context,
-            &Notification::from_template(
-                Severity::Info,
-                "test",
-                Default::default(),
-                Default::default(),
-            ),
-        );
-        let messages = mock.messages();
-        assert_eq!(messages.len(), 1);
-
-        Ok(())
-    }
-
-    #[test]
-    fn test_multiple_endpoints_with_different_matchers() -> Result<(), Error> {
-        let context = test::test_context();
-
-        let endpoint1 = MockEndpoint::new("mock1");
-        let endpoint2 = MockEndpoint::new("mock2");
-
-        let mut bus = Bus::default();
-
-        bus.add_endpoint(Box::new(endpoint1.clone()));
-        bus.add_endpoint(Box::new(endpoint2.clone()));
-
-        bus.add_matcher(MatcherConfig {
-            name: "matcher1".into(),
-            expression: Some(expression_to_string(
-                SeverityMatcher {
-                    severities: vec![Severity::Error, Severity::Warning],
-                }
-                .into(),
-            )),
-            target: vec!["mock1".into()],
-            ..Default::default()
-        });
-
-        bus.add_matcher(MatcherConfig {
-            name: "matcher2".into(),
-            expression: Some(expression_to_string(
-                SeverityMatcher {
-                    severities: vec![Severity::Error],
-                }
-                .into(),
-            )),
-            target: vec!["mock2".into()],
-            ..Default::default()
-        });
-
-        let send_with_severity = |severity| {
-            let notification = Notification::from_template(
-                severity,
-                "test",
-                Default::default(),
-                Default::default(),
-            );
-
-            bus.send(&context, &notification);
-        };
-
-        send_with_severity(Severity::Info);
-        assert_eq!(endpoint1.messages().len(), 0);
-        assert_eq!(endpoint2.messages().len(), 0);
-
-        send_with_severity(Severity::Warning);
-        assert_eq!(endpoint1.messages().len(), 1);
-        assert_eq!(endpoint2.messages().len(), 0);
-
-        send_with_severity(Severity::Error);
-        assert_eq!(endpoint1.messages().len(), 2);
-        assert_eq!(endpoint2.messages().len(), 1);
-
-        Ok(())
-    }
-}
diff --git a/proxmox-notify/src/send.rs b/proxmox-notify/src/send.rs
new file mode 100644
index 000000000..3ef63aa8c
--- /dev/null
+++ b/proxmox-notify/src/send.rs
@@ -0,0 +1,393 @@
+use std::collections::HashMap;
+
+use proxmox_uuid::Uuid;
+use serde::Deserialize;
+use serde_json::json;
+use tracing::{error, info};
+
+use crate::api_types::{GOTIFY_TYPENAME, GotifyConfig, GotifyPrivateConfig};
+use crate::api_types::{MATCHER_TYPENAME, MatcherConfig};
+use crate::api_types::{SENDMAIL_TYPENAME, SendmailConfig};
+use crate::api_types::{SMTP_TYPENAME, SmtpConfig, SmtpPrivateConfig};
+use crate::api_types::{WEBHOOK_TYPENAME, WebhookConfig, WebhookPrivateConfig};
+use crate::endpoints::Endpoint;
+use crate::endpoints::gotify::GotifyEndpoint;
+use crate::endpoints::sendmail::SendmailEndpoint;
+use crate::endpoints::smtp::SmtpEndpoint;
+use crate::endpoints::webhook::WebhookEndpoint;
+use crate::{Config, Content, Context, Error, Metadata, Notification, Severity};
+
+/// Send a notification to a given target.
+///
+/// The caller is responsible for any needed permission checks.
+/// Returns an `anyhow::Error` in case of an error.
+pub fn send(context: &Context, config: &Config, notification: &Notification) -> Result<(), Error> {
+    let bus = Bus::from_config(config)?;
+    bus.send(context, notification);
+
+    Ok(())
+}
+
+/// Test target (group or single endpoint) identified by its `name`.
+///
+/// The caller is responsible for any needed permission checks.
+/// Returns an `anyhow::Error` if sending via the endpoint failed.
+pub fn test_target(context: &Context, config: &Config, endpoint: &str) -> Result<(), Error> {
+    let bus = Bus::from_config(config)?;
+    bus.test_target(context, endpoint)?;
+
+    Ok(())
+}
+
+/// Notification bus - distributes notifications to all registered endpoints
+// The reason for the split between `Config` and this struct is to make testing with mocked
+// endpoints a bit easier.
+#[derive(Default)]
+struct Bus {
+    endpoints: HashMap<String, Box<dyn Endpoint>>,
+    matchers: Vec<MatcherConfig>,
+}
+
+macro_rules! parse_endpoints_with_private_config {
+    ($config:ident, $public_config:ty, $private_config:ty, $endpoint_type:ident, $type_name:expr) => {
+        (|| -> Result<Vec<Box<dyn Endpoint>>, Error> {
+            let mut endpoints = Vec::<Box<dyn Endpoint>>::new();
+
+            let configs: Vec<$public_config> = $config
+                .config
+                .convert_to_typed_array($type_name)
+                .map_err(|err| Error::ConfigDeserialization(err.into()))?;
+
+            for config in configs {
+                match $config.private_config.sections.get(&config.name) {
+                    Some((section_type_name, private_config)) => {
+                        if $type_name != section_type_name {
+                            error!(
+                                "Could not instantiate endpoint '{name}': \
+                                private config has wrong type",
+                                name = config.name
+                            );
+                        }
+                        let private_config = <$private_config>::deserialize(private_config)
+                            .map_err(|err| Error::ConfigDeserialization(err.into()))?;
+
+                        endpoints.push(Box::new($endpoint_type {
+                            config,
+                            private_config: private_config.clone(),
+                        }));
+                    }
+                    None => error!(
+                        "Could not instantiate endpoint '{name}': \
+                            private config does not exist",
+                        name = config.name
+                    ),
+                }
+            }
+
+            Ok(endpoints)
+        })()
+    };
+}
+
+macro_rules! parse_endpoints_without_private_config {
+    ($config:ident, $public_config:ty, $endpoint_type:ident, $type_name:expr) => {
+        (|| -> Result<Vec<Box<dyn Endpoint>>, Error> {
+            let mut endpoints = Vec::<Box<dyn Endpoint>>::new();
+
+            let configs: Vec<$public_config> = $config
+                .config
+                .convert_to_typed_array($type_name)
+                .map_err(|err| Error::ConfigDeserialization(err.into()))?;
+
+            for config in configs {
+                endpoints.push(Box::new($endpoint_type { config }));
+            }
+
+            Ok(endpoints)
+        })()
+    };
+}
+
+impl Bus {
+    /// Instantiate notification bus from a given configuration.
+    pub fn from_config(config: &Config) -> Result<Self, Error> {
+        let mut endpoints = HashMap::new();
+
+        // Instantiate endpoints
+        endpoints.extend(
+            parse_endpoints_without_private_config!(
+                config,
+                SendmailConfig,
+                SendmailEndpoint,
+                SENDMAIL_TYPENAME
+            )?
+            .into_iter()
+            .map(|e| (e.name().into(), e)),
+        );
+
+        endpoints.extend(
+            parse_endpoints_with_private_config!(
+                config,
+                GotifyConfig,
+                GotifyPrivateConfig,
+                GotifyEndpoint,
+                GOTIFY_TYPENAME
+            )?
+            .into_iter()
+            .map(|e| (e.name().into(), e)),
+        );
+
+        endpoints.extend(
+            parse_endpoints_with_private_config!(
+                config,
+                SmtpConfig,
+                SmtpPrivateConfig,
+                SmtpEndpoint,
+                SMTP_TYPENAME
+            )?
+            .into_iter()
+            .map(|e| (e.name().into(), e)),
+        );
+
+        endpoints.extend(
+            parse_endpoints_with_private_config!(
+                config,
+                WebhookConfig,
+                WebhookPrivateConfig,
+                WebhookEndpoint,
+                WEBHOOK_TYPENAME
+            )?
+            .into_iter()
+            .map(|e| (e.name().into(), e)),
+        );
+
+        let matchers = config
+            .config
+            .convert_to_typed_array(MATCHER_TYPENAME)
+            .map_err(|err| Error::ConfigDeserialization(err.into()))?;
+
+        Ok(Bus {
+            endpoints,
+            matchers,
+        })
+    }
+
+    #[cfg(test)]
+    pub(crate) fn add_endpoint(&mut self, endpoint: Box<dyn Endpoint>) {
+        self.endpoints.insert(endpoint.name().to_string(), endpoint);
+    }
+
+    #[cfg(test)]
+    pub(crate) fn add_matcher(&mut self, filter: MatcherConfig) {
+        self.matchers.push(filter)
+    }
+
+    /// Send a notification. Notification matchers will determine which targets will receive
+    /// the notification.
+    ///
+    /// 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);
+
+        for target in targets {
+            if let Some(endpoint) = self.endpoints.get(target) {
+                let name = endpoint.name();
+
+                if endpoint.disabled() {
+                    // Skip this target if it is disabled
+                    info!("skipping disabled target '{name}'");
+                    continue;
+                }
+
+                match endpoint.send(context, notification) {
+                    Ok(_) => {
+                        info!("notified via target `{name}`");
+                    }
+                    Err(e) => {
+                        // Only log on errors, do not propagate fail to the caller.
+                        error!("could not notify via target `{name}`: {e}");
+                    }
+                }
+            } else {
+                error!("could not notify via target '{target}', it does not exist");
+            }
+        }
+    }
+
+    /// Send a test notification to a target (endpoint or group).
+    ///
+    /// In contrast to the `send` function, this function will return
+    /// any errors to the caller.
+    pub fn test_target(&self, context: &Context, target: &str) -> Result<(), Error> {
+        let notification = Notification {
+            metadata: Metadata {
+                severity: Severity::Info,
+                // TODO: what fields would make sense for test notifications?
+                additional_fields: Default::default(),
+                timestamp: proxmox_time::epoch_i64(),
+            },
+            content: Content::Template {
+                template_name: "test".to_string(),
+                data: json!({ "target": target }),
+            },
+            id: Uuid::generate(),
+        };
+
+        if let Some(endpoint) = self.endpoints.get(target) {
+            endpoint.send(context, &notification)?;
+        } else {
+            return Err(Error::target_does_not_exist(target));
+        }
+
+        Ok(())
+    }
+}
+
+#[cfg(test)]
+mod tests {
+    use std::{cell::RefCell, rc::Rc};
+
+    use proxmox_match_expression::Expression;
+
+    use crate::{
+        api_types::{expression::NotificationMatcher, severity::SeverityMatcher},
+        context::{Context, test},
+    };
+
+    use super::*;
+
+    #[derive(Default, Clone)]
+    struct MockEndpoint {
+        name: &'static str,
+        // Needs to be an Rc so that we can clone MockEndpoint before
+        // passing it to Bus, while still retaining a handle to the Vec
+        messages: Rc<RefCell<Vec<Notification>>>,
+    }
+
+    impl Endpoint for MockEndpoint {
+        fn send(&self, _context: &Context, message: &Notification) -> Result<(), Error> {
+            self.messages.borrow_mut().push(message.clone());
+
+            Ok(())
+        }
+
+        fn name(&self) -> &str {
+            self.name
+        }
+
+        fn disabled(&self) -> bool {
+            false
+        }
+    }
+
+    impl MockEndpoint {
+        fn new(name: &'static str) -> Self {
+            Self {
+                name,
+                ..Default::default()
+            }
+        }
+
+        fn messages(&self) -> Vec<Notification> {
+            self.messages.borrow().clone()
+        }
+    }
+
+    fn expression_to_string(expression: Expression<NotificationMatcher>) -> String {
+        serde_json::to_string(&expression).unwrap()
+    }
+
+    #[test]
+    fn test_add_mock_endpoint() -> Result<(), Error> {
+        let context = test::test_context();
+        let mock = MockEndpoint::new("endpoint");
+
+        let mut bus = Bus::default();
+        bus.add_endpoint(Box::new(mock.clone()));
+
+        let matcher = MatcherConfig {
+            target: vec!["endpoint".into()],
+            expression: Some(expression_to_string(Expression::Constant(true))),
+            ..Default::default()
+        };
+
+        bus.add_matcher(matcher);
+
+        // Send directly to endpoint
+        bus.send(
+            &context,
+            &Notification::from_template(
+                Severity::Info,
+                "test",
+                Default::default(),
+                Default::default(),
+            ),
+        );
+        let messages = mock.messages();
+        assert_eq!(messages.len(), 1);
+
+        Ok(())
+    }
+
+    #[test]
+    fn test_multiple_endpoints_with_different_matchers() -> Result<(), Error> {
+        let context = test::test_context();
+
+        let endpoint1 = MockEndpoint::new("mock1");
+        let endpoint2 = MockEndpoint::new("mock2");
+
+        let mut bus = Bus::default();
+
+        bus.add_endpoint(Box::new(endpoint1.clone()));
+        bus.add_endpoint(Box::new(endpoint2.clone()));
+
+        bus.add_matcher(MatcherConfig {
+            name: "matcher1".into(),
+            expression: Some(expression_to_string(
+                SeverityMatcher {
+                    severities: vec![Severity::Error, Severity::Warning],
+                }
+                .into(),
+            )),
+            target: vec!["mock1".into()],
+            ..Default::default()
+        });
+
+        bus.add_matcher(MatcherConfig {
+            name: "matcher2".into(),
+            expression: Some(expression_to_string(
+                SeverityMatcher {
+                    severities: vec![Severity::Error],
+                }
+                .into(),
+            )),
+            target: vec!["mock2".into()],
+            ..Default::default()
+        });
+
+        let send_with_severity = |severity| {
+            let notification = Notification::from_template(
+                severity,
+                "test",
+                Default::default(),
+                Default::default(),
+            );
+
+            bus.send(&context, &notification);
+        };
+
+        send_with_severity(Severity::Info);
+        assert_eq!(endpoint1.messages().len(), 0);
+        assert_eq!(endpoint2.messages().len(), 0);
+
+        send_with_severity(Severity::Warning);
+        assert_eq!(endpoint1.messages().len(), 1);
+        assert_eq!(endpoint2.messages().len(), 0);
+
+        send_with_severity(Severity::Error);
+        assert_eq!(endpoint1.messages().len(), 2);
+        assert_eq!(endpoint2.messages().len(), 1);
+
+        Ok(())
+    }
+}
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 12/63] notify: move Origin type to api_types module
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (10 preceding siblings ...)
  2026-11-18  9:42 ` [PATCH proxmox v2 11/63] notify: move `send`, `test_target` and `Bus` to new `send` module Lukas Wagner
@ 2026-11-18  9:42 ` Lukas Wagner
  2026-11-18  9:42 ` [PATCH proxmox v2 13/63] notify: move Target " Lukas Wagner
                   ` (51 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:42 UTC (permalink / raw)
  To: pve-devel

This is another step in cleaning up the crate root in lib.rs.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/api/mod.rs               |  3 ++-
 proxmox-notify/src/api_types/gotify.rs      |  3 ++-
 proxmox-notify/src/api_types/matcher/mod.rs |  3 ++-
 proxmox-notify/src/api_types/mod.rs         | 17 +++++++++++++++++
 proxmox-notify/src/api_types/sendmail.rs    |  6 ++----
 proxmox-notify/src/api_types/smtp.rs        |  2 +-
 proxmox-notify/src/api_types/webhook.rs     |  5 ++++-
 proxmox-notify/src/lib.rs                   | 17 +----------------
 8 files changed, 31 insertions(+), 25 deletions(-)

diff --git a/proxmox-notify/src/api/mod.rs b/proxmox-notify/src/api/mod.rs
index 63185fd55..c7288ae15 100644
--- a/proxmox-notify/src/api/mod.rs
+++ b/proxmox-notify/src/api/mod.rs
@@ -6,7 +6,8 @@ use proxmox_config_digest::ConfigDigest;
 use proxmox_http_error::HttpError;
 use proxmox_schema::api;
 
-use crate::{Config, Origin};
+use crate::Config;
+use crate::api_types::Origin;
 
 pub mod common;
 pub mod gotify;
diff --git a/proxmox-notify/src/api_types/gotify.rs b/proxmox-notify/src/api_types/gotify.rs
index 7c6e897e8..433a9fae3 100644
--- a/proxmox-notify/src/api_types/gotify.rs
+++ b/proxmox-notify/src/api_types/gotify.rs
@@ -2,7 +2,8 @@ use serde::{Deserialize, Serialize};
 
 use proxmox_schema::{Updater, api, api_types::COMMENT_SCHEMA};
 
-use crate::{Origin, schema::ENTITY_NAME_SCHEMA};
+use crate::api_types::Origin;
+use crate::schema::ENTITY_NAME_SCHEMA;
 
 pub const GOTIFY_TYPENAME: &str = "gotify";
 
diff --git a/proxmox-notify/src/api_types/matcher/mod.rs b/proxmox-notify/src/api_types/matcher/mod.rs
index 815c9e8ff..3e8bc4dbe 100644
--- a/proxmox-notify/src/api_types/matcher/mod.rs
+++ b/proxmox-notify/src/api_types/matcher/mod.rs
@@ -9,8 +9,9 @@ use proxmox_api_macro::api;
 use proxmox_schema::Updater;
 use proxmox_schema::api_types::COMMENT_SCHEMA;
 
+use crate::api_types::Origin;
 use crate::schema::ENTITY_NAME_SCHEMA;
-use crate::{Error, Notification, Origin};
+use crate::{Error, Notification};
 
 pub mod calendar;
 pub mod expression;
diff --git a/proxmox-notify/src/api_types/mod.rs b/proxmox-notify/src/api_types/mod.rs
index 443dea336..1e2509f19 100644
--- a/proxmox-notify/src/api_types/mod.rs
+++ b/proxmox-notify/src/api_types/mod.rs
@@ -5,6 +5,10 @@
 //!   - the generic target listing
 //!   - send receipts.
 
+use serde::{Deserialize, Serialize};
+
+use proxmox_schema::api;
+
 mod gotify;
 pub use gotify::*;
 
@@ -19,3 +23,16 @@ pub use smtp::*;
 
 mod matcher;
 pub use matcher::*;
+
+#[api]
+#[derive(Clone, Debug, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd)]
+#[serde(rename_all = "kebab-case")]
+/// The origin of a notification configuration entry.
+pub enum Origin {
+    /// User-created config entry
+    UserCreated,
+    /// Config entry provided by the system
+    Builtin,
+    /// Config entry provided by the system, but modified by the user.
+    ModifiedBuiltin,
+}
diff --git a/proxmox-notify/src/api_types/sendmail.rs b/proxmox-notify/src/api_types/sendmail.rs
index 921970265..c3437bc1f 100644
--- a/proxmox-notify/src/api_types/sendmail.rs
+++ b/proxmox-notify/src/api_types/sendmail.rs
@@ -2,10 +2,8 @@ use serde::{Deserialize, Serialize};
 
 use proxmox_schema::{Updater, api, api_types::COMMENT_SCHEMA};
 
-use crate::{
-    Origin,
-    schema::{EMAIL_SCHEMA, ENTITY_NAME_SCHEMA, USER_SCHEMA},
-};
+use crate::api_types::Origin;
+use crate::schema::{EMAIL_SCHEMA, ENTITY_NAME_SCHEMA, USER_SCHEMA};
 
 pub const SENDMAIL_TYPENAME: &str = "sendmail";
 
diff --git a/proxmox-notify/src/api_types/smtp.rs b/proxmox-notify/src/api_types/smtp.rs
index 9ab26700f..653c7a50f 100644
--- a/proxmox-notify/src/api_types/smtp.rs
+++ b/proxmox-notify/src/api_types/smtp.rs
@@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
 
 use proxmox_schema::{Updater, api, api_types::COMMENT_SCHEMA};
 
-use crate::Origin;
+use crate::api_types::Origin;
 use crate::schema::{EMAIL_SCHEMA, ENTITY_NAME_SCHEMA, USER_SCHEMA};
 
 pub const SMTP_TYPENAME: &str = "smtp";
diff --git a/proxmox-notify/src/api_types/webhook.rs b/proxmox-notify/src/api_types/webhook.rs
index 7d51f0470..c556d1b3f 100644
--- a/proxmox-notify/src/api_types/webhook.rs
+++ b/proxmox-notify/src/api_types/webhook.rs
@@ -4,7 +4,10 @@ use proxmox_schema::{
 };
 use serde::{Deserialize, Serialize};
 
-use crate::{Error, Origin, schema::ENTITY_NAME_SCHEMA};
+use crate::Error;
+use crate::api_types::Origin;
+
+use crate::schema::ENTITY_NAME_SCHEMA;
 
 /// This will be used as a section type in the public/private configuration file.
 pub const WEBHOOK_TYPENAME: &str = "webhook";
diff --git a/proxmox-notify/src/lib.rs b/proxmox-notify/src/lib.rs
index 2061d9150..8f0b962e7 100644
--- a/proxmox-notify/src/lib.rs
+++ b/proxmox-notify/src/lib.rs
@@ -1,9 +1,7 @@
 #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
 #![deny(unsafe_code)]
 
-use std::collections::HashMap;
-use std::fmt::Display;
-use std::str::FromStr;
+use std::{collections::HashMap, fmt::Display, str::FromStr};
 
 use serde::{Deserialize, Serialize};
 use serde_json::Value;
@@ -78,19 +76,6 @@ impl FromStr for Severity {
     }
 }
 
-#[api()]
-#[derive(Clone, Debug, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd)]
-#[serde(rename_all = "kebab-case")]
-/// The origin of a notification configuration entry.
-pub enum Origin {
-    /// User-created config entry
-    UserCreated,
-    /// Config entry provided by the system
-    Builtin,
-    /// Config entry provided by the system, but modified by the user.
-    ModifiedBuiltin,
-}
-
 #[derive(Debug, Clone, Serialize, Deserialize)]
 #[serde(rename_all = "kebab-case")]
 pub enum Content {
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 13/63] notify: move Target type to api_types module
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (11 preceding siblings ...)
  2026-11-18  9:42 ` [PATCH proxmox v2 12/63] notify: move Origin type to api_types module Lukas Wagner
@ 2026-11-18  9:42 ` Lukas Wagner
  2026-11-18  9:42 ` [PATCH proxmox v2 14/63] notify: move Config to config module Lukas Wagner
                   ` (50 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:42 UTC (permalink / raw)
  To: pve-devel

Since it is a serializable API type, all fields were made public as
well.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/api/mod.rs       | 38 +----------------------------
 proxmox-notify/src/api_types/mod.rs | 35 ++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 37 deletions(-)

diff --git a/proxmox-notify/src/api/mod.rs b/proxmox-notify/src/api/mod.rs
index c7288ae15..d93cb8353 100644
--- a/proxmox-notify/src/api/mod.rs
+++ b/proxmox-notify/src/api/mod.rs
@@ -4,10 +4,9 @@ use serde::{Deserialize, Serialize};
 
 use proxmox_config_digest::ConfigDigest;
 use proxmox_http_error::HttpError;
-use proxmox_schema::api;
 
 use crate::Config;
-use crate::api_types::Origin;
+use crate::api_types::{EndpointType, Origin, Target};
 
 pub mod common;
 pub mod gotify;
@@ -40,41 +39,6 @@ macro_rules! http_bail {
 pub use http_bail;
 pub use http_err;
 
-#[api]
-#[derive(Clone, Debug, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd)]
-#[serde(rename_all = "kebab-case")]
-/// Type of the endpoint.
-pub enum EndpointType {
-    /// Sendmail endpoint
-    Sendmail,
-    /// SMTP endpoint
-    Smtp,
-    /// Gotify endpoint
-    Gotify,
-    /// Webhook endpoint
-    Webhook,
-}
-
-#[api]
-#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd)]
-#[serde(rename_all = "kebab-case")]
-/// Target information
-pub struct Target {
-    /// Name of the endpoint
-    name: String,
-    /// Origin of the endpoint
-    origin: Origin,
-    /// Type of the endpoint
-    #[serde(rename = "type")]
-    endpoint_type: EndpointType,
-    /// Target is disabled
-    #[serde(skip_serializing_if = "Option::is_none")]
-    disable: Option<bool>,
-    /// Comment
-    #[serde(skip_serializing_if = "Option::is_none")]
-    comment: Option<String>,
-}
-
 /// Get a list of all notification targets.
 pub fn get_targets(config: &Config) -> Result<Vec<Target>, HttpError> {
     let mut targets = Vec::new();
diff --git a/proxmox-notify/src/api_types/mod.rs b/proxmox-notify/src/api_types/mod.rs
index 1e2509f19..a72ddbc16 100644
--- a/proxmox-notify/src/api_types/mod.rs
+++ b/proxmox-notify/src/api_types/mod.rs
@@ -36,3 +36,38 @@ pub enum Origin {
     /// Config entry provided by the system, but modified by the user.
     ModifiedBuiltin,
 }
+
+#[api]
+#[derive(Clone, Debug, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd)]
+#[serde(rename_all = "kebab-case")]
+/// Type of the endpoint.
+pub enum EndpointType {
+    /// Sendmail endpoint
+    Sendmail,
+    /// SMTP endpoint
+    Smtp,
+    /// Gotify endpoint
+    Gotify,
+    /// Webhook endpoint
+    Webhook,
+}
+
+#[api]
+#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd)]
+#[serde(rename_all = "kebab-case")]
+/// Target information
+pub struct Target {
+    /// Name of the endpoint
+    pub name: String,
+    /// Origin of the endpoint
+    pub origin: Origin,
+    /// Type of the endpoint
+    #[serde(rename = "type")]
+    pub endpoint_type: EndpointType,
+    /// Target is disabled
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub disable: Option<bool>,
+    /// Comment
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub comment: Option<String>,
+}
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 14/63] notify: move Config to config module
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (12 preceding siblings ...)
  2026-11-18  9:42 ` [PATCH proxmox v2 13/63] notify: move Target " Lukas Wagner
@ 2026-11-18  9:42 ` Lukas Wagner
  2026-11-18  9:42 ` [PATCH proxmox v2 15/63] notify: move Notification and sub-types to `notification` module Lukas Wagner
                   ` (49 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:42 UTC (permalink / raw)
  To: pve-devel

Another step in cleaning up lib.rs.

Took the opportunity to make `digest` a private field and add a new
getter `digest`.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/api/gotify.rs   |   2 +-
 proxmox-notify/src/api/matcher.rs  |  12 ++--
 proxmox-notify/src/api/sendmail.rs |   2 +-
 proxmox-notify/src/api/smtp.rs     |   2 +-
 proxmox-notify/src/api/webhook.rs  |   2 +-
 proxmox-notify/src/config.rs       | 103 +++++++++++++++++++++++++++-
 proxmox-notify/src/lib.rs          | 106 +----------------------------
 7 files changed, 113 insertions(+), 116 deletions(-)

diff --git a/proxmox-notify/src/api/gotify.rs b/proxmox-notify/src/api/gotify.rs
index fc56d250b..e0f7cf16b 100644
--- a/proxmox-notify/src/api/gotify.rs
+++ b/proxmox-notify/src/api/gotify.rs
@@ -234,7 +234,7 @@ mod tests {
         let mut config = empty_config();
         add_default_gotify_endpoint(&mut config)?;
 
-        let digest = config.digest.clone();
+        let digest = config.digest().clone();
 
         update_endpoint(
             &mut config,
diff --git a/proxmox-notify/src/api/matcher.rs b/proxmox-notify/src/api/matcher.rs
index 1994cb65c..7df30c083 100644
--- a/proxmox-notify/src/api/matcher.rs
+++ b/proxmox-notify/src/api/matcher.rs
@@ -270,7 +270,7 @@ matcher: matcher2
 
         let mut config = config_with_two_matchers();
 
-        let digest = config.digest.clone();
+        let digest = config.digest().clone();
 
         update_matcher(
             &mut config,
@@ -327,7 +327,7 @@ matcher: matcher2
     fn test_matcher_update() -> Result<(), HttpError> {
         let mut config = config_with_two_matchers();
 
-        let digest = config.digest.clone();
+        let digest = config.digest().clone();
 
         update_matcher(
             &mut config,
@@ -382,7 +382,7 @@ matcher: matcher2
     #[cfg(feature = "legacy-matchers")]
     fn test_update_matcher_mutually_exclusive_with_expression() -> Result<(), HttpError> {
         let mut config = config_with_two_matchers();
-        let digest = config.digest.clone();
+        let digest = config.digest().clone();
 
         let proto = MatcherConfigUpdater {
             expression: Some(valid_expression_string()),
@@ -416,7 +416,7 @@ matcher: matcher2
     #[test]
     fn test_update_invalid_expression() -> Result<(), HttpError> {
         let mut config = config_with_two_matchers();
-        let digest = config.digest.clone();
+        let digest = config.digest().clone();
 
         assert!(
             update_matcher(
@@ -447,7 +447,7 @@ matcher: matcher2
     #[test]
     fn test_update_minifies_pretty_printed_expression() -> Result<(), HttpError> {
         let mut config = config_with_two_matchers();
-        let digest = config.digest.clone();
+        let digest = config.digest().clone();
 
         let expr = nested_expression();
         let pretty = serde_json::to_string_pretty(&expr).unwrap();
@@ -476,7 +476,7 @@ matcher: matcher2
     #[test]
     fn test_update_normalizes_expression_with_extra_whitespace() -> Result<(), HttpError> {
         let mut config = config_with_two_matchers();
-        let digest = config.digest.clone();
+        let digest = config.digest().clone();
 
         // Same expression as `nested_expression`, but handwritten, with all sorts of
         // odd whitespace characters.
diff --git a/proxmox-notify/src/api/sendmail.rs b/proxmox-notify/src/api/sendmail.rs
index aecc69b38..cff63b806 100644
--- a/proxmox-notify/src/api/sendmail.rs
+++ b/proxmox-notify/src/api/sendmail.rs
@@ -230,7 +230,7 @@ pub mod tests {
         let mut config = empty_config();
         add_sendmail_endpoint_for_test(&mut config, "sendmail-endpoint")?;
 
-        let digest = config.digest.clone();
+        let digest = config.digest().clone();
 
         update_endpoint(
             &mut config,
diff --git a/proxmox-notify/src/api/smtp.rs b/proxmox-notify/src/api/smtp.rs
index f36a51e8c..ceae77df3 100644
--- a/proxmox-notify/src/api/smtp.rs
+++ b/proxmox-notify/src/api/smtp.rs
@@ -289,7 +289,7 @@ pub mod tests {
         let mut config = empty_config();
         add_smtp_endpoint_for_test(&mut config, "smtp-endpoint")?;
 
-        let digest = config.digest.clone();
+        let digest = config.digest().clone();
 
         update_endpoint(
             &mut config,
diff --git a/proxmox-notify/src/api/webhook.rs b/proxmox-notify/src/api/webhook.rs
index 8755eb291..7266faca6 100644
--- a/proxmox-notify/src/api/webhook.rs
+++ b/proxmox-notify/src/api/webhook.rs
@@ -351,7 +351,7 @@ mod tests {
         let mut config = empty_config();
         add_default_webhook_endpoint(&mut config)?;
 
-        let digest = config.digest.clone();
+        let digest = config.digest().clone();
 
         update_endpoint(
             &mut config,
diff --git a/proxmox-notify/src/config.rs b/proxmox-notify/src/config.rs
index bf1469160..59da68c5e 100644
--- a/proxmox-notify/src/config.rs
+++ b/proxmox-notify/src/config.rs
@@ -3,14 +3,16 @@ use std::sync::OnceLock;
 use proxmox_config_digest::ConfigDigest;
 use proxmox_schema::{ApiType, ObjectSchema};
 use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin};
+use serde_json::Value;
+use tracing::error;
 
-use crate::Error;
 use crate::api_types::{
     GOTIFY_TYPENAME, GotifyConfig, GotifyPrivateConfig, MATCHER_TYPENAME, MatcherConfig,
     SENDMAIL_TYPENAME, SMTP_TYPENAME, SendmailConfig, SmtpConfig, SmtpPrivateConfig,
     WEBHOOK_TYPENAME, WebhookConfig, WebhookPrivateConfig,
 };
 use crate::schema::BACKEND_NAME_SCHEMA;
+use crate::{Context, Error};
 
 /// Section config schema for the public config file.
 pub fn config_parser() -> &'static SectionConfig {
@@ -126,3 +128,102 @@ pub fn write_private(config: &SectionConfigData) -> Result<String, Error> {
         .write("priv/notifications.cfg", config)
         .map_err(Error::config_serialization)
 }
+
+/// Notification configuration
+#[derive(Debug, Clone)]
+pub struct Config {
+    pub(crate) config: SectionConfigData,
+    pub(crate) private_config: SectionConfigData,
+    digest: ConfigDigest,
+}
+
+impl Config {
+    /// Parse raw config
+    pub fn new(
+        context: &Context,
+        raw_config: &str,
+        raw_private_config: &str,
+    ) -> Result<Self, Error> {
+        let (mut config, digest) = config(raw_config)?;
+        let (private_config, _) = private_config(raw_private_config)?;
+
+        let default_config = context.default_config();
+
+        let builtin_config = config_parser()
+            .parse("<builtin>", default_config)
+            .map_err(|err| Error::ConfigDeserialization(err.into()))?;
+
+        for (key, (builtin_typename, builtin_value)) in &builtin_config.sections {
+            if let Some((typename, value)) = config.sections.get_mut(key) {
+                if builtin_typename == typename && value == builtin_value {
+                    // Entry is built-in and the config entry section in notifications.cfg
+                    // is exactly the same.
+                    if let Some(obj) = value.as_object_mut() {
+                        obj.insert("origin".to_string(), Value::String("builtin".into()));
+                    } else {
+                        error!("section config entry is not an object. This should not happen");
+                    }
+                } else {
+                    // Entry is built-in, but it has been modified by the user.
+                    if let Some(obj) = value.as_object_mut() {
+                        obj.insert(
+                            "origin".to_string(),
+                            Value::String("modified-builtin".into()),
+                        );
+                    } else {
+                        error!("section config entry is not an object. This should not happen");
+                    }
+                }
+            } else {
+                let mut val = builtin_value.clone();
+
+                if let Some(obj) = val.as_object_mut() {
+                    obj.insert("origin".to_string(), Value::String("builtin".into()));
+                } else {
+                    error!("section config entry is not an object. This should not happen");
+                }
+                config
+                    .set_data(key, builtin_typename, val)
+                    .map_err(|err| Error::ConfigDeserialization(err.into()))?;
+            }
+        }
+
+        for (_, (_, value)) in config.sections.iter_mut() {
+            if let Some(obj) = value.as_object_mut() {
+                if obj.get("origin").is_none() {
+                    obj.insert("origin".to_string(), Value::String("user-created".into()));
+                }
+            }
+        }
+
+        Ok(Self {
+            config,
+            digest,
+            private_config,
+        })
+    }
+
+    /// Serialize config
+    pub fn write(&self) -> Result<(String, String), Error> {
+        let mut c = self.config.clone();
+        for (_, (_, value)) in c.sections.iter_mut() {
+            // Remove 'origin' parameter, we do not want it in our
+            // config fields
+            // TODO: Check if there is a better way for this, maybe a
+            // separate type for API responses?
+            if let Some(obj) = value.as_object_mut() {
+                obj.remove("origin");
+            } else {
+                error!("section config entry is not an object. This should not happen");
+            }
+        }
+
+        Ok((write(&c)?, write_private(&self.private_config)?))
+    }
+
+    /// Returns the SHA256 digest of the configuration.
+    /// The digest is only computed once when the configuration deserialized.
+    pub fn digest(&self) -> &ConfigDigest {
+        &self.digest
+    }
+}
diff --git a/proxmox-notify/src/lib.rs b/proxmox-notify/src/lib.rs
index 8f0b962e7..4407ae80d 100644
--- a/proxmox-notify/src/lib.rs
+++ b/proxmox-notify/src/lib.rs
@@ -5,11 +5,8 @@ use std::{collections::HashMap, fmt::Display, str::FromStr};
 
 use serde::{Deserialize, Serialize};
 use serde_json::Value;
-use tracing::error;
 
-use proxmox_config_digest::ConfigDigest;
 use proxmox_schema::api;
-use proxmox_section_config::SectionConfigData;
 use proxmox_uuid::Uuid;
 
 #[cfg(feature = "api-impl")]
@@ -30,6 +27,7 @@ pub mod api_types;
 mod error;
 pub use error::Error;
 
+pub use config::Config;
 pub use context::Context;
 pub use context::ContextImpl;
 
@@ -187,105 +185,3 @@ impl Notification {
         self.metadata.timestamp
     }
 }
-
-/// Notification configuration
-#[derive(Debug, Clone)]
-pub struct Config {
-    config: SectionConfigData,
-    private_config: SectionConfigData,
-    digest: ConfigDigest,
-}
-
-impl Config {
-    /// Parse raw config
-    pub fn new(
-        context: &Context,
-        raw_config: &str,
-        raw_private_config: &str,
-    ) -> Result<Self, Error> {
-        let (mut config, digest) = config::config(raw_config)?;
-        let (private_config, _) = config::private_config(raw_private_config)?;
-
-        let default_config = context.default_config();
-
-        let builtin_config = config::config_parser()
-            .parse("<builtin>", default_config)
-            .map_err(|err| Error::ConfigDeserialization(err.into()))?;
-
-        for (key, (builtin_typename, builtin_value)) in &builtin_config.sections {
-            if let Some((typename, value)) = config.sections.get_mut(key) {
-                if builtin_typename == typename && value == builtin_value {
-                    // Entry is built-in and the config entry section in notifications.cfg
-                    // is exactly the same.
-                    if let Some(obj) = value.as_object_mut() {
-                        obj.insert("origin".to_string(), Value::String("builtin".into()));
-                    } else {
-                        error!("section config entry is not an object. This should not happen");
-                    }
-                } else {
-                    // Entry is built-in, but it has been modified by the user.
-                    if let Some(obj) = value.as_object_mut() {
-                        obj.insert(
-                            "origin".to_string(),
-                            Value::String("modified-builtin".into()),
-                        );
-                    } else {
-                        error!("section config entry is not an object. This should not happen");
-                    }
-                }
-            } else {
-                let mut val = builtin_value.clone();
-
-                if let Some(obj) = val.as_object_mut() {
-                    obj.insert("origin".to_string(), Value::String("builtin".into()));
-                } else {
-                    error!("section config entry is not an object. This should not happen");
-                }
-                config
-                    .set_data(key, builtin_typename, val)
-                    .map_err(|err| Error::ConfigDeserialization(err.into()))?;
-            }
-        }
-
-        for (_, (_, value)) in config.sections.iter_mut() {
-            if let Some(obj) = value.as_object_mut() {
-                if obj.get("origin").is_none() {
-                    obj.insert("origin".to_string(), Value::String("user-created".into()));
-                }
-            }
-        }
-
-        Ok(Self {
-            config,
-            digest,
-            private_config,
-        })
-    }
-
-    /// Serialize config
-    pub fn write(&self) -> Result<(String, String), Error> {
-        let mut c = self.config.clone();
-        for (_, (_, value)) in c.sections.iter_mut() {
-            // Remove 'origin' parameter, we do not want it in our
-            // config fields
-            // TODO: Check if there is a better way for this, maybe a
-            // separate type for API responses?
-            if let Some(obj) = value.as_object_mut() {
-                obj.remove("origin");
-            } else {
-                error!("section config entry is not an object. This should not happen");
-            }
-        }
-
-        Ok((
-            config::write(&c)?,
-            config::write_private(&self.private_config)?,
-        ))
-    }
-
-    /// Returns the SHA256 digest of the configuration.
-    /// The digest is only computed once when the configuration deserialized.
-    pub fn digest(&self) -> &ConfigDigest {
-        &self.digest
-    }
-}
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 15/63] notify: move Notification and sub-types to `notification` module
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (13 preceding siblings ...)
  2026-11-18  9:42 ` [PATCH proxmox v2 14/63] notify: move Config to config module Lukas Wagner
@ 2026-11-18  9:42 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 16/63] notify: move schema module to api_types Lukas Wagner
                   ` (48 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:42 UTC (permalink / raw)
  To: pve-devel

No functional changes.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/lib.rs          | 164 +----------------------------
 proxmox-notify/src/notification.rs | 164 +++++++++++++++++++++++++++++
 2 files changed, 166 insertions(+), 162 deletions(-)
 create mode 100644 proxmox-notify/src/notification.rs

diff --git a/proxmox-notify/src/lib.rs b/proxmox-notify/src/lib.rs
index 4407ae80d..f0d0f3866 100644
--- a/proxmox-notify/src/lib.rs
+++ b/proxmox-notify/src/lib.rs
@@ -1,14 +1,6 @@
 #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
 #![deny(unsafe_code)]
 
-use std::{collections::HashMap, fmt::Display, str::FromStr};
-
-use serde::{Deserialize, Serialize};
-use serde_json::Value;
-
-use proxmox_schema::api;
-use proxmox_uuid::Uuid;
-
 #[cfg(feature = "api-impl")]
 pub mod api;
 
@@ -31,157 +23,5 @@ pub use config::Config;
 pub use context::Context;
 pub use context::ContextImpl;
 
-#[api()]
-#[derive(Clone, Debug, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd)]
-#[serde(rename_all = "kebab-case")]
-/// Severity of a notification
-pub enum Severity {
-    /// General information
-    Info,
-    /// A noteworthy event
-    Notice,
-    /// Warning
-    Warning,
-    /// Error
-    Error,
-    /// Unknown severity (e.g. forwarded system mails)
-    Unknown,
-}
-
-impl Display for Severity {
-    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
-        match self {
-            Severity::Info => f.write_str("info"),
-            Severity::Notice => f.write_str("notice"),
-            Severity::Warning => f.write_str("warning"),
-            Severity::Error => f.write_str("error"),
-            Severity::Unknown => f.write_str("unknown"),
-        }
-    }
-}
-
-impl FromStr for Severity {
-    type Err = Error;
-    fn from_str(s: &str) -> Result<Self, Self::Err> {
-        match s {
-            "info" => Ok(Self::Info),
-            "notice" => Ok(Self::Notice),
-            "warning" => Ok(Self::Warning),
-            "error" => Ok(Self::Error),
-            "unknown" => Ok(Self::Unknown),
-            _ => Err(Error::invalid_config(format!("invalid severity {s}"))),
-        }
-    }
-}
-
-#[derive(Debug, Clone, Serialize, Deserialize)]
-#[serde(rename_all = "kebab-case")]
-pub enum Content {
-    /// Title and body will be rendered as a template
-    #[serde(rename_all = "kebab-case")]
-    Template {
-        /// Name of the used template
-        template_name: String,
-        /// Data that can be used for template rendering.
-        data: Value,
-    },
-    #[cfg(feature = "mail-forwarder")]
-    #[serde(rename_all = "kebab-case")]
-    ForwardedMail {
-        /// Raw mail contents
-        raw: Vec<u8>,
-        /// Fallback title
-        title: String,
-        /// Fallback body
-        body: String,
-        /// UID to use when calling sendmail
-        #[allow(dead_code)] // Unused in some feature flag permutations
-        uid: Option<u32>,
-    },
-}
-
-#[derive(Debug, Clone, Serialize, Deserialize)]
-#[serde(rename_all = "kebab-case")]
-pub struct Metadata {
-    /// Notification severity
-    severity: Severity,
-    /// Timestamp of the notification as a UNIX epoch
-    timestamp: i64,
-    /// Additional fields for additional key-value metadata
-    additional_fields: HashMap<String, String>,
-}
-
-#[derive(Debug, Clone, Serialize, Deserialize)]
-#[serde(rename_all = "kebab-case")]
-/// Notification which can be sent
-pub struct Notification {
-    /// Notification content
-    content: Content,
-    /// Metadata
-    metadata: Metadata,
-    /// Unique ID
-    id: Uuid,
-}
-
-impl Notification {
-    pub fn from_template<S: AsRef<str>>(
-        severity: Severity,
-        template_name: S,
-        template_data: Value,
-        fields: HashMap<String, String>,
-    ) -> Self {
-        Self {
-            metadata: Metadata {
-                severity,
-                additional_fields: fields,
-                timestamp: proxmox_time::epoch_i64(),
-            },
-            content: Content::Template {
-                template_name: template_name.as_ref().to_string(),
-                data: template_data,
-            },
-            id: Uuid::generate(),
-        }
-    }
-    #[cfg(feature = "mail-forwarder")]
-    pub fn new_forwarded_mail(raw_mail: &[u8], uid: Option<u32>) -> Result<Self, Error> {
-        let message = mail_parser::MessageParser::default()
-            .parse(raw_mail)
-            .ok_or_else(|| Error::invalid_forwarded_message("could not parse forwarded email"))?;
-
-        let title = message.subject().unwrap_or_default().into();
-        let body = message.body_text(0).unwrap_or_default().into();
-
-        let mut additional_fields = HashMap::new();
-        additional_fields.insert("hostname".into(), proxmox_sys::nodename().into());
-        additional_fields.insert("type".into(), "system-mail".into());
-
-        Ok(Self {
-            // Unfortunately we cannot reasonably infer the severity from the
-            // mail contents, so just set it to the highest for now so that
-            // it is not filtered out.
-            content: Content::ForwardedMail {
-                raw: raw_mail.into(),
-                title,
-                body,
-                uid,
-            },
-            metadata: Metadata {
-                severity: Severity::Unknown,
-                additional_fields,
-                timestamp: proxmox_time::epoch_i64(),
-            },
-            id: Uuid::generate(),
-        })
-    }
-
-    /// Return the unique ID of this notification.
-    pub fn id(&self) -> &Uuid {
-        &self.id
-    }
-
-    /// Return the notification's timestamp
-    pub fn timestamp(&self) -> i64 {
-        self.metadata.timestamp
-    }
-}
+mod notification;
+pub use notification::*;
diff --git a/proxmox-notify/src/notification.rs b/proxmox-notify/src/notification.rs
new file mode 100644
index 000000000..426a2259a
--- /dev/null
+++ b/proxmox-notify/src/notification.rs
@@ -0,0 +1,164 @@
+use std::{collections::HashMap, fmt::Display, str::FromStr};
+
+use serde::{Deserialize, Serialize};
+use serde_json::Value;
+
+use proxmox_schema::api;
+use proxmox_uuid::Uuid;
+
+use crate::Error;
+
+#[api]
+#[derive(Clone, Debug, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd)]
+#[serde(rename_all = "kebab-case")]
+/// Severity of a notification
+pub enum Severity {
+    /// General information
+    Info,
+    /// A noteworthy event
+    Notice,
+    /// Warning
+    Warning,
+    /// Error
+    Error,
+    /// Unknown severity (e.g. forwarded system mails)
+    Unknown,
+}
+
+impl Display for Severity {
+    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
+        match self {
+            Severity::Info => f.write_str("info"),
+            Severity::Notice => f.write_str("notice"),
+            Severity::Warning => f.write_str("warning"),
+            Severity::Error => f.write_str("error"),
+            Severity::Unknown => f.write_str("unknown"),
+        }
+    }
+}
+
+impl FromStr for Severity {
+    type Err = Error;
+    fn from_str(s: &str) -> Result<Self, Self::Err> {
+        match s {
+            "info" => Ok(Self::Info),
+            "notice" => Ok(Self::Notice),
+            "warning" => Ok(Self::Warning),
+            "error" => Ok(Self::Error),
+            "unknown" => Ok(Self::Unknown),
+            _ => Err(Error::invalid_config(format!("invalid severity {s}"))),
+        }
+    }
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case")]
+pub enum Content {
+    /// Title and body will be rendered as a template
+    #[serde(rename_all = "kebab-case")]
+    Template {
+        /// Name of the used template
+        template_name: String,
+        /// Data that can be used for template rendering.
+        data: Value,
+    },
+    #[cfg(feature = "mail-forwarder")]
+    #[serde(rename_all = "kebab-case")]
+    ForwardedMail {
+        /// Raw mail contents
+        raw: Vec<u8>,
+        /// Fallback title
+        title: String,
+        /// Fallback body
+        body: String,
+        /// UID to use when calling sendmail
+        #[allow(dead_code)] // Unused in some feature flag permutations
+        uid: Option<u32>,
+    },
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case")]
+pub struct Metadata {
+    /// Notification severity
+    pub(crate) severity: Severity,
+    /// Timestamp of the notification as a UNIX epoch
+    pub(crate) timestamp: i64,
+    /// Additional fields for additional key-value metadata
+    pub(crate) additional_fields: HashMap<String, String>,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case")]
+/// Notification which can be sent
+pub struct Notification {
+    /// Notification content
+    pub(crate) content: Content,
+    /// Metadata
+    pub(crate) metadata: Metadata,
+    /// Unique ID
+    pub(crate) id: Uuid,
+}
+
+impl Notification {
+    pub fn from_template<S: AsRef<str>>(
+        severity: Severity,
+        template_name: S,
+        template_data: Value,
+        fields: HashMap<String, String>,
+    ) -> Self {
+        Self {
+            metadata: Metadata {
+                severity,
+                additional_fields: fields,
+                timestamp: proxmox_time::epoch_i64(),
+            },
+            content: Content::Template {
+                template_name: template_name.as_ref().to_string(),
+                data: template_data,
+            },
+            id: Uuid::generate(),
+        }
+    }
+    #[cfg(feature = "mail-forwarder")]
+    pub fn new_forwarded_mail(raw_mail: &[u8], uid: Option<u32>) -> Result<Self, Error> {
+        let message = mail_parser::MessageParser::default()
+            .parse(raw_mail)
+            .ok_or_else(|| Error::invalid_forwarded_message("could not parse forwarded email"))?;
+
+        let title = message.subject().unwrap_or_default().into();
+        let body = message.body_text(0).unwrap_or_default().into();
+
+        let mut additional_fields = HashMap::new();
+        additional_fields.insert("hostname".into(), proxmox_sys::nodename().into());
+        additional_fields.insert("type".into(), "system-mail".into());
+
+        Ok(Self {
+            // Unfortunately we cannot reasonably infer the severity from the
+            // mail contents, so just set it to the highest for now so that
+            // it is not filtered out.
+            content: Content::ForwardedMail {
+                raw: raw_mail.into(),
+                title,
+                body,
+                uid,
+            },
+            metadata: Metadata {
+                severity: Severity::Unknown,
+                additional_fields,
+                timestamp: proxmox_time::epoch_i64(),
+            },
+            id: Uuid::generate(),
+        })
+    }
+
+    /// Return the unique ID of this notification.
+    pub fn id(&self) -> &Uuid {
+        &self.id
+    }
+
+    /// Return the notification's timestamp
+    pub fn timestamp(&self) -> i64 {
+        self.metadata.timestamp
+    }
+}
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 16/63] notify: move schema module to api_types
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (14 preceding siblings ...)
  2026-11-18  9:42 ` [PATCH proxmox v2 15/63] notify: move Notification and sub-types to `notification` module Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 17/63] notify: move check_matches from api_types::matcher to send::Bus Lukas Wagner
                   ` (47 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

No functional changes.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/api_types/gotify.rs       | 3 ++-
 proxmox-notify/src/api_types/matcher/mod.rs  | 3 ++-
 proxmox-notify/src/api_types/mod.rs          | 3 +++
 proxmox-notify/src/{ => api_types}/schema.rs | 0
 proxmox-notify/src/api_types/sendmail.rs     | 3 ++-
 proxmox-notify/src/api_types/smtp.rs         | 3 ++-
 proxmox-notify/src/api_types/webhook.rs      | 2 +-
 proxmox-notify/src/config.rs                 | 5 ++---
 proxmox-notify/src/lib.rs                    | 1 -
 9 files changed, 14 insertions(+), 9 deletions(-)
 rename proxmox-notify/src/{ => api_types}/schema.rs (100%)

diff --git a/proxmox-notify/src/api_types/gotify.rs b/proxmox-notify/src/api_types/gotify.rs
index 433a9fae3..334920145 100644
--- a/proxmox-notify/src/api_types/gotify.rs
+++ b/proxmox-notify/src/api_types/gotify.rs
@@ -3,7 +3,8 @@ use serde::{Deserialize, Serialize};
 use proxmox_schema::{Updater, api, api_types::COMMENT_SCHEMA};
 
 use crate::api_types::Origin;
-use crate::schema::ENTITY_NAME_SCHEMA;
+
+use super::schema::ENTITY_NAME_SCHEMA;
 
 pub const GOTIFY_TYPENAME: &str = "gotify";
 
diff --git a/proxmox-notify/src/api_types/matcher/mod.rs b/proxmox-notify/src/api_types/matcher/mod.rs
index 3e8bc4dbe..c88ae09cd 100644
--- a/proxmox-notify/src/api_types/matcher/mod.rs
+++ b/proxmox-notify/src/api_types/matcher/mod.rs
@@ -10,9 +10,10 @@ use proxmox_schema::Updater;
 use proxmox_schema::api_types::COMMENT_SCHEMA;
 
 use crate::api_types::Origin;
-use crate::schema::ENTITY_NAME_SCHEMA;
 use crate::{Error, Notification};
 
+use super::schema::ENTITY_NAME_SCHEMA;
+
 pub mod calendar;
 pub mod expression;
 pub mod field;
diff --git a/proxmox-notify/src/api_types/mod.rs b/proxmox-notify/src/api_types/mod.rs
index a72ddbc16..f3b381a8b 100644
--- a/proxmox-notify/src/api_types/mod.rs
+++ b/proxmox-notify/src/api_types/mod.rs
@@ -24,6 +24,9 @@ pub use smtp::*;
 mod matcher;
 pub use matcher::*;
 
+mod schema;
+pub use schema::*;
+
 #[api]
 #[derive(Clone, Debug, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd)]
 #[serde(rename_all = "kebab-case")]
diff --git a/proxmox-notify/src/schema.rs b/proxmox-notify/src/api_types/schema.rs
similarity index 100%
rename from proxmox-notify/src/schema.rs
rename to proxmox-notify/src/api_types/schema.rs
diff --git a/proxmox-notify/src/api_types/sendmail.rs b/proxmox-notify/src/api_types/sendmail.rs
index c3437bc1f..bb843fbfa 100644
--- a/proxmox-notify/src/api_types/sendmail.rs
+++ b/proxmox-notify/src/api_types/sendmail.rs
@@ -3,7 +3,8 @@ use serde::{Deserialize, Serialize};
 use proxmox_schema::{Updater, api, api_types::COMMENT_SCHEMA};
 
 use crate::api_types::Origin;
-use crate::schema::{EMAIL_SCHEMA, ENTITY_NAME_SCHEMA, USER_SCHEMA};
+
+use super::schema::{EMAIL_SCHEMA, ENTITY_NAME_SCHEMA, USER_SCHEMA};
 
 pub const SENDMAIL_TYPENAME: &str = "sendmail";
 
diff --git a/proxmox-notify/src/api_types/smtp.rs b/proxmox-notify/src/api_types/smtp.rs
index 653c7a50f..5cebbf8ad 100644
--- a/proxmox-notify/src/api_types/smtp.rs
+++ b/proxmox-notify/src/api_types/smtp.rs
@@ -3,7 +3,8 @@ use serde::{Deserialize, Serialize};
 use proxmox_schema::{Updater, api, api_types::COMMENT_SCHEMA};
 
 use crate::api_types::Origin;
-use crate::schema::{EMAIL_SCHEMA, ENTITY_NAME_SCHEMA, USER_SCHEMA};
+
+use super::schema::{EMAIL_SCHEMA, ENTITY_NAME_SCHEMA, USER_SCHEMA};
 
 pub const SMTP_TYPENAME: &str = "smtp";
 
diff --git a/proxmox-notify/src/api_types/webhook.rs b/proxmox-notify/src/api_types/webhook.rs
index c556d1b3f..4a2430cec 100644
--- a/proxmox-notify/src/api_types/webhook.rs
+++ b/proxmox-notify/src/api_types/webhook.rs
@@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
 use crate::Error;
 use crate::api_types::Origin;
 
-use crate::schema::ENTITY_NAME_SCHEMA;
+use super::schema::ENTITY_NAME_SCHEMA;
 
 /// This will be used as a section type in the public/private configuration file.
 pub const WEBHOOK_TYPENAME: &str = "webhook";
diff --git a/proxmox-notify/src/config.rs b/proxmox-notify/src/config.rs
index 59da68c5e..fcbf568f4 100644
--- a/proxmox-notify/src/config.rs
+++ b/proxmox-notify/src/config.rs
@@ -7,11 +7,10 @@ use serde_json::Value;
 use tracing::error;
 
 use crate::api_types::{
-    GOTIFY_TYPENAME, GotifyConfig, GotifyPrivateConfig, MATCHER_TYPENAME, MatcherConfig,
-    SENDMAIL_TYPENAME, SMTP_TYPENAME, SendmailConfig, SmtpConfig, SmtpPrivateConfig,
+    BACKEND_NAME_SCHEMA, GOTIFY_TYPENAME, GotifyConfig, GotifyPrivateConfig, MATCHER_TYPENAME,
+    MatcherConfig, SENDMAIL_TYPENAME, SMTP_TYPENAME, SendmailConfig, SmtpConfig, SmtpPrivateConfig,
     WEBHOOK_TYPENAME, WebhookConfig, WebhookPrivateConfig,
 };
-use crate::schema::BACKEND_NAME_SCHEMA;
 use crate::{Context, Error};
 
 /// Section config schema for the public config file.
diff --git a/proxmox-notify/src/lib.rs b/proxmox-notify/src/lib.rs
index f0d0f3866..925465bf5 100644
--- a/proxmox-notify/src/lib.rs
+++ b/proxmox-notify/src/lib.rs
@@ -8,7 +8,6 @@ pub mod config;
 pub mod context;
 pub mod endpoints;
 pub mod renderer;
-pub mod schema;
 
 #[cfg(feature = "send-impl")]
 pub mod send;
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 17/63] notify: move check_matches from api_types::matcher to send::Bus
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (15 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 16/63] notify: move schema module to api_types Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 18/63] notify: move TemplateSource to context module Lukas Wagner
                   ` (46 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

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 <l.wagner@proxmox.com>
---
 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





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 18/63] notify: move TemplateSource to context module
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (16 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 17/63] notify: move check_matches from api_types::matcher to send::Bus Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 19/63] notify: config: cleanup helper names and visibility Lukas Wagner
                   ` (45 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

The type is mainly used for the context trait, and otherwise we have to
pull in the 'renderer' module if we only compile with the 'api-impl'
flag (since it pulls in context, which needs TemplateSource).

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/context/mod.rs  | 19 +++++++++++++++++--
 proxmox-notify/src/context/test.rs |  3 ++-
 proxmox-notify/src/renderer/mod.rs | 22 ++++------------------
 3 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/proxmox-notify/src/context/mod.rs b/proxmox-notify/src/context/mod.rs
index 71d94c6e3..fd55dca14 100644
--- a/proxmox-notify/src/context/mod.rs
+++ b/proxmox-notify/src/context/mod.rs
@@ -1,9 +1,8 @@
-use std::fmt::Debug;
+use std::fmt::{Debug, Display};
 use std::ops::Deref;
 use std::sync::Arc;
 
 use crate::error::BoxedError;
-use crate::renderer::TemplateSource;
 
 #[cfg(any(feature = "pve-context", feature = "pbs-context"))]
 pub mod common;
@@ -61,3 +60,19 @@ pub trait ContextImpl: Send + Sync + Debug {
         source: TemplateSource,
     ) -> Result<Option<String>, BoxedError>;
 }
+
+/// Choose between the provided `vendor` template or its by the user optionally created `override`
+#[derive(Copy, Clone)]
+pub enum TemplateSource {
+    Vendor,
+    Override,
+}
+
+impl Display for TemplateSource {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        match self {
+            TemplateSource::Vendor => f.write_str("vendor"),
+            TemplateSource::Override => f.write_str("override"),
+        }
+    }
+}
diff --git a/proxmox-notify/src/context/test.rs b/proxmox-notify/src/context/test.rs
index b959cb929..8296dbf62 100644
--- a/proxmox-notify/src/context/test.rs
+++ b/proxmox-notify/src/context/test.rs
@@ -1,7 +1,8 @@
 use crate::Context;
 use crate::context::ContextImpl;
 use crate::error::BoxedError;
-use crate::renderer::TemplateSource;
+
+use super::TemplateSource;
 
 #[derive(Debug)]
 pub(crate) struct TestContext;
diff --git a/proxmox-notify/src/renderer/mod.rs b/proxmox-notify/src/renderer/mod.rs
index da6279a1d..55282e204 100644
--- a/proxmox-notify/src/renderer/mod.rs
+++ b/proxmox-notify/src/renderer/mod.rs
@@ -1,6 +1,6 @@
 //! Module for rendering notification templates.
 
-use std::{fmt::Display, time::Duration};
+use std::time::Duration;
 
 use handlebars::Context as HandlebarsContext;
 use handlebars::{
@@ -13,7 +13,9 @@ use tracing::error;
 use proxmox_human_byte::HumanByte;
 use proxmox_time::TimeSpan;
 
-use crate::{Context, Error};
+use crate::Context;
+use crate::Error;
+use crate::context::TemplateSource;
 
 mod html;
 mod plaintext;
@@ -178,22 +180,6 @@ impl ValueRenderFunction {
     }
 }
 
-/// Choose between the provided `vendor` template or its by the user optionally created `override`
-#[derive(Copy, Clone)]
-pub enum TemplateSource {
-    Vendor,
-    Override,
-}
-
-impl Display for TemplateSource {
-    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        match self {
-            TemplateSource::Vendor => f.write_str("vendor"),
-            TemplateSource::Override => f.write_str("override"),
-        }
-    }
-}
-
 /// Available template types
 #[derive(Copy, Clone, PartialEq)]
 pub enum TemplateType {
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 19/63] notify: config: cleanup helper names and visibility
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (17 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 18/63] notify: move TemplateSource to context module Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 20/63] notify: config: rename section config parser/writer methods Lukas Wagner
                   ` (44 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

Given that Config now lives in the same module, we can lower the
visibility of these helpers.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/config.rs | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/proxmox-notify/src/config.rs b/proxmox-notify/src/config.rs
index fcbf568f4..f7055b9ff 100644
--- a/proxmox-notify/src/config.rs
+++ b/proxmox-notify/src/config.rs
@@ -98,7 +98,7 @@ fn private_config_init() -> SectionConfig {
     config
 }
 
-pub fn config(raw_config: &str) -> Result<(SectionConfigData, ConfigDigest), Error> {
+fn parse_config(raw_config: &str) -> Result<(SectionConfigData, ConfigDigest), Error> {
     let digest = ConfigDigest::from_slice(raw_config.as_bytes());
     let data = config_parser()
         .parse("notifications.cfg", raw_config)
@@ -107,7 +107,7 @@ pub fn config(raw_config: &str) -> Result<(SectionConfigData, ConfigDigest), Err
     Ok((data, digest))
 }
 
-pub fn private_config(raw_config: &str) -> Result<(SectionConfigData, ConfigDigest), Error> {
+fn parse_private_config(raw_config: &str) -> Result<(SectionConfigData, ConfigDigest), Error> {
     let digest = ConfigDigest::from_slice(raw_config.as_bytes());
     let data = private_config_parser()
         .parse("priv/notifications.cfg", raw_config)
@@ -116,13 +116,13 @@ pub fn private_config(raw_config: &str) -> Result<(SectionConfigData, ConfigDige
     Ok((data, digest))
 }
 
-pub fn write(config: &SectionConfigData) -> Result<String, Error> {
+fn write(config: &SectionConfigData) -> Result<String, Error> {
     config_parser()
         .write("notifications.cfg", config)
         .map_err(Error::config_serialization)
 }
 
-pub fn write_private(config: &SectionConfigData) -> Result<String, Error> {
+fn write_private(config: &SectionConfigData) -> Result<String, Error> {
     private_config_parser()
         .write("priv/notifications.cfg", config)
         .map_err(Error::config_serialization)
@@ -143,8 +143,8 @@ impl Config {
         raw_config: &str,
         raw_private_config: &str,
     ) -> Result<Self, Error> {
-        let (mut config, digest) = config(raw_config)?;
-        let (private_config, _) = private_config(raw_private_config)?;
+        let (mut config, digest) = parse_config(raw_config)?;
+        let (private_config, _) = parse_private_config(raw_private_config)?;
 
         let default_config = context.default_config();
 
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 20/63] notify: config: rename section config parser/writer methods
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (18 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 19/63] notify: config: cleanup helper names and visibility Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 21/63] notify: config: pass builtins explicitly when parsing section config Lukas Wagner
                   ` (43 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

`new` and `write` were a bit too generic, so they are renamed to
`parse_section_config` and `to_section_config`.

The original names were not a big issue, but since we are breaking the
public crate API anyway, we might as well improve naming where we can.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/api/matcher.rs | 9 +++++----
 proxmox-notify/src/api/mod.rs     | 2 +-
 proxmox-notify/src/config.rs      | 6 +++---
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/proxmox-notify/src/api/matcher.rs b/proxmox-notify/src/api/matcher.rs
index 7df30c083..65ceb1dc7 100644
--- a/proxmox-notify/src/api/matcher.rs
+++ b/proxmox-notify/src/api/matcher.rs
@@ -214,12 +214,12 @@ mod tests {
 
     fn empty_config() -> Config {
         let context = test_context();
-        Config::new(&context, "", "").unwrap()
+        Config::parse_section_config(&context, "", "").unwrap()
     }
 
     fn config_with_two_matchers() -> Config {
         let context = test_context();
-        Config::new(
+        Config::parse_section_config(
             &context,
             "
 sendmail: foo
@@ -501,9 +501,10 @@ matcher: matcher2
 
         // The normalized expression should stay the same after
         // a read/write cycle of the config
-        let (raw_config, raw_private_config) = config.write().unwrap();
+        let (raw_config, raw_private_config) = config.to_section_config().unwrap();
         let context = test_context();
-        let config = Config::new(&context, &raw_config, &raw_private_config).unwrap();
+        let config =
+            Config::parse_section_config(&context, &raw_config, &raw_private_config).unwrap();
         let matcher = get_matcher(&config, "matcher1")?;
 
         assert_eq!(matcher.expression, Some(stored));
diff --git a/proxmox-notify/src/api/mod.rs b/proxmox-notify/src/api/mod.rs
index d93cb8353..b70c32df8 100644
--- a/proxmox-notify/src/api/mod.rs
+++ b/proxmox-notify/src/api/mod.rs
@@ -226,7 +226,7 @@ mod test_helpers {
     #[allow(unused)]
     pub fn empty_config() -> Config {
         let context = test::test_context();
-        Config::new(&context, "", "").unwrap()
+        Config::parse_section_config(&context, "", "").unwrap()
     }
 }
 
diff --git a/proxmox-notify/src/config.rs b/proxmox-notify/src/config.rs
index f7055b9ff..8c7c84cc8 100644
--- a/proxmox-notify/src/config.rs
+++ b/proxmox-notify/src/config.rs
@@ -137,8 +137,8 @@ pub struct Config {
 }
 
 impl Config {
-    /// Parse raw config
-    pub fn new(
+    /// Parse notification configuration from section config format.
+    pub fn parse_section_config(
         context: &Context,
         raw_config: &str,
         raw_private_config: &str,
@@ -203,7 +203,7 @@ impl Config {
     }
 
     /// Serialize config
-    pub fn write(&self) -> Result<(String, String), Error> {
+    pub fn to_section_config(&self) -> Result<(String, String), Error> {
         let mut c = self.config.clone();
         for (_, (_, value)) in c.sections.iter_mut() {
             // Remove 'origin' parameter, we do not want it in our
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 21/63] notify: config: pass builtins explicitly when parsing section config
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (19 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 20/63] notify: config: rename section config parser/writer methods Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 22/63] notify: implement PartialEq for all Config types Lukas Wagner
                   ` (42 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

Instead of passing &Context just for calling default_config, we pass
the section config data directly as an option. This makes the code a bit
less awkward in tests, where we don't care about builtins.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/api/matcher.rs | 12 ++----
 proxmox-notify/src/api/mod.rs     |  5 +--
 proxmox-notify/src/config.rs      | 64 +++++++++++++++----------------
 3 files changed, 36 insertions(+), 45 deletions(-)

diff --git a/proxmox-notify/src/api/matcher.rs b/proxmox-notify/src/api/matcher.rs
index 65ceb1dc7..f8bc06a9a 100644
--- a/proxmox-notify/src/api/matcher.rs
+++ b/proxmox-notify/src/api/matcher.rs
@@ -210,17 +210,14 @@ mod tests {
 
     use super::*;
 
-    use crate::{api_types::expression::NotificationMatcher, context::test::test_context};
+    use crate::api_types::expression::NotificationMatcher;
 
     fn empty_config() -> Config {
-        let context = test_context();
-        Config::parse_section_config(&context, "", "").unwrap()
+        Config::parse_section_config("", "", None).unwrap()
     }
 
     fn config_with_two_matchers() -> Config {
-        let context = test_context();
         Config::parse_section_config(
-            &context,
             "
 sendmail: foo
     mailto test@example.com
@@ -230,6 +227,7 @@ matcher: matcher1
 matcher: matcher2
 ",
             "",
+            None,
         )
         .unwrap()
     }
@@ -502,9 +500,7 @@ matcher: matcher2
         // The normalized expression should stay the same after
         // a read/write cycle of the config
         let (raw_config, raw_private_config) = config.to_section_config().unwrap();
-        let context = test_context();
-        let config =
-            Config::parse_section_config(&context, &raw_config, &raw_private_config).unwrap();
+        let config = Config::parse_section_config(&raw_config, &raw_private_config, None).unwrap();
         let matcher = get_matcher(&config, "matcher1")?;
 
         assert_eq!(matcher.expression, Some(stored));
diff --git a/proxmox-notify/src/api/mod.rs b/proxmox-notify/src/api/mod.rs
index b70c32df8..43e448bc9 100644
--- a/proxmox-notify/src/api/mod.rs
+++ b/proxmox-notify/src/api/mod.rs
@@ -221,12 +221,11 @@ fn remove_private_config_entry(config: &mut Config, name: &str) -> Result<(), Ht
 
 #[cfg(test)]
 mod test_helpers {
-    use crate::{Config, context::test};
+    use crate::Config;
 
     #[allow(unused)]
     pub fn empty_config() -> Config {
-        let context = test::test_context();
-        Config::parse_section_config(&context, "", "").unwrap()
+        Config::parse_section_config("", "", None).unwrap()
     }
 }
 
diff --git a/proxmox-notify/src/config.rs b/proxmox-notify/src/config.rs
index 8c7c84cc8..f59da9bdd 100644
--- a/proxmox-notify/src/config.rs
+++ b/proxmox-notify/src/config.rs
@@ -6,12 +6,12 @@ use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlug
 use serde_json::Value;
 use tracing::error;
 
+use crate::Error;
 use crate::api_types::{
     BACKEND_NAME_SCHEMA, GOTIFY_TYPENAME, GotifyConfig, GotifyPrivateConfig, MATCHER_TYPENAME,
     MatcherConfig, SENDMAIL_TYPENAME, SMTP_TYPENAME, SendmailConfig, SmtpConfig, SmtpPrivateConfig,
     WEBHOOK_TYPENAME, WebhookConfig, WebhookPrivateConfig,
 };
-use crate::{Context, Error};
 
 /// Section config schema for the public config file.
 pub fn config_parser() -> &'static SectionConfig {
@@ -139,51 +139,47 @@ pub struct Config {
 impl Config {
     /// Parse notification configuration from section config format.
     pub fn parse_section_config(
-        context: &Context,
         raw_config: &str,
         raw_private_config: &str,
+        builtin_config: Option<&SectionConfigData>,
     ) -> Result<Self, Error> {
         let (mut config, digest) = parse_config(raw_config)?;
         let (private_config, _) = parse_private_config(raw_private_config)?;
 
-        let default_config = context.default_config();
+        if let Some(builtin_config) = builtin_config {
+            for (key, (builtin_typename, builtin_value)) in &builtin_config.sections {
+                if let Some((typename, value)) = config.sections.get_mut(key) {
+                    if builtin_typename == typename && value == builtin_value {
+                        // Entry is built-in and the config entry section in notifications.cfg
+                        // is exactly the same.
+                        if let Some(obj) = value.as_object_mut() {
+                            obj.insert("origin".to_string(), Value::String("builtin".into()));
+                        } else {
+                            error!("section config entry is not an object. This should not happen");
+                        }
+                    } else {
+                        // Entry is built-in, but it has been modified by the user.
+                        if let Some(obj) = value.as_object_mut() {
+                            obj.insert(
+                                "origin".to_string(),
+                                Value::String("modified-builtin".into()),
+                            );
+                        } else {
+                            error!("section config entry is not an object. This should not happen");
+                        }
+                    }
+                } else {
+                    let mut val = builtin_value.clone();
 
-        let builtin_config = config_parser()
-            .parse("<builtin>", default_config)
-            .map_err(|err| Error::ConfigDeserialization(err.into()))?;
-
-        for (key, (builtin_typename, builtin_value)) in &builtin_config.sections {
-            if let Some((typename, value)) = config.sections.get_mut(key) {
-                if builtin_typename == typename && value == builtin_value {
-                    // Entry is built-in and the config entry section in notifications.cfg
-                    // is exactly the same.
-                    if let Some(obj) = value.as_object_mut() {
+                    if let Some(obj) = val.as_object_mut() {
                         obj.insert("origin".to_string(), Value::String("builtin".into()));
                     } else {
                         error!("section config entry is not an object. This should not happen");
                     }
-                } else {
-                    // Entry is built-in, but it has been modified by the user.
-                    if let Some(obj) = value.as_object_mut() {
-                        obj.insert(
-                            "origin".to_string(),
-                            Value::String("modified-builtin".into()),
-                        );
-                    } else {
-                        error!("section config entry is not an object. This should not happen");
-                    }
+                    config
+                        .set_data(key, builtin_typename, val)
+                        .map_err(|err| Error::ConfigDeserialization(err.into()))?;
                 }
-            } else {
-                let mut val = builtin_value.clone();
-
-                if let Some(obj) = val.as_object_mut() {
-                    obj.insert("origin".to_string(), Value::String("builtin".into()));
-                } else {
-                    error!("section config entry is not an object. This should not happen");
-                }
-                config
-                    .set_data(key, builtin_typename, val)
-                    .map_err(|err| Error::ConfigDeserialization(err.into()))?;
             }
         }
 
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 22/63] notify: implement PartialEq for all Config types
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (20 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 21/63] notify: config: pass builtins explicitly when parsing section config Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 23/63] notify: use typed SectionConfigData Lukas Wagner
                   ` (41 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/api_types/gotify.rs        |  2 +-
 .../src/api_types/matcher/calendar.rs         | 11 ++++++--
 proxmox-notify/src/api_types/matcher/field.rs | 25 ++++++++++++++++++-
 proxmox-notify/src/api_types/matcher/mod.rs   |  4 +--
 .../src/api_types/matcher/severity.rs         |  4 +--
 proxmox-notify/src/api_types/sendmail.rs      |  2 +-
 proxmox-notify/src/api_types/smtp.rs          |  4 +--
 proxmox-notify/src/api_types/webhook.rs       |  4 +--
 8 files changed, 43 insertions(+), 13 deletions(-)

diff --git a/proxmox-notify/src/api_types/gotify.rs b/proxmox-notify/src/api_types/gotify.rs
index 334920145..f74777472 100644
--- a/proxmox-notify/src/api_types/gotify.rs
+++ b/proxmox-notify/src/api_types/gotify.rs
@@ -19,7 +19,7 @@ pub const GOTIFY_TYPENAME: &str = "gotify";
         },
     }
 )]
-#[derive(Serialize, Deserialize, Updater, Default)]
+#[derive(Clone, Debug, Serialize, Deserialize, Updater, Default, PartialEq)]
 #[serde(rename_all = "kebab-case")]
 /// Config for Gotify notification endpoints
 pub struct GotifyConfig {
diff --git a/proxmox-notify/src/api_types/matcher/calendar.rs b/proxmox-notify/src/api_types/matcher/calendar.rs
index a0640b49a..65fd9bb4b 100644
--- a/proxmox-notify/src/api_types/matcher/calendar.rs
+++ b/proxmox-notify/src/api_types/matcher/calendar.rs
@@ -45,11 +45,18 @@ impl DailyDurationWrapper {
     }
 }
 
+impl PartialEq for DailyDurationWrapper {
+    fn eq(&self, other: &Self) -> bool {
+        // `daily_duration` is derived from `schedule`, so comparing the latter suffices.
+        self.schedule == other.schedule
+    }
+}
+
 proxmox_serde::forward_deserialize_to_from_str!(DailyDurationWrapper);
 proxmox_serde::forward_serialize_to_display!(DailyDurationWrapper);
 
 /// Match timestamp of the notification.
-#[derive(Clone, Debug, Serialize, Deserialize)]
+#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
 #[serde(rename_all = "kebab-case")]
 pub struct CalendarMatcher {
     schedule: DailyDurationWrapper,
@@ -90,7 +97,7 @@ pub mod inline {
     ///
     /// This is a wrapper that serializes into an inline format that can be used
     /// in a section config key-value pair.
-    #[derive(Clone, Debug)]
+    #[derive(Clone, Debug, PartialEq)]
     pub struct InlineCalendarMatcher(CalendarMatcher);
 
     impl MatchDirective for InlineCalendarMatcher {
diff --git a/proxmox-notify/src/api_types/matcher/field.rs b/proxmox-notify/src/api_types/matcher/field.rs
index b1ea25302..a00d46c3e 100644
--- a/proxmox-notify/src/api_types/matcher/field.rs
+++ b/proxmox-notify/src/api_types/matcher/field.rs
@@ -29,6 +29,29 @@ impl From<FieldMatcher> for Expression<NotificationMatcher> {
     }
 }
 
+// `Regex` does not implement `PartialEq`, so compare the regex patterns instead.
+impl PartialEq for FieldMatcher {
+    fn eq(&self, other: &Self) -> bool {
+        match (self, other) {
+            (
+                Self::Exact { field, values },
+                Self::Exact {
+                    field: other_field,
+                    values: other_values,
+                },
+            ) => field == other_field && values == other_values,
+            (
+                Self::Regex { field, regex },
+                Self::Regex {
+                    field: other_field,
+                    regex: other_regex,
+                },
+            ) => field == other_field && regex.as_str() == other_regex.as_str(),
+            _ => false,
+        }
+    }
+}
+
 impl MatchDirective for FieldMatcher {
     fn matches(&self, notification: &Notification) -> Result<bool, Error> {
         Ok(match self {
@@ -99,7 +122,7 @@ pub mod inline {
     /// Check if the notification metadata fields match
     /// This is a wrapper that serializes into an inline format that can be used
     /// in a section config key-value pair.
-    #[derive(Clone, Debug)]
+    #[derive(Clone, Debug, PartialEq)]
     pub struct InlineFieldMatcher(FieldMatcher);
 
     impl MatchDirective for InlineFieldMatcher {
diff --git a/proxmox-notify/src/api_types/matcher/mod.rs b/proxmox-notify/src/api_types/matcher/mod.rs
index dd9a987f4..e10ae6986 100644
--- a/proxmox-notify/src/api_types/matcher/mod.rs
+++ b/proxmox-notify/src/api_types/matcher/mod.rs
@@ -23,7 +23,7 @@ pub const MATCHER_TYPENAME: &str = "matcher";
 
 #[api]
 #[cfg(feature = "legacy-matchers")]
-#[derive(Debug, Serialize, Deserialize, Default, Clone, Copy)]
+#[derive(Debug, Serialize, Deserialize, Default, Clone, Copy, PartialEq)]
 #[serde(rename_all = "kebab-case")]
 /// The mode in which the results of matches are combined.
 pub enum MatchModeOperator {
@@ -75,7 +75,7 @@ pub enum MatchModeOperator {
             optional: true,
         },
     })]
-#[derive(Clone, Debug, Serialize, Deserialize, Updater, Default)]
+#[derive(Clone, Debug, Serialize, Deserialize, Updater, Default, PartialEq)]
 #[serde(rename_all = "kebab-case")]
 /// Config for notification matchers.
 pub struct MatcherConfig {
diff --git a/proxmox-notify/src/api_types/matcher/severity.rs b/proxmox-notify/src/api_types/matcher/severity.rs
index 2d68a46bb..ed0278888 100644
--- a/proxmox-notify/src/api_types/matcher/severity.rs
+++ b/proxmox-notify/src/api_types/matcher/severity.rs
@@ -6,7 +6,7 @@ use crate::{Error, Notification, Severity, api_types::expression::NotificationMa
 use super::MatchDirective;
 
 /// Match severity of the notification.
-#[derive(Clone, Debug, Serialize, Deserialize)]
+#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
 pub struct SeverityMatcher {
     pub(crate) severities: Vec<Severity>,
 }
@@ -44,7 +44,7 @@ pub mod inline {
     ///
     /// This is a wrapper that serializes into an inline format that can be used
     /// in a section config key-value pair.
-    #[derive(Clone, Debug)]
+    #[derive(Clone, Debug, PartialEq)]
     pub struct InlineSeverityMatcher(SeverityMatcher);
 
     /// Common trait implemented by all matching directives
diff --git a/proxmox-notify/src/api_types/sendmail.rs b/proxmox-notify/src/api_types/sendmail.rs
index bb843fbfa..fd7e457c2 100644
--- a/proxmox-notify/src/api_types/sendmail.rs
+++ b/proxmox-notify/src/api_types/sendmail.rs
@@ -33,7 +33,7 @@ pub const SENDMAIL_TYPENAME: &str = "sendmail";
         },
     },
 )]
-#[derive(Debug, Serialize, Deserialize, Updater, Default)]
+#[derive(Clone, Debug, Serialize, Deserialize, Updater, Default, PartialEq)]
 #[serde(rename_all = "kebab-case")]
 /// Config for Sendmail notification endpoints
 pub struct SendmailConfig {
diff --git a/proxmox-notify/src/api_types/smtp.rs b/proxmox-notify/src/api_types/smtp.rs
index 5cebbf8ad..e7dd37ef3 100644
--- a/proxmox-notify/src/api_types/smtp.rs
+++ b/proxmox-notify/src/api_types/smtp.rs
@@ -9,7 +9,7 @@ use super::schema::{EMAIL_SCHEMA, ENTITY_NAME_SCHEMA, USER_SCHEMA};
 pub const SMTP_TYPENAME: &str = "smtp";
 
 #[api]
-#[derive(Debug, Serialize, Deserialize, Default, Clone, Copy)]
+#[derive(Debug, Serialize, Deserialize, Default, Clone, Copy, PartialEq)]
 #[serde(rename_all = "kebab-case")]
 /// Connection security
 pub enum SmtpMode {
@@ -48,7 +48,7 @@ pub enum SmtpMode {
         },
     },
 )]
-#[derive(Debug, Serialize, Deserialize, Updater, Default)]
+#[derive(Clone, Debug, Serialize, Deserialize, Updater, Default, PartialEq)]
 #[serde(rename_all = "kebab-case")]
 /// Config for SMTP notification endpoints
 pub struct SmtpConfig {
diff --git a/proxmox-notify/src/api_types/webhook.rs b/proxmox-notify/src/api_types/webhook.rs
index 4a2430cec..68c2f381a 100644
--- a/proxmox-notify/src/api_types/webhook.rs
+++ b/proxmox-notify/src/api_types/webhook.rs
@@ -73,7 +73,7 @@ impl From<HttpMethod> for &str {
         },
     }
 )]
-#[derive(Serialize, Deserialize, Updater, Default, Clone)]
+#[derive(Serialize, Deserialize, Updater, Default, Clone, PartialEq)]
 #[serde(rename_all = "kebab-case")]
 /// Config for Webhook notification endpoints
 pub struct WebhookConfig {
@@ -165,7 +165,7 @@ pub enum DeleteableWebhookProperty {
 }
 
 #[api]
-#[derive(Serialize, Deserialize, Debug, Default, Clone)]
+#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)]
 /// Datatype used to represent key-value pairs, the value
 /// being encoded in base64.
 pub struct KeyAndBase64Val {
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 23/63] notify: use typed SectionConfigData
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (21 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 22/63] notify: implement PartialEq for all Config types Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 24/63] notify: api: api types: rename Deleteable* -> Deletable* Lukas Wagner
                   ` (40 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

This allows us to simplify working with the config quite a bit. Added a
config-parsing roundtrip test while at it.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---

Notes:
    Changes since v1:
    
      - Use id-property and id-schema to simplify code.

 proxmox-notify/Cargo.toml                     |   3 +
 proxmox-notify/src/api/gotify.rs              | 103 +++---
 proxmox-notify/src/api/matcher.rs             |  54 +--
 proxmox-notify/src/api/mod.rs                 |  40 +--
 proxmox-notify/src/api/sendmail.rs            |  49 +--
 proxmox-notify/src/api/smtp.rs                |  93 +++--
 proxmox-notify/src/api/webhook.rs             | 147 ++++----
 proxmox-notify/src/config.rs                  | 326 +++++++++---------
 proxmox-notify/src/send.rs                    | 180 ++++------
 .../testdata/notifications-priv.cfg.ref       |   8 +
 proxmox-notify/testdata/notifications.cfg.ref |  29 ++
 11 files changed, 467 insertions(+), 565 deletions(-)
 create mode 100644 proxmox-notify/testdata/notifications-priv.cfg.ref
 create mode 100644 proxmox-notify/testdata/notifications.cfg.ref

diff --git a/proxmox-notify/Cargo.toml b/proxmox-notify/Cargo.toml
index 6bb4871f7..5f7ea3176 100644
--- a/proxmox-notify/Cargo.toml
+++ b/proxmox-notify/Cargo.toml
@@ -40,6 +40,9 @@ proxmox-sys = { workspace = true, optional = true }
 proxmox-time.workspace = true
 proxmox-uuid = { workspace = true, features = ["serde"] }
 
+[dev-dependencies]
+pretty_assertions.workspace = true
+
 [features]
 default = ["send-impl", "api-types"]
 api-impl = [
diff --git a/proxmox-notify/src/api/gotify.rs b/proxmox-notify/src/api/gotify.rs
index e0f7cf16b..e4ac46328 100644
--- a/proxmox-notify/src/api/gotify.rs
+++ b/proxmox-notify/src/api/gotify.rs
@@ -1,12 +1,14 @@
 use proxmox_config_digest::ConfigDigest;
 use proxmox_http_error::HttpError;
+use proxmox_section_config::typed::{convert_to_typed_array, lookup};
 
 use crate::Config;
 use crate::api::http_err;
 use crate::api_types::{
-    DeleteableGotifyProperty, GOTIFY_TYPENAME, GotifyConfig, GotifyConfigUpdater,
-    GotifyPrivateConfig, GotifyPrivateConfigUpdater,
+    DeleteableGotifyProperty, GotifyConfig, GotifyConfigUpdater, GotifyPrivateConfig,
+    GotifyPrivateConfigUpdater,
 };
+use crate::config::{ConfigEntity, PrivateConfigEntity};
 
 /// Get a list of all gotify endpoints.
 ///
@@ -14,10 +16,10 @@ use crate::api_types::{
 /// Returns a list of all gotify endpoints or a `HttpError` if the config is
 /// erroneous (`500 Internal server error`).
 pub fn get_endpoints(config: &Config) -> Result<Vec<GotifyConfig>, HttpError> {
-    config
-        .config
-        .convert_to_typed_array(GOTIFY_TYPENAME)
-        .map_err(|e| http_err!(NOT_FOUND, "Could not fetch endpoints: {e}"))
+    Ok(convert_to_typed_array!(config.config, ConfigEntity::Gotify)
+        .into_iter()
+        .cloned()
+        .collect())
 }
 
 /// Get gotify endpoint with given `name`
@@ -25,10 +27,9 @@ pub fn get_endpoints(config: &Config) -> Result<Vec<GotifyConfig>, HttpError> {
 /// The caller is responsible for any needed permission checks.
 /// Returns the endpoint or a `HttpError` if the endpoint was not found (`404 Not found`).
 pub fn get_endpoint(config: &Config, name: &str) -> Result<GotifyConfig, HttpError> {
-    config
-        .config
-        .lookup(GOTIFY_TYPENAME, name)
-        .map_err(|_| http_err!(NOT_FOUND, "endpoint '{name}' not found"))
+    lookup!(config.config, name, ConfigEntity::Gotify)
+        .cloned()
+        .ok_or_else(|| http_err!(NOT_FOUND, "endpoint '{name}' not found"))
 }
 
 /// Add a new gotify endpoint.
@@ -52,18 +53,17 @@ pub fn add_endpoint(
 
     super::ensure_unique(config, &endpoint_config.name)?;
 
-    set_private_config_entry(config, &private_endpoint_config)?;
+    config.private_config.insert(
+        private_endpoint_config.name.clone(),
+        PrivateConfigEntity::Gotify(private_endpoint_config),
+    );
 
-    config
-        .config
-        .set_data(&endpoint_config.name, GOTIFY_TYPENAME, &endpoint_config)
-        .map_err(|e| {
-            http_err!(
-                INTERNAL_SERVER_ERROR,
-                "could not save endpoint '{}': {e}",
-                endpoint_config.name
-            )
-        })
+    config.config.insert(
+        endpoint_config.name.clone(),
+        ConfigEntity::Gotify(endpoint_config),
+    );
+
+    Ok(())
 }
 
 /// Update existing gotify endpoint
@@ -99,13 +99,13 @@ pub fn update_endpoint(
     }
 
     if let Some(token) = private_endpoint_config_updater.token {
-        set_private_config_entry(
-            config,
-            &GotifyPrivateConfig {
+        config.private_config.insert(
+            name,
+            PrivateConfigEntity::Gotify(GotifyPrivateConfig {
                 name: name.into(),
                 token,
-            },
-        )?;
+            }),
+        );
     }
 
     if let Some(comment) = endpoint_config_updater.comment {
@@ -116,15 +116,9 @@ pub fn update_endpoint(
         endpoint.disable = Some(disable);
     }
 
-    config
-        .config
-        .set_data(name, GOTIFY_TYPENAME, &endpoint)
-        .map_err(|e| {
-            http_err!(
-                INTERNAL_SERVER_ERROR,
-                "could not save endpoint '{name}': {e}"
-            )
-        })
+    config.config.insert(name, ConfigEntity::Gotify(endpoint));
+
+    Ok(())
 }
 
 /// Delete existing gotify endpoint
@@ -139,33 +133,12 @@ pub fn delete_gotify_endpoint(config: &mut Config, name: &str) -> Result<(), Htt
     let _ = get_endpoint(config, name)?;
     super::ensure_safe_to_delete(config, name)?;
 
-    remove_private_config_entry(config, name)?;
-    config.config.sections.remove(name);
+    config.private_config.remove(name);
+    config.config.remove(name);
 
     Ok(())
 }
 
-fn set_private_config_entry(
-    config: &mut Config,
-    private_config: &GotifyPrivateConfig,
-) -> Result<(), HttpError> {
-    config
-        .private_config
-        .set_data(&private_config.name, GOTIFY_TYPENAME, private_config)
-        .map_err(|e| {
-            http_err!(
-                INTERNAL_SERVER_ERROR,
-                "could not save private config for endpoint '{}': {e}",
-                private_config.name
-            )
-        })
-}
-
-fn remove_private_config_entry(config: &mut Config, name: &str) -> Result<(), HttpError> {
-    config.private_config.sections.remove(name);
-    Ok(())
-}
-
 #[cfg(test)]
 mod tests {
     use super::*;
@@ -255,13 +228,15 @@ mod tests {
 
         assert_eq!(endpoint.server, "newhost".to_string());
 
-        let token = config
-            .private_config
-            .lookup::<GotifyPrivateConfig>(GOTIFY_TYPENAME, "gotify-endpoint")
-            .unwrap()
-            .token;
+        let token = &lookup!(
+            config.private_config,
+            "gotify-endpoint",
+            PrivateConfigEntity::Gotify
+        )
+        .unwrap()
+        .token;
 
-        assert_eq!(token, "changedtoken".to_string());
+        assert_eq!(token, "changedtoken");
         assert_eq!(endpoint.comment, Some("newcomment".to_string()));
 
         // Test property deletion
diff --git a/proxmox-notify/src/api/matcher.rs b/proxmox-notify/src/api/matcher.rs
index f8bc06a9a..cdb66f368 100644
--- a/proxmox-notify/src/api/matcher.rs
+++ b/proxmox-notify/src/api/matcher.rs
@@ -1,11 +1,11 @@
 use proxmox_config_digest::ConfigDigest;
 use proxmox_http_error::HttpError;
+use proxmox_section_config::typed::{convert_to_typed_array, lookup};
 
 use crate::Config;
 use crate::api::http_err;
-use crate::api_types::{
-    DeleteableMatcherProperty, MATCHER_TYPENAME, MatcherConfig, MatcherConfigUpdater,
-};
+use crate::api_types::{DeleteableMatcherProperty, MatcherConfig, MatcherConfigUpdater};
+use crate::config::ConfigEntity;
 
 /// Get a list of all matchers
 ///
@@ -13,10 +13,12 @@ use crate::api_types::{
 /// Returns a list of all matchers or a `HttpError` if the config is
 /// (`500 Internal server error`).
 pub fn get_matchers(config: &Config) -> Result<Vec<MatcherConfig>, HttpError> {
-    config
-        .config
-        .convert_to_typed_array(MATCHER_TYPENAME)
-        .map_err(|e| http_err!(INTERNAL_SERVER_ERROR, "Could not fetch matchers: {e}"))
+    Ok(
+        convert_to_typed_array!(config.config, ConfigEntity::Matcher)
+            .into_iter()
+            .cloned()
+            .collect(),
+    )
 }
 
 /// Get matcher with given `name`
@@ -24,10 +26,9 @@ pub fn get_matchers(config: &Config) -> Result<Vec<MatcherConfig>, HttpError> {
 /// The caller is responsible for any needed permission checks.
 /// Returns the endpoint or a `HttpError` if the matcher was not found (`404 Not found`).
 pub fn get_matcher(config: &Config, name: &str) -> Result<MatcherConfig, HttpError> {
-    config
-        .config
-        .lookup(MATCHER_TYPENAME, name)
-        .map_err(|_| http_err!(NOT_FOUND, "matcher '{name}' not found"))
+    lookup!(config.config, name, ConfigEntity::Matcher)
+        .cloned()
+        .ok_or_else(|| http_err!(NOT_FOUND, "matcher '{name}' not found"))
 }
 
 /// Get matcher with given `name`, translating any existing 'match-*' keys into an
@@ -37,10 +38,7 @@ pub fn get_matcher(config: &Config, name: &str) -> Result<MatcherConfig, HttpErr
 /// Returns the endpoint or a `HttpError` if the matcher was not found (`404 Not found`).
 #[cfg(feature = "legacy-matchers")]
 pub fn get_matcher_as_expression(config: &Config, name: &str) -> Result<MatcherConfig, HttpError> {
-    let mut matcher: MatcherConfig = config
-        .config
-        .lookup(MATCHER_TYPENAME, name)
-        .map_err(|_| http_err!(NOT_FOUND, "matcher '{name}' not found"))?;
+    let mut matcher = get_matcher(config, name)?;
 
     if matcher.expression.is_none() {
         let expression = matcher.generate_expression_from_legacy_config();
@@ -80,16 +78,10 @@ pub fn add_matcher(
         .ensure_valid()
         .map_err(|err| http_err!(BAD_REQUEST, "invalid matcher config: {err}"))?;
 
-    config
-        .config
-        .set_data(&matcher_config.name, MATCHER_TYPENAME, &matcher_config)
-        .map_err(|e| {
-            http_err!(
-                INTERNAL_SERVER_ERROR,
-                "could not save matcher '{}': {e}",
-                matcher_config.name
-            )
-        })?;
+    config.config.insert(
+        matcher_config.name.clone(),
+        ConfigEntity::Matcher(matcher_config),
+    );
 
     Ok(())
 }
@@ -176,15 +168,7 @@ pub fn update_matcher(
         .ensure_valid()
         .map_err(|err| http_err!(BAD_REQUEST, "invalid matcher config: {err}"))?;
 
-    config
-        .config
-        .set_data(name, MATCHER_TYPENAME, &matcher)
-        .map_err(|e| {
-            http_err!(
-                INTERNAL_SERVER_ERROR,
-                "could not save matcher '{name}': {e}"
-            )
-        })?;
+    config.config.insert(name, ConfigEntity::Matcher(matcher));
 
     Ok(())
 }
@@ -199,7 +183,7 @@ pub fn delete_matcher(config: &mut Config, name: &str) -> Result<(), HttpError>
     // Check if the matcher exists
     let _ = get_matcher(config, name)?;
 
-    config.config.sections.remove(name);
+    config.config.remove(name);
 
     Ok(())
 }
diff --git a/proxmox-notify/src/api/mod.rs b/proxmox-notify/src/api/mod.rs
index 43e448bc9..fb6ba9ad9 100644
--- a/proxmox-notify/src/api/mod.rs
+++ b/proxmox-notify/src/api/mod.rs
@@ -1,7 +1,5 @@
 use std::collections::HashSet;
 
-use serde::{Deserialize, Serialize};
-
 use proxmox_config_digest::ConfigDigest;
 use proxmox_http_error::HttpError;
 
@@ -118,7 +116,7 @@ fn ensure_endpoints_exist<T: AsRef<str>>(
 }
 
 fn ensure_unique(config: &Config, entity: &str) -> Result<(), HttpError> {
-    if config.config.sections.contains_key(entity) {
+    if config.config.contains_key(entity) {
         http_bail!(
             BAD_REQUEST,
             "Cannot create '{entity}', an entity with the same name already exists"
@@ -141,14 +139,11 @@ fn get_referrers(config: &Config, entity: &str) -> Result<HashSet<String>, HttpE
 }
 
 fn ensure_safe_to_delete(config: &Config, entity: &str) -> Result<(), HttpError> {
-    if let Some(entity_config) = config.config.sections.get(entity) {
-        if let Ok(origin) = Origin::deserialize(&entity_config.1["origin"]) {
-            // Built-ins are never actually removed, only reset to their default
-            // It is thus safe to do the reset if another entity depends
-            // on it
-            if origin == Origin::Builtin || origin == Origin::ModifiedBuiltin {
-                return Ok(());
-            }
+    if let Some(entity_config) = config.config.get(entity) {
+        let origin = entity_config.origin().unwrap_or(Origin::UserCreated);
+
+        if origin == Origin::Builtin || origin == Origin::ModifiedBuiltin {
+            return Ok(());
         }
     } else {
         http_bail!(NOT_FOUND, "entity '{entity}' does not exist");
@@ -196,29 +191,6 @@ fn get_referenced_entities(config: &Config, entity: &str) -> HashSet<String> {
     expanded
 }
 
-fn set_private_config_entry<T: Serialize>(
-    config: &mut Config,
-    private_config: T,
-    typename: &str,
-    name: &str,
-) -> Result<(), HttpError> {
-    config
-        .private_config
-        .set_data(name, typename, &private_config)
-        .map_err(|e| {
-            http_err!(
-                INTERNAL_SERVER_ERROR,
-                "could not save private config for endpoint '{}': {e}",
-                name
-            )
-        })
-}
-
-fn remove_private_config_entry(config: &mut Config, name: &str) -> Result<(), HttpError> {
-    config.private_config.sections.remove(name);
-    Ok(())
-}
-
 #[cfg(test)]
 mod test_helpers {
     use crate::Config;
diff --git a/proxmox-notify/src/api/sendmail.rs b/proxmox-notify/src/api/sendmail.rs
index cff63b806..1d429c8f8 100644
--- a/proxmox-notify/src/api/sendmail.rs
+++ b/proxmox-notify/src/api/sendmail.rs
@@ -1,11 +1,11 @@
 use proxmox_config_digest::ConfigDigest;
 use proxmox_http_error::HttpError;
+use proxmox_section_config::typed::{convert_to_typed_array, lookup};
 
 use crate::Config;
 use crate::api::{http_bail, http_err};
-use crate::api_types::{
-    DeleteableSendmailProperty, SENDMAIL_TYPENAME, SendmailConfig, SendmailConfigUpdater,
-};
+use crate::api_types::{DeleteableSendmailProperty, SendmailConfig, SendmailConfigUpdater};
+use crate::config::ConfigEntity;
 
 /// Get a list of all sendmail endpoints.
 ///
@@ -13,10 +13,12 @@ use crate::api_types::{
 /// Returns a list of all sendmail endpoints or a `HttpError` if the config is
 /// erroneous (`500 Internal server error`).
 pub fn get_endpoints(config: &Config) -> Result<Vec<SendmailConfig>, HttpError> {
-    config
-        .config
-        .convert_to_typed_array(SENDMAIL_TYPENAME)
-        .map_err(|e| http_err!(NOT_FOUND, "Could not fetch endpoints: {e}"))
+    Ok(
+        convert_to_typed_array!(config.config, ConfigEntity::Sendmail)
+            .into_iter()
+            .cloned()
+            .collect(),
+    )
 }
 
 /// Get sendmail endpoint with given `name`.
@@ -24,10 +26,9 @@ pub fn get_endpoints(config: &Config) -> Result<Vec<SendmailConfig>, HttpError>
 /// The caller is responsible for any needed permission checks.
 /// Returns the endpoint or a `HttpError` if the endpoint was not found (`404 Not found`).
 pub fn get_endpoint(config: &Config, name: &str) -> Result<SendmailConfig, HttpError> {
-    config
-        .config
-        .lookup(SENDMAIL_TYPENAME, name)
-        .map_err(|_| http_err!(NOT_FOUND, "endpoint '{name}' not found"))
+    lookup!(config.config, name, ConfigEntity::Sendmail)
+        .cloned()
+        .ok_or_else(|| http_err!(NOT_FOUND, "endpoint '{name}' not found"))
 }
 
 /// Add a new sendmail endpoint.
@@ -50,14 +51,9 @@ pub fn add_endpoint(config: &mut Config, endpoint: SendmailConfig) -> Result<(),
 
     config
         .config
-        .set_data(&endpoint.name, SENDMAIL_TYPENAME, &endpoint)
-        .map_err(|e| {
-            http_err!(
-                INTERNAL_SERVER_ERROR,
-                "could not save endpoint '{}': {e}",
-                endpoint.name
-            )
-        })
+        .insert(endpoint.name.clone(), ConfigEntity::Sendmail(endpoint));
+
+    Ok(())
 }
 
 /// Update existing sendmail endpoint
@@ -122,16 +118,9 @@ pub fn update_endpoint(
         );
     }
 
-    config
-        .config
-        .set_data(name, SENDMAIL_TYPENAME, &endpoint)
-        .map_err(|e| {
-            http_err!(
-                INTERNAL_SERVER_ERROR,
-                "could not save endpoint '{}': {e}",
-                endpoint.name
-            )
-        })
+    config.config.insert(name, ConfigEntity::Sendmail(endpoint));
+
+    Ok(())
 }
 
 /// Delete existing sendmail endpoint
@@ -147,7 +136,7 @@ pub fn delete_endpoint(config: &mut Config, name: &str) -> Result<(), HttpError>
     let _ = get_endpoint(config, name)?;
     super::ensure_safe_to_delete(config, name)?;
 
-    config.config.sections.remove(name);
+    config.config.remove(name);
 
     Ok(())
 }
diff --git a/proxmox-notify/src/api/smtp.rs b/proxmox-notify/src/api/smtp.rs
index ceae77df3..30df66d21 100644
--- a/proxmox-notify/src/api/smtp.rs
+++ b/proxmox-notify/src/api/smtp.rs
@@ -1,12 +1,14 @@
 use proxmox_config_digest::ConfigDigest;
 use proxmox_http_error::HttpError;
+use proxmox_section_config::typed::{convert_to_typed_array, lookup};
 
 use crate::Config;
 use crate::api::{http_bail, http_err};
 use crate::api_types::{
-    DeleteableSmtpProperty, SMTP_TYPENAME, SmtpConfig, SmtpConfigUpdater, SmtpPrivateConfig,
+    DeleteableSmtpProperty, SmtpConfig, SmtpConfigUpdater, SmtpPrivateConfig,
     SmtpPrivateConfigUpdater,
 };
+use crate::config::{ConfigEntity, PrivateConfigEntity};
 
 /// Get a list of all smtp endpoints.
 ///
@@ -14,10 +16,10 @@ use crate::api_types::{
 /// Returns a list of all smtp endpoints or a `HttpError` if the config is
 /// erroneous (`500 Internal server error`).
 pub fn get_endpoints(config: &Config) -> Result<Vec<SmtpConfig>, HttpError> {
-    config
-        .config
-        .convert_to_typed_array(SMTP_TYPENAME)
-        .map_err(|e| http_err!(NOT_FOUND, "Could not fetch endpoints: {e}"))
+    Ok(convert_to_typed_array!(config.config, ConfigEntity::Smtp)
+        .into_iter()
+        .cloned()
+        .collect())
 }
 
 /// Get smtp endpoint with given `name`.
@@ -25,10 +27,9 @@ pub fn get_endpoints(config: &Config) -> Result<Vec<SmtpConfig>, HttpError> {
 /// The caller is responsible for any needed permission checks.
 /// Returns the endpoint or a `HttpError` if the endpoint was not found (`404 Not found`).
 pub fn get_endpoint(config: &Config, name: &str) -> Result<SmtpConfig, HttpError> {
-    config
-        .config
-        .lookup(SMTP_TYPENAME, name)
-        .map_err(|_| http_err!(NOT_FOUND, "endpoint '{name}' not found"))
+    lookup!(config.config, name, ConfigEntity::Smtp)
+        .cloned()
+        .ok_or_else(|| http_err!(NOT_FOUND, "endpoint '{name}' not found"))
 }
 
 /// Add a new smtp endpoint.
@@ -58,23 +59,17 @@ pub fn add_endpoint(
         );
     }
 
-    super::set_private_config_entry(
-        config,
-        private_endpoint_config,
-        SMTP_TYPENAME,
-        &endpoint_config.name,
-    )?;
+    config.private_config.insert(
+        private_endpoint_config.name.clone(),
+        PrivateConfigEntity::Smtp(private_endpoint_config),
+    );
 
-    config
-        .config
-        .set_data(&endpoint_config.name, SMTP_TYPENAME, &endpoint_config)
-        .map_err(|e| {
-            http_err!(
-                INTERNAL_SERVER_ERROR,
-                "could not save endpoint '{}': {e}",
-                endpoint_config.name
-            )
-        })
+    config.config.insert(
+        endpoint_config.name.clone(),
+        ConfigEntity::Smtp(endpoint_config),
+    );
+
+    Ok(())
 }
 
 /// Update existing smtp endpoint
@@ -104,15 +99,15 @@ pub fn update_endpoint(
                 DeleteableSmtpProperty::Disable => endpoint.disable = None,
                 DeleteableSmtpProperty::Mailto => endpoint.mailto.clear(),
                 DeleteableSmtpProperty::MailtoUser => endpoint.mailto_user.clear(),
-                DeleteableSmtpProperty::Password => super::set_private_config_entry(
-                    config,
-                    SmtpPrivateConfig {
-                        name: name.to_string(),
-                        password: None,
-                    },
-                    SMTP_TYPENAME,
-                    name,
-                )?,
+                DeleteableSmtpProperty::Password => {
+                    config.private_config.insert(
+                        name,
+                        PrivateConfigEntity::Smtp(SmtpPrivateConfig {
+                            name: name.into(),
+                            password: None,
+                        }),
+                    );
+                }
                 DeleteableSmtpProperty::Port => endpoint.port = None,
                 DeleteableSmtpProperty::Username => endpoint.username = None,
             }
@@ -141,15 +136,13 @@ pub fn update_endpoint(
         endpoint.mode = Some(mode);
     }
     if let Some(password) = private_endpoint_config_updater.password {
-        super::set_private_config_entry(
-            config,
-            SmtpPrivateConfig {
+        config.private_config.insert(
+            name,
+            PrivateConfigEntity::Smtp(SmtpPrivateConfig {
                 name: name.into(),
                 password: Some(password),
-            },
-            SMTP_TYPENAME,
-            name,
-        )?;
+            }),
+        );
     }
 
     if let Some(author) = updater.author {
@@ -171,16 +164,9 @@ pub fn update_endpoint(
         );
     }
 
-    config
-        .config
-        .set_data(name, SMTP_TYPENAME, &endpoint)
-        .map_err(|e| {
-            http_err!(
-                INTERNAL_SERVER_ERROR,
-                "could not save endpoint '{}': {e}",
-                endpoint.name
-            )
-        })
+    config.config.insert(name, ConfigEntity::Smtp(endpoint));
+
+    Ok(())
 }
 
 /// Delete existing smtp endpoint
@@ -195,8 +181,9 @@ pub fn delete_endpoint(config: &mut Config, name: &str) -> Result<(), HttpError>
     let _ = get_endpoint(config, name)?;
     super::ensure_safe_to_delete(config, name)?;
 
-    super::remove_private_config_entry(config, name)?;
-    config.config.sections.remove(name);
+    config.private_config.remove(name);
+
+    config.config.remove(name);
 
     Ok(())
 }
diff --git a/proxmox-notify/src/api/webhook.rs b/proxmox-notify/src/api/webhook.rs
index 7266faca6..beaa26f15 100644
--- a/proxmox-notify/src/api/webhook.rs
+++ b/proxmox-notify/src/api/webhook.rs
@@ -5,37 +5,38 @@
 use proxmox_config_digest::ConfigDigest;
 use proxmox_http_error::HttpError;
 use proxmox_schema::property_string::PropertyString;
+use proxmox_section_config::typed::{convert_to_typed_array, lookup};
 
 use crate::api::http_err;
 use crate::api_types::{
-    DeleteableWebhookProperty, KeyAndBase64Val, WEBHOOK_TYPENAME, WebhookConfig,
-    WebhookConfigUpdater, WebhookPrivateConfig,
+    DeleteableWebhookProperty, KeyAndBase64Val, WebhookConfig, WebhookConfigUpdater,
+    WebhookPrivateConfig,
 };
+use crate::config::{ConfigEntity, PrivateConfigEntity};
 use crate::{Config, http_bail};
 
-use super::remove_private_config_entry;
-use super::set_private_config_entry;
-
 /// Get a list of all webhook endpoints.
 ///
 /// The caller is responsible for any needed permission checks.
 /// Returns a list of all webhook endpoints or a [`HttpError`] if the config is
 /// erroneous (`500 Internal server error`).
 pub fn get_endpoints(config: &Config) -> Result<Vec<WebhookConfig>, HttpError> {
-    let mut endpoints: Vec<WebhookConfig> = config
-        .config
-        .convert_to_typed_array(WEBHOOK_TYPENAME)
-        .map_err(|e| http_err!(NOT_FOUND, "Could not fetch endpoints: {e}"))?;
+    let mut endpoints: Vec<WebhookConfig> =
+        convert_to_typed_array!(config.config, ConfigEntity::Webhook)
+            .into_iter()
+            .cloned()
+            .collect();
 
     for endpoint in &mut endpoints {
-        let priv_config: WebhookPrivateConfig = config
-            .private_config
-            .lookup(WEBHOOK_TYPENAME, &endpoint.name)
-            .unwrap_or_default();
+        let priv_config = lookup!(
+            config.private_config,
+            &endpoint.name,
+            PrivateConfigEntity::Webhook
+        );
 
         let mut secret_names = Vec::new();
         // We only return *which* secrets we have stored, but not their values.
-        for secret in priv_config.secret {
+        for secret in priv_config.into_iter().flat_map(|c| &c.secret) {
             secret_names.push(
                 KeyAndBase64Val {
                     name: secret.name.clone(),
@@ -56,15 +57,15 @@ pub fn get_endpoints(config: &Config) -> Result<Vec<WebhookConfig>, HttpError> {
 /// The caller is responsible for any needed permission checks.
 /// Returns the endpoint or a [`HttpError`] if the endpoint was not found (`404 Not found`).
 pub fn get_endpoint(config: &Config, name: &str) -> Result<WebhookConfig, HttpError> {
-    let mut endpoint: WebhookConfig = config
-        .config
-        .lookup(WEBHOOK_TYPENAME, name)
-        .map_err(|_| http_err!(NOT_FOUND, "endpoint '{name}' not found"))?;
+    let mut endpoint = lookup!(config.config, name, ConfigEntity::Webhook)
+        .cloned()
+        .ok_or_else(|| http_err!(NOT_FOUND, "endpoint '{name}' not found"))?;
 
-    let priv_config: Option<WebhookPrivateConfig> = config
-        .private_config
-        .lookup(WEBHOOK_TYPENAME, &endpoint.name)
-        .ok();
+    let priv_config = lookup!(
+        config.private_config,
+        &endpoint.name,
+        PrivateConfigEntity::Webhook
+    );
 
     let mut secret_names = Vec::new();
     if let Some(priv_config) = priv_config {
@@ -100,26 +101,20 @@ pub fn add_endpoint(
 
     let secrets = std::mem::take(&mut endpoint_config.secret);
 
-    set_private_config_entry(
-        config,
-        &WebhookPrivateConfig {
+    config.private_config.insert(
+        endpoint_config.name.clone(),
+        PrivateConfigEntity::Webhook(WebhookPrivateConfig {
             name: endpoint_config.name.clone(),
             secret: secrets,
-        },
-        WEBHOOK_TYPENAME,
-        &endpoint_config.name,
-    )?;
+        }),
+    );
 
-    config
-        .config
-        .set_data(&endpoint_config.name, WEBHOOK_TYPENAME, &endpoint_config)
-        .map_err(|e| {
-            http_err!(
-                INTERNAL_SERVER_ERROR,
-                "could not save endpoint '{}': {e}",
-                endpoint_config.name
-            )
-        })
+    config.config.insert(
+        endpoint_config.name.clone(),
+        ConfigEntity::Webhook(endpoint_config),
+    );
+
+    Ok(())
 }
 
 /// Update existing webhook endpoint.
@@ -144,11 +139,10 @@ pub fn update_endpoint(
     let mut endpoint = get_endpoint(config, name)?;
     endpoint.secret.clear();
 
-    let old_secrets = config
-        .private_config
-        .lookup::<WebhookPrivateConfig>(WEBHOOK_TYPENAME, name)
-        .map_err(|err| http_err!(INTERNAL_SERVER_ERROR, "could not read secret config: {err}"))?
-        .secret;
+    let old_secrets = lookup!(config.private_config, name, PrivateConfigEntity::Webhook)
+        .ok_or_else(|| http_err!(INTERNAL_SERVER_ERROR, "could not read secret config"))?
+        .secret
+        .clone();
 
     if let Some(delete) = delete {
         for deleteable_property in delete {
@@ -158,15 +152,13 @@ pub fn update_endpoint(
                 DeleteableWebhookProperty::Header => endpoint.header = Vec::new(),
                 DeleteableWebhookProperty::Body => endpoint.body = None,
                 DeleteableWebhookProperty::Secret => {
-                    set_private_config_entry(
-                        config,
-                        &WebhookPrivateConfig {
+                    config.private_config.insert(
+                        name,
+                        PrivateConfigEntity::Webhook(WebhookPrivateConfig {
                             name: name.into(),
                             secret: Vec::new(),
-                        },
-                        WEBHOOK_TYPENAME,
-                        name,
-                    )?;
+                        }),
+                    );
                 }
             }
         }
@@ -250,26 +242,18 @@ pub fn update_endpoint(
             new_secrets.push(sec);
         }
 
-        set_private_config_entry(
-            config,
-            &WebhookPrivateConfig {
+        config.private_config.insert(
+            name,
+            PrivateConfigEntity::Webhook(WebhookPrivateConfig {
                 name: name.into(),
                 secret: new_secrets,
-            },
-            WEBHOOK_TYPENAME,
-            name,
-        )?;
+            }),
+        );
     }
 
-    config
-        .config
-        .set_data(name, WEBHOOK_TYPENAME, &endpoint)
-        .map_err(|e| {
-            http_err!(
-                INTERNAL_SERVER_ERROR,
-                "could not save endpoint '{name}': {e}"
-            )
-        })
+    config.config.insert(name, ConfigEntity::Webhook(endpoint));
+
+    Ok(())
 }
 
 /// Delete existing webhook endpoint.
@@ -284,8 +268,9 @@ pub fn delete_endpoint(config: &mut Config, name: &str) -> Result<(), HttpError>
     let _ = get_endpoint(config, name)?;
     super::ensure_safe_to_delete(config, name)?;
 
-    remove_private_config_entry(config, name)?;
-    config.config.sections.remove(name);
+    config.private_config.remove(name);
+
+    config.config.remove(name);
 
     Ok(())
 }
@@ -381,11 +366,13 @@ mod tests {
         assert_eq!(endpoint.comment, Some("newcomment".to_string()));
         assert!(matches!(endpoint.method, HttpMethod::Put));
 
-        let secrets = config
-            .private_config
-            .lookup::<WebhookPrivateConfig>(WEBHOOK_TYPENAME, "webhook-endpoint")
-            .unwrap()
-            .secret;
+        let secrets = &lookup!(
+            config.private_config,
+            "webhook-endpoint",
+            PrivateConfigEntity::Webhook
+        )
+        .unwrap()
+        .secret;
 
         assert_eq!(secrets[1].name, "token".to_string());
         assert_eq!(secrets[1].value, Some(proxmox_base64::encode("secret")));
@@ -407,11 +394,13 @@ mod tests {
         let endpoint = get_endpoint(&config, "webhook-endpoint")?;
         assert_eq!(endpoint.comment, None);
 
-        let secrets = config
-            .private_config
-            .lookup::<WebhookPrivateConfig>(WEBHOOK_TYPENAME, "webhook-endpoint")
-            .unwrap()
-            .secret;
+        let secrets = &lookup!(
+            config.private_config,
+            "webhook-endpoint",
+            PrivateConfigEntity::Webhook
+        )
+        .unwrap()
+        .secret;
 
         assert!(secrets.is_empty());
 
diff --git a/proxmox-notify/src/config.rs b/proxmox-notify/src/config.rs
index f59da9bdd..459e2f322 100644
--- a/proxmox-notify/src/config.rs
+++ b/proxmox-notify/src/config.rs
@@ -1,138 +1,40 @@
-use std::sync::OnceLock;
-
 use proxmox_config_digest::ConfigDigest;
-use proxmox_schema::{ApiType, ObjectSchema};
-use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin};
-use serde_json::Value;
-use tracing::error;
+use proxmox_schema::api;
+use proxmox_schema::api_types::SAFE_ID_FORMAT;
+use proxmox_section_config::typed::{ApiSectionDataEntry, SectionConfigData};
+use serde::{Deserialize, Serialize};
 
 use crate::Error;
 use crate::api_types::{
-    BACKEND_NAME_SCHEMA, GOTIFY_TYPENAME, GotifyConfig, GotifyPrivateConfig, MATCHER_TYPENAME,
-    MatcherConfig, SENDMAIL_TYPENAME, SMTP_TYPENAME, SendmailConfig, SmtpConfig, SmtpPrivateConfig,
-    WEBHOOK_TYPENAME, WebhookConfig, WebhookPrivateConfig,
+    GotifyConfig, GotifyPrivateConfig, MatcherConfig, Origin, SendmailConfig, SmtpConfig,
+    SmtpPrivateConfig, WebhookConfig, WebhookPrivateConfig,
 };
 
-/// Section config schema for the public config file.
-pub fn config_parser() -> &'static SectionConfig {
-    static CONFIG: OnceLock<SectionConfig> = OnceLock::new();
-    CONFIG.get_or_init(config_init)
-}
-
-/// Section config schema for the private config file.
-pub fn private_config_parser() -> &'static SectionConfig {
-    static CONFIG: OnceLock<SectionConfig> = OnceLock::new();
-    CONFIG.get_or_init(private_config_init)
-}
-
-fn config_init() -> SectionConfig {
-    let mut config = SectionConfig::new(&BACKEND_NAME_SCHEMA);
-
-    {
-        const SENDMAIL_SCHEMA: &ObjectSchema = SendmailConfig::API_SCHEMA.unwrap_object_schema();
-        config.register_plugin(SectionConfigPlugin::new(
-            SENDMAIL_TYPENAME.to_string(),
-            Some(String::from("name")),
-            SENDMAIL_SCHEMA,
-        ));
-    }
-    {
-        const SMTP_SCHEMA: &ObjectSchema = SmtpConfig::API_SCHEMA.unwrap_object_schema();
-        config.register_plugin(SectionConfigPlugin::new(
-            SMTP_TYPENAME.to_string(),
-            Some(String::from("name")),
-            SMTP_SCHEMA,
-        ));
-    }
-    {
-        const GOTIFY_SCHEMA: &ObjectSchema = GotifyConfig::API_SCHEMA.unwrap_object_schema();
-        config.register_plugin(SectionConfigPlugin::new(
-            GOTIFY_TYPENAME.to_string(),
-            Some(String::from("name")),
-            GOTIFY_SCHEMA,
-        ));
-    }
-    {
-        const WEBHOOK_SCHEMA: &ObjectSchema = WebhookConfig::API_SCHEMA.unwrap_object_schema();
-        config.register_plugin(SectionConfigPlugin::new(
-            WEBHOOK_TYPENAME.to_string(),
-            Some(String::from("name")),
-            WEBHOOK_SCHEMA,
-        ));
-    }
-
-    const MATCHER_SCHEMA: &ObjectSchema = MatcherConfig::API_SCHEMA.unwrap_object_schema();
-    config.register_plugin(SectionConfigPlugin::new(
-        MATCHER_TYPENAME.to_string(),
-        Some(String::from("name")),
-        MATCHER_SCHEMA,
-    ));
-
-    config
-}
-
-fn private_config_init() -> SectionConfig {
-    let mut config = SectionConfig::new(&BACKEND_NAME_SCHEMA);
-
-    const GOTIFY_SCHEMA: &ObjectSchema = GotifyPrivateConfig::API_SCHEMA.unwrap_object_schema();
-    config.register_plugin(SectionConfigPlugin::new(
-        GOTIFY_TYPENAME.to_string(),
-        Some(String::from("name")),
-        GOTIFY_SCHEMA,
-    ));
-
-    const SMTP_SCHEMA: &ObjectSchema = SmtpPrivateConfig::API_SCHEMA.unwrap_object_schema();
-    config.register_plugin(SectionConfigPlugin::new(
-        SMTP_TYPENAME.to_string(),
-        Some(String::from("name")),
-        SMTP_SCHEMA,
-    ));
-
-    const WEBHOOK_SCHEMA: &ObjectSchema = WebhookPrivateConfig::API_SCHEMA.unwrap_object_schema();
-    config.register_plugin(SectionConfigPlugin::new(
-        WEBHOOK_TYPENAME.to_string(),
-        Some(String::from("name")),
-        WEBHOOK_SCHEMA,
-    ));
-
-    config
-}
-
-fn parse_config(raw_config: &str) -> Result<(SectionConfigData, ConfigDigest), Error> {
+fn parse_config(
+    raw_config: &str,
+) -> Result<(SectionConfigData<ConfigEntity>, ConfigDigest), Error> {
     let digest = ConfigDigest::from_slice(raw_config.as_bytes());
-    let data = config_parser()
-        .parse("notifications.cfg", raw_config)
+    let data = ConfigEntity::parse_section_config("notifications.cfg", raw_config)
         .map_err(Error::config_deserialization)?;
 
     Ok((data, digest))
 }
 
-fn parse_private_config(raw_config: &str) -> Result<(SectionConfigData, ConfigDigest), Error> {
+fn parse_private_config(
+    raw_config: &str,
+) -> Result<(SectionConfigData<PrivateConfigEntity>, ConfigDigest), Error> {
     let digest = ConfigDigest::from_slice(raw_config.as_bytes());
-    let data = private_config_parser()
-        .parse("priv/notifications.cfg", raw_config)
+    let data = PrivateConfigEntity::parse_section_config("priv/notifications.cfg", raw_config)
         .map_err(Error::config_deserialization)?;
 
     Ok((data, digest))
 }
 
-fn write(config: &SectionConfigData) -> Result<String, Error> {
-    config_parser()
-        .write("notifications.cfg", config)
-        .map_err(Error::config_serialization)
-}
-
-fn write_private(config: &SectionConfigData) -> Result<String, Error> {
-    private_config_parser()
-        .write("priv/notifications.cfg", config)
-        .map_err(Error::config_serialization)
-}
-
 /// Notification configuration
-#[derive(Debug, Clone)]
+#[derive(Clone)]
 pub struct Config {
-    pub(crate) config: SectionConfigData,
-    pub(crate) private_config: SectionConfigData,
+    pub(crate) config: SectionConfigData<ConfigEntity>,
+    pub(crate) private_config: SectionConfigData<PrivateConfigEntity>,
     digest: ConfigDigest,
 }
 
@@ -141,53 +43,38 @@ impl Config {
     pub fn parse_section_config(
         raw_config: &str,
         raw_private_config: &str,
-        builtin_config: Option<&SectionConfigData>,
+        builtin_config: Option<&SectionConfigData<ConfigEntity>>,
     ) -> Result<Self, Error> {
         let (mut config, digest) = parse_config(raw_config)?;
         let (private_config, _) = parse_private_config(raw_private_config)?;
 
         if let Some(builtin_config) = builtin_config {
-            for (key, (builtin_typename, builtin_value)) in &builtin_config.sections {
-                if let Some((typename, value)) = config.sections.get_mut(key) {
-                    if builtin_typename == typename && value == builtin_value {
+            for (key, builtin_value) in builtin_config {
+                if let Some(value) = config.get_mut(key) {
+                    if value == builtin_value {
                         // Entry is built-in and the config entry section in notifications.cfg
                         // is exactly the same.
-                        if let Some(obj) = value.as_object_mut() {
-                            obj.insert("origin".to_string(), Value::String("builtin".into()));
-                        } else {
-                            error!("section config entry is not an object. This should not happen");
-                        }
+                        value.set_origin(Some(Origin::Builtin));
                     } else {
                         // Entry is built-in, but it has been modified by the user.
-                        if let Some(obj) = value.as_object_mut() {
-                            obj.insert(
-                                "origin".to_string(),
-                                Value::String("modified-builtin".into()),
-                            );
-                        } else {
-                            error!("section config entry is not an object. This should not happen");
-                        }
+                        value.set_origin(Some(Origin::ModifiedBuiltin));
                     }
                 } else {
-                    let mut val = builtin_value.clone();
-
-                    if let Some(obj) = val.as_object_mut() {
-                        obj.insert("origin".to_string(), Value::String("builtin".into()));
-                    } else {
-                        error!("section config entry is not an object. This should not happen");
-                    }
-                    config
-                        .set_data(key, builtin_typename, val)
-                        .map_err(|err| Error::ConfigDeserialization(err.into()))?;
+                    // If it doesn't exist, we insert the builtin
+                    let mut value = builtin_value.clone();
+                    value.set_origin(Some(Origin::Builtin));
+                    config.insert(key.to_string(), value);
                 }
             }
         }
 
-        for (_, (_, value)) in config.sections.iter_mut() {
-            if let Some(obj) = value.as_object_mut() {
-                if obj.get("origin").is_none() {
-                    obj.insert("origin".to_string(), Value::String("user-created".into()));
-                }
+        let keys: Vec<String> = config.keys().cloned().collect();
+
+        for key in keys {
+            if let Some(value) = config.get_mut(&key)
+                && value.origin().is_none()
+            {
+                value.set_origin(Some(Origin::UserCreated));
             }
         }
 
@@ -200,20 +87,48 @@ impl Config {
 
     /// Serialize config
     pub fn to_section_config(&self) -> Result<(String, String), Error> {
-        let mut c = self.config.clone();
-        for (_, (_, value)) in c.sections.iter_mut() {
-            // Remove 'origin' parameter, we do not want it in our
-            // config fields
-            // TODO: Check if there is a better way for this, maybe a
-            // separate type for API responses?
-            if let Some(obj) = value.as_object_mut() {
-                obj.remove("origin");
-            } else {
-                error!("section config entry is not an object. This should not happen");
+        let mut configs_without_origin = SectionConfigData::default();
+
+        for (name, section) in &self.config {
+            match section {
+                ConfigEntity::Sendmail(config) => {
+                    let mut config = config.clone();
+                    config.origin = None;
+                    configs_without_origin.insert(name, ConfigEntity::Sendmail(config));
+                }
+                ConfigEntity::Smtp(config) => {
+                    let mut config = config.clone();
+                    config.origin = None;
+                    configs_without_origin.insert(name, ConfigEntity::Smtp(config));
+                }
+                ConfigEntity::Gotify(config) => {
+                    let mut config = config.clone();
+                    config.origin = None;
+                    configs_without_origin.insert(name, ConfigEntity::Gotify(config));
+                }
+                ConfigEntity::Webhook(config) => {
+                    let mut config = config.clone();
+                    config.origin = None;
+                    configs_without_origin.insert(name, ConfigEntity::Webhook(config));
+                }
+                ConfigEntity::Matcher(config) => {
+                    let mut config = config.clone();
+                    config.origin = None;
+                    configs_without_origin.insert(name, ConfigEntity::Matcher(config));
+                }
             }
         }
 
-        Ok((write(&c)?, write_private(&self.private_config)?))
+        let config_str =
+            ConfigEntity::write_section_config("notifications.cfg", &configs_without_origin)
+                .map_err(Error::config_serialization)?;
+        let private_config_str = PrivateConfigEntity::write_section_config(
+            "priv/notifications.cfg",
+            &self.private_config,
+        )
+        .map_err(Error::config_serialization)?;
+
+        Ok((config_str, private_config_str))
     }
 
     /// Returns the SHA256 digest of the configuration.
@@ -222,3 +137,98 @@ impl Config {
         &self.digest
     }
 }
+
+#[api(
+    "id-property": "name",
+    "id-schema": {
+        type: String,
+        description: "Notification config entity name.",
+        min_length: 3,
+        max_length: 32,
+        format: &SAFE_ID_FORMAT,
+    },
+)]
+/// Config entity in the notification config file.
+#[derive(Clone, Deserialize, Serialize, PartialEq)]
+#[serde(rename_all = "kebab-case", tag = "type")]
+pub enum ConfigEntity {
+    /// Sendmail endpoint.
+    Sendmail(SendmailConfig),
+    /// Gotify endpoint.
+    Gotify(GotifyConfig),
+    /// SMTP endpoint.
+    Smtp(SmtpConfig),
+    /// Webhook endpoint.
+    Webhook(WebhookConfig),
+    /// Matcher configuration.
+    Matcher(MatcherConfig),
+}
+
+impl ConfigEntity {
+    pub(crate) fn set_origin(&mut self, origin: Option<Origin>) {
+        match self {
+            ConfigEntity::Sendmail(config) => config.origin = origin,
+            ConfigEntity::Gotify(config) => config.origin = origin,
+            ConfigEntity::Smtp(config) => config.origin = origin,
+            ConfigEntity::Webhook(config) => config.origin = origin,
+            ConfigEntity::Matcher(config) => config.origin = origin,
+        }
+    }
+
+    pub(crate) fn origin(&self) -> Option<Origin> {
+        match self {
+            ConfigEntity::Sendmail(config) => config.origin,
+            ConfigEntity::Gotify(config) => config.origin,
+            ConfigEntity::Smtp(config) => config.origin,
+            ConfigEntity::Webhook(config) => config.origin,
+            ConfigEntity::Matcher(config) => config.origin,
+        }
+    }
+}
+
+#[api(
+    "id-property": "name",
+    "id-schema": {
+        type: String,
+        description: "Notification config entity name.",
+        min_length: 3,
+        max_length: 32,
+        format: &SAFE_ID_FORMAT,
+    },
+)]
+/// Config entity in the private notification config file.
+#[derive(Clone, Deserialize, Serialize)]
+#[serde(rename_all = "kebab-case", tag = "type")]
+pub enum PrivateConfigEntity {
+    /// Private config for a gotify endpoint.
+    Gotify(GotifyPrivateConfig),
+    /// Private config for an SMTP endpoint.
+    Smtp(SmtpPrivateConfig),
+    /// Private config for a webhook endpoint.
+    Webhook(WebhookPrivateConfig),
+}
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    const CONFIG_REF: &str = include_str!("../testdata/notifications.cfg.ref");
+    const PRIV_CONFIG_REF: &str = include_str!("../testdata/notifications-priv.cfg.ref");
+
+    use pretty_assertions::assert_eq;
+
+    #[test]
+    fn section_config_roundtrip() {
+        let config = Config::parse_section_config(CONFIG_REF, PRIV_CONFIG_REF, None).unwrap();
+
+        assert_eq!(
+            config.digest().to_string(),
+            "53554a97ca1747b69582f7cde5d4493f68b77c0d5946ce593a59547c9638d504"
+        );
+
+        let (public_config, private_config) = config.to_section_config().unwrap();
+
+        assert_eq!(public_config, CONFIG_REF);
+        assert_eq!(private_config, PRIV_CONFIG_REF);
+    }
+}
diff --git a/proxmox-notify/src/send.rs b/proxmox-notify/src/send.rs
index 3cb9444c2..210a42599 100644
--- a/proxmox-notify/src/send.rs
+++ b/proxmox-notify/src/send.rs
@@ -1,15 +1,12 @@
 use std::collections::{HashMap, HashSet};
 
+use proxmox_section_config::typed::{convert_to_typed_array, lookup};
 use proxmox_uuid::Uuid;
-use serde::Deserialize;
 use serde_json::json;
 use tracing::{error, info};
 
-use crate::api_types::{GOTIFY_TYPENAME, GotifyConfig, GotifyPrivateConfig};
-use crate::api_types::{MATCHER_TYPENAME, MatcherConfig};
-use crate::api_types::{SENDMAIL_TYPENAME, SendmailConfig};
-use crate::api_types::{SMTP_TYPENAME, SmtpConfig, SmtpPrivateConfig};
-use crate::api_types::{WEBHOOK_TYPENAME, WebhookConfig, WebhookPrivateConfig};
+use crate::api_types::MatcherConfig;
+use crate::config::{ConfigEntity, PrivateConfigEntity};
 use crate::endpoints::Endpoint;
 use crate::endpoints::gotify::GotifyEndpoint;
 use crate::endpoints::sendmail::SendmailEndpoint;
@@ -48,64 +45,8 @@ struct Bus {
     matchers: Vec<MatcherConfig>,
 }
 
-macro_rules! parse_endpoints_with_private_config {
-    ($config:ident, $public_config:ty, $private_config:ty, $endpoint_type:ident, $type_name:expr) => {
-        (|| -> Result<Vec<Box<dyn Endpoint>>, Error> {
-            let mut endpoints = Vec::<Box<dyn Endpoint>>::new();
-
-            let configs: Vec<$public_config> = $config
-                .config
-                .convert_to_typed_array($type_name)
-                .map_err(|err| Error::ConfigDeserialization(err.into()))?;
-
-            for config in configs {
-                match $config.private_config.sections.get(&config.name) {
-                    Some((section_type_name, private_config)) => {
-                        if $type_name != section_type_name {
-                            error!(
-                                "Could not instantiate endpoint '{name}': \
-                                private config has wrong type",
-                                name = config.name
-                            );
-                        }
-                        let private_config = <$private_config>::deserialize(private_config)
-                            .map_err(|err| Error::ConfigDeserialization(err.into()))?;
-
-                        endpoints.push(Box::new($endpoint_type {
-                            config,
-                            private_config: private_config.clone(),
-                        }));
-                    }
-                    None => error!(
-                        "Could not instantiate endpoint '{name}': \
-                            private config does not exist",
-                        name = config.name
-                    ),
-                }
-            }
-
-            Ok(endpoints)
-        })()
-    };
-}
-
-macro_rules! parse_endpoints_without_private_config {
-    ($config:ident, $public_config:ty, $endpoint_type:ident, $type_name:expr) => {
-        (|| -> Result<Vec<Box<dyn Endpoint>>, Error> {
-            let mut endpoints = Vec::<Box<dyn Endpoint>>::new();
-
-            let configs: Vec<$public_config> = $config
-                .config
-                .convert_to_typed_array($type_name)
-                .map_err(|err| Error::ConfigDeserialization(err.into()))?;
-
-            for config in configs {
-                endpoints.push(Box::new($endpoint_type { config }));
-            }
-
-            Ok(endpoints)
-        })()
-    };
+fn log_missing_private_config(endpoint_name: &str) {
+    error!("Could not instantiate endpoint '{endpoint_name}': private config does not exist");
 }
 
 impl Bus {
@@ -113,58 +54,73 @@ impl Bus {
     pub fn from_config(config: &Config) -> Result<Self, Error> {
         let mut endpoints = HashMap::new();
 
-        // Instantiate endpoints
-        endpoints.extend(
-            parse_endpoints_without_private_config!(
-                config,
-                SendmailConfig,
-                SendmailEndpoint,
-                SENDMAIL_TYPENAME
-            )?
-            .into_iter()
-            .map(|e| (e.name().into(), e)),
-        );
+        for endpoint_config in convert_to_typed_array!(config.config, ConfigEntity::Sendmail) {
+            endpoints.insert(
+                endpoint_config.name.clone(),
+                Box::new(SendmailEndpoint {
+                    config: endpoint_config.clone(),
+                }) as Box<dyn Endpoint>,
+            );
+        }
 
-        endpoints.extend(
-            parse_endpoints_with_private_config!(
-                config,
-                GotifyConfig,
-                GotifyPrivateConfig,
-                GotifyEndpoint,
-                GOTIFY_TYPENAME
-            )?
-            .into_iter()
-            .map(|e| (e.name().into(), e)),
-        );
+        for endpoint_config in convert_to_typed_array!(config.config, ConfigEntity::Gotify) {
+            if let Some(private_config) = lookup!(
+                config.private_config,
+                &endpoint_config.name,
+                PrivateConfigEntity::Gotify
+            ) {
+                endpoints.insert(
+                    endpoint_config.name.clone(),
+                    Box::new(GotifyEndpoint {
+                        config: endpoint_config.clone(),
+                        private_config: private_config.clone(),
+                    }) as Box<dyn Endpoint>,
+                );
+            } else {
+                log_missing_private_config(&endpoint_config.name);
+            }
+        }
 
-        endpoints.extend(
-            parse_endpoints_with_private_config!(
-                config,
-                SmtpConfig,
-                SmtpPrivateConfig,
-                SmtpEndpoint,
-                SMTP_TYPENAME
-            )?
-            .into_iter()
-            .map(|e| (e.name().into(), e)),
-        );
+        for endpoint_config in convert_to_typed_array!(config.config, ConfigEntity::Webhook) {
+            if let Some(private_config) = lookup!(
+                config.private_config,
+                &endpoint_config.name,
+                PrivateConfigEntity::Webhook
+            ) {
+                endpoints.insert(
+                    endpoint_config.name.clone(),
+                    Box::new(WebhookEndpoint {
+                        config: endpoint_config.clone(),
+                        private_config: private_config.clone(),
+                    }) as Box<dyn Endpoint>,
+                );
+            } else {
+                log_missing_private_config(&endpoint_config.name);
+            }
+        }
 
-        endpoints.extend(
-            parse_endpoints_with_private_config!(
-                config,
-                WebhookConfig,
-                WebhookPrivateConfig,
-                WebhookEndpoint,
-                WEBHOOK_TYPENAME
-            )?
-            .into_iter()
-            .map(|e| (e.name().into(), e)),
-        );
+        for endpoint_config in convert_to_typed_array!(config.config, ConfigEntity::Smtp) {
+            if let Some(private_config) = lookup!(
+                config.private_config,
+                &endpoint_config.name,
+                PrivateConfigEntity::Smtp
+            ) {
+                endpoints.insert(
+                    endpoint_config.name.clone(),
+                    Box::new(SmtpEndpoint {
+                        config: endpoint_config.clone(),
+                        private_config: private_config.clone(),
+                    }) as Box<dyn Endpoint>,
+                );
+            } else {
+                log_missing_private_config(&endpoint_config.name);
+            }
+        }
 
-        let matchers = config
-            .config
-            .convert_to_typed_array(MATCHER_TYPENAME)
-            .map_err(|err| Error::ConfigDeserialization(err.into()))?;
+        let matchers = convert_to_typed_array!(config.config, ConfigEntity::Matcher)
+            .into_iter()
+            .cloned()
+            .collect();
 
         Ok(Bus {
             endpoints,
diff --git a/proxmox-notify/testdata/notifications-priv.cfg.ref b/proxmox-notify/testdata/notifications-priv.cfg.ref
new file mode 100644
index 000000000..fcf4d0dbe
--- /dev/null
+++ b/proxmox-notify/testdata/notifications-priv.cfg.ref
@@ -0,0 +1,8 @@
+gotify: test-gotify
+	token test
+
+smtp: test-smtp
+	password password
+
+webhook: test-webhook
+	secret name=key,value=c2VjcmV0
diff --git a/proxmox-notify/testdata/notifications.cfg.ref b/proxmox-notify/testdata/notifications.cfg.ref
new file mode 100644
index 000000000..53040973f
--- /dev/null
+++ b/proxmox-notify/testdata/notifications.cfg.ref
@@ -0,0 +1,29 @@
+sendmail: mail-to-root
+	comment Send mails to root@pam's email address
+	mailto-user root@pam
+
+matcher: default-matcher
+	comment Route all notifications to mail-to-root
+	expression {"constant":true}
+	target mail-to-root
+
+gotify: test-gotify
+	comment some comment
+	server https://localhost:8000
+
+smtp: test-smtp
+	author Proxmox VE (test)
+	comment some comment
+	from-address test@example.com
+	mailto test@example.com
+	mailto-user root@pam
+	mode tls
+	server mail.example.com
+	username testuser
+
+webhook: test-webhook
+	body c29tZXRoaW5n
+	comment some comment
+	header name=Content-Type,value=YXBwbGljYXRpb24vanNvbg==
+	method post
+	url https://localhost:8001
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 24/63] notify: api: api types: rename Deleteable* -> Deletable*
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (22 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 23/63] notify: use typed SectionConfigData Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 25/63] notify: context: parse builtin config only once Lukas Wagner
                   ` (39 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/api/gotify.rs            | 10 +++---
 proxmox-notify/src/api/matcher.rs           | 38 ++++++++++-----------
 proxmox-notify/src/api/sendmail.rs          | 20 +++++------
 proxmox-notify/src/api/smtp.rs              | 30 ++++++++--------
 proxmox-notify/src/api/webhook.rs           | 18 +++++-----
 proxmox-notify/src/api_types/gotify.rs      |  2 +-
 proxmox-notify/src/api_types/matcher/mod.rs |  2 +-
 proxmox-notify/src/api_types/sendmail.rs    |  2 +-
 proxmox-notify/src/api_types/smtp.rs        |  2 +-
 proxmox-notify/src/api_types/webhook.rs     |  2 +-
 10 files changed, 63 insertions(+), 63 deletions(-)

diff --git a/proxmox-notify/src/api/gotify.rs b/proxmox-notify/src/api/gotify.rs
index e4ac46328..629b21bc2 100644
--- a/proxmox-notify/src/api/gotify.rs
+++ b/proxmox-notify/src/api/gotify.rs
@@ -5,7 +5,7 @@ use proxmox_section_config::typed::{convert_to_typed_array, lookup};
 use crate::Config;
 use crate::api::http_err;
 use crate::api_types::{
-    DeleteableGotifyProperty, GotifyConfig, GotifyConfigUpdater, GotifyPrivateConfig,
+    DeletableGotifyProperty, GotifyConfig, GotifyConfigUpdater, GotifyPrivateConfig,
     GotifyPrivateConfigUpdater,
 };
 use crate::config::{ConfigEntity, PrivateConfigEntity};
@@ -78,7 +78,7 @@ pub fn update_endpoint(
     name: &str,
     endpoint_config_updater: GotifyConfigUpdater,
     private_endpoint_config_updater: GotifyPrivateConfigUpdater,
-    delete: Option<&[DeleteableGotifyProperty]>,
+    delete: Option<&[DeletableGotifyProperty]>,
     digest: Option<ConfigDigest>,
 ) -> Result<(), HttpError> {
     super::verify_digest(config, digest)?;
@@ -88,8 +88,8 @@ pub fn update_endpoint(
     if let Some(delete) = delete {
         for deletable_property in delete {
             match deletable_property {
-                DeleteableGotifyProperty::Comment => endpoint.comment = None,
-                DeleteableGotifyProperty::Disable => endpoint.disable = None,
+                DeletableGotifyProperty::Comment => endpoint.comment = None,
+                DeletableGotifyProperty::Disable => endpoint.disable = None,
             }
         }
     }
@@ -245,7 +245,7 @@ mod tests {
             "gotify-endpoint",
             Default::default(),
             Default::default(),
-            Some(&[DeleteableGotifyProperty::Comment]),
+            Some(&[DeletableGotifyProperty::Comment]),
             None,
         )?;
 
diff --git a/proxmox-notify/src/api/matcher.rs b/proxmox-notify/src/api/matcher.rs
index cdb66f368..980c6f774 100644
--- a/proxmox-notify/src/api/matcher.rs
+++ b/proxmox-notify/src/api/matcher.rs
@@ -4,7 +4,7 @@ use proxmox_section_config::typed::{convert_to_typed_array, lookup};
 
 use crate::Config;
 use crate::api::http_err;
-use crate::api_types::{DeleteableMatcherProperty, MatcherConfig, MatcherConfigUpdater};
+use crate::api_types::{DeletableMatcherProperty, MatcherConfig, MatcherConfigUpdater};
 use crate::config::ConfigEntity;
 
 /// Get a list of all matchers
@@ -97,7 +97,7 @@ pub fn update_matcher(
     config: &mut Config,
     name: &str,
     matcher_updater: MatcherConfigUpdater,
-    delete: Option<&[DeleteableMatcherProperty]>,
+    delete: Option<&[DeletableMatcherProperty]>,
     digest: Option<ConfigDigest>,
 ) -> Result<(), HttpError> {
     super::verify_digest(config, digest)?;
@@ -108,19 +108,19 @@ pub fn update_matcher(
         for deletable_property in delete {
             match deletable_property {
                 #[cfg(feature = "legacy-matchers")]
-                DeleteableMatcherProperty::MatchSeverity => matcher.match_severity.clear(),
+                DeletableMatcherProperty::MatchSeverity => matcher.match_severity.clear(),
                 #[cfg(feature = "legacy-matchers")]
-                DeleteableMatcherProperty::MatchField => matcher.match_field.clear(),
+                DeletableMatcherProperty::MatchField => matcher.match_field.clear(),
                 #[cfg(feature = "legacy-matchers")]
-                DeleteableMatcherProperty::MatchCalendar => matcher.match_calendar.clear(),
+                DeletableMatcherProperty::MatchCalendar => matcher.match_calendar.clear(),
                 #[cfg(feature = "legacy-matchers")]
-                DeleteableMatcherProperty::InvertMatch => matcher.invert_match = None,
+                DeletableMatcherProperty::InvertMatch => matcher.invert_match = None,
                 #[cfg(feature = "legacy-matchers")]
-                DeleteableMatcherProperty::Mode => matcher.mode = None,
-                DeleteableMatcherProperty::Expression => matcher.expression = None,
-                DeleteableMatcherProperty::Comment => matcher.comment = None,
-                DeleteableMatcherProperty::Target => matcher.target.clear(),
-                DeleteableMatcherProperty::Disable => matcher.disable = None,
+                DeletableMatcherProperty::Mode => matcher.mode = None,
+                DeletableMatcherProperty::Expression => matcher.expression = None,
+                DeletableMatcherProperty::Comment => matcher.comment = None,
+                DeletableMatcherProperty::Target => matcher.target.clear(),
+                DeletableMatcherProperty::Disable => matcher.disable = None,
             }
         }
     }
@@ -283,11 +283,11 @@ matcher: matcher2
             "matcher1",
             Default::default(),
             Some(&[
-                DeleteableMatcherProperty::InvertMatch,
-                DeleteableMatcherProperty::Mode,
-                DeleteableMatcherProperty::MatchField,
-                DeleteableMatcherProperty::Target,
-                DeleteableMatcherProperty::Comment,
+                DeletableMatcherProperty::InvertMatch,
+                DeletableMatcherProperty::Mode,
+                DeletableMatcherProperty::MatchField,
+                DeletableMatcherProperty::Target,
+                DeletableMatcherProperty::Comment,
             ]),
             Some(digest),
         )?;
@@ -334,9 +334,9 @@ matcher: matcher2
             "matcher1",
             Default::default(),
             Some(&[
-                DeleteableMatcherProperty::Target,
-                DeleteableMatcherProperty::Comment,
-                DeleteableMatcherProperty::Expression,
+                DeletableMatcherProperty::Target,
+                DeletableMatcherProperty::Comment,
+                DeletableMatcherProperty::Expression,
             ]),
             Some(digest),
         )?;
diff --git a/proxmox-notify/src/api/sendmail.rs b/proxmox-notify/src/api/sendmail.rs
index 1d429c8f8..91f7ad8b9 100644
--- a/proxmox-notify/src/api/sendmail.rs
+++ b/proxmox-notify/src/api/sendmail.rs
@@ -4,7 +4,7 @@ use proxmox_section_config::typed::{convert_to_typed_array, lookup};
 
 use crate::Config;
 use crate::api::{http_bail, http_err};
-use crate::api_types::{DeleteableSendmailProperty, SendmailConfig, SendmailConfigUpdater};
+use crate::api_types::{DeletableSendmailProperty, SendmailConfig, SendmailConfigUpdater};
 use crate::config::ConfigEntity;
 
 /// Get a list of all sendmail endpoints.
@@ -67,7 +67,7 @@ pub fn update_endpoint(
     config: &mut Config,
     name: &str,
     updater: SendmailConfigUpdater,
-    delete: Option<&[DeleteableSendmailProperty]>,
+    delete: Option<&[DeletableSendmailProperty]>,
     digest: Option<ConfigDigest>,
 ) -> Result<(), HttpError> {
     super::verify_digest(config, digest)?;
@@ -77,12 +77,12 @@ pub fn update_endpoint(
     if let Some(delete) = delete {
         for deletable_property in delete {
             match deletable_property {
-                DeleteableSendmailProperty::FromAddress => endpoint.from_address = None,
-                DeleteableSendmailProperty::Author => endpoint.author = None,
-                DeleteableSendmailProperty::Comment => endpoint.comment = None,
-                DeleteableSendmailProperty::Mailto => endpoint.mailto.clear(),
-                DeleteableSendmailProperty::MailtoUser => endpoint.mailto_user.clear(),
-                DeleteableSendmailProperty::Disable => endpoint.disable = None,
+                DeletableSendmailProperty::FromAddress => endpoint.from_address = None,
+                DeletableSendmailProperty::Author => endpoint.author = None,
+                DeletableSendmailProperty::Comment => endpoint.comment = None,
+                DeletableSendmailProperty::Mailto => endpoint.mailto.clear(),
+                DeletableSendmailProperty::MailtoUser => endpoint.mailto_user.clear(),
+                DeletableSendmailProperty::Disable => endpoint.disable = None,
             }
         }
     }
@@ -256,8 +256,8 @@ pub mod tests {
             "sendmail-endpoint",
             Default::default(),
             Some(&[
-                DeleteableSendmailProperty::FromAddress,
-                DeleteableSendmailProperty::Author,
+                DeletableSendmailProperty::FromAddress,
+                DeletableSendmailProperty::Author,
             ]),
             None,
         )?;
diff --git a/proxmox-notify/src/api/smtp.rs b/proxmox-notify/src/api/smtp.rs
index 30df66d21..431bd7a62 100644
--- a/proxmox-notify/src/api/smtp.rs
+++ b/proxmox-notify/src/api/smtp.rs
@@ -5,7 +5,7 @@ use proxmox_section_config::typed::{convert_to_typed_array, lookup};
 use crate::Config;
 use crate::api::{http_bail, http_err};
 use crate::api_types::{
-    DeleteableSmtpProperty, SmtpConfig, SmtpConfigUpdater, SmtpPrivateConfig,
+    DeletableSmtpProperty, SmtpConfig, SmtpConfigUpdater, SmtpPrivateConfig,
     SmtpPrivateConfigUpdater,
 };
 use crate::config::{ConfigEntity, PrivateConfigEntity};
@@ -84,7 +84,7 @@ pub fn update_endpoint(
     name: &str,
     updater: SmtpConfigUpdater,
     private_endpoint_config_updater: SmtpPrivateConfigUpdater,
-    delete: Option<&[DeleteableSmtpProperty]>,
+    delete: Option<&[DeletableSmtpProperty]>,
     digest: Option<ConfigDigest>,
 ) -> Result<(), HttpError> {
     super::verify_digest(config, digest)?;
@@ -94,12 +94,12 @@ pub fn update_endpoint(
     if let Some(delete) = delete {
         for deletable_property in delete {
             match deletable_property {
-                DeleteableSmtpProperty::Author => endpoint.author = None,
-                DeleteableSmtpProperty::Comment => endpoint.comment = None,
-                DeleteableSmtpProperty::Disable => endpoint.disable = None,
-                DeleteableSmtpProperty::Mailto => endpoint.mailto.clear(),
-                DeleteableSmtpProperty::MailtoUser => endpoint.mailto_user.clear(),
-                DeleteableSmtpProperty::Password => {
+                DeletableSmtpProperty::Author => endpoint.author = None,
+                DeletableSmtpProperty::Comment => endpoint.comment = None,
+                DeletableSmtpProperty::Disable => endpoint.disable = None,
+                DeletableSmtpProperty::Mailto => endpoint.mailto.clear(),
+                DeletableSmtpProperty::MailtoUser => endpoint.mailto_user.clear(),
+                DeletableSmtpProperty::Password => {
                     config.private_config.insert(
                         name,
                         PrivateConfigEntity::Smtp(SmtpPrivateConfig {
@@ -108,8 +108,8 @@ pub fn update_endpoint(
                         }),
                     );
                 }
-                DeleteableSmtpProperty::Port => endpoint.port = None,
-                DeleteableSmtpProperty::Username => endpoint.username = None,
+                DeletableSmtpProperty::Port => endpoint.port = None,
+                DeletableSmtpProperty::Username => endpoint.username = None,
             }
         }
     }
@@ -319,11 +319,11 @@ pub mod tests {
             Default::default(),
             Default::default(),
             Some(&[
-                DeleteableSmtpProperty::Author,
-                DeleteableSmtpProperty::MailtoUser,
-                DeleteableSmtpProperty::Port,
-                DeleteableSmtpProperty::Username,
-                DeleteableSmtpProperty::Comment,
+                DeletableSmtpProperty::Author,
+                DeletableSmtpProperty::MailtoUser,
+                DeletableSmtpProperty::Port,
+                DeletableSmtpProperty::Username,
+                DeletableSmtpProperty::Comment,
             ]),
             None,
         )?;
diff --git a/proxmox-notify/src/api/webhook.rs b/proxmox-notify/src/api/webhook.rs
index beaa26f15..ec4692d7c 100644
--- a/proxmox-notify/src/api/webhook.rs
+++ b/proxmox-notify/src/api/webhook.rs
@@ -9,7 +9,7 @@ use proxmox_section_config::typed::{convert_to_typed_array, lookup};
 
 use crate::api::http_err;
 use crate::api_types::{
-    DeleteableWebhookProperty, KeyAndBase64Val, WebhookConfig, WebhookConfigUpdater,
+    DeletableWebhookProperty, KeyAndBase64Val, WebhookConfig, WebhookConfigUpdater,
     WebhookPrivateConfig,
 };
 use crate::config::{ConfigEntity, PrivateConfigEntity};
@@ -131,7 +131,7 @@ pub fn update_endpoint(
     config: &mut Config,
     name: &str,
     config_updater: WebhookConfigUpdater,
-    delete: Option<&[DeleteableWebhookProperty]>,
+    delete: Option<&[DeletableWebhookProperty]>,
     digest: Option<ConfigDigest>,
 ) -> Result<(), HttpError> {
     super::verify_digest(config, digest)?;
@@ -147,11 +147,11 @@ pub fn update_endpoint(
     if let Some(delete) = delete {
         for deleteable_property in delete {
             match deleteable_property {
-                DeleteableWebhookProperty::Comment => endpoint.comment = None,
-                DeleteableWebhookProperty::Disable => endpoint.disable = None,
-                DeleteableWebhookProperty::Header => endpoint.header = Vec::new(),
-                DeleteableWebhookProperty::Body => endpoint.body = None,
-                DeleteableWebhookProperty::Secret => {
+                DeletableWebhookProperty::Comment => endpoint.comment = None,
+                DeletableWebhookProperty::Disable => endpoint.disable = None,
+                DeletableWebhookProperty::Header => endpoint.header = Vec::new(),
+                DeletableWebhookProperty::Body => endpoint.body = None,
+                DeletableWebhookProperty::Secret => {
                     config.private_config.insert(
                         name,
                         PrivateConfigEntity::Webhook(WebhookPrivateConfig {
@@ -385,8 +385,8 @@ mod tests {
             "webhook-endpoint",
             Default::default(),
             Some(&[
-                DeleteableWebhookProperty::Comment,
-                DeleteableWebhookProperty::Secret,
+                DeletableWebhookProperty::Comment,
+                DeletableWebhookProperty::Secret,
             ]),
             None,
         )?;
diff --git a/proxmox-notify/src/api_types/gotify.rs b/proxmox-notify/src/api_types/gotify.rs
index f74777472..f651eb61c 100644
--- a/proxmox-notify/src/api_types/gotify.rs
+++ b/proxmox-notify/src/api_types/gotify.rs
@@ -62,7 +62,7 @@ pub struct GotifyPrivateConfig {
 #[derive(Serialize, Deserialize)]
 #[serde(rename_all = "kebab-case")]
 /// The set of properties that can be deleted from a gotify endpoint configuration.
-pub enum DeleteableGotifyProperty {
+pub enum DeletableGotifyProperty {
     /// Delete `comment`
     Comment,
     /// Delete `disable`
diff --git a/proxmox-notify/src/api_types/matcher/mod.rs b/proxmox-notify/src/api_types/matcher/mod.rs
index e10ae6986..e65063c5e 100644
--- a/proxmox-notify/src/api_types/matcher/mod.rs
+++ b/proxmox-notify/src/api_types/matcher/mod.rs
@@ -358,7 +358,7 @@ impl MatcherConfig {
 #[derive(Serialize, Deserialize)]
 #[serde(rename_all = "kebab-case")]
 /// The set of matcher properties that can be deleted.
-pub enum DeleteableMatcherProperty {
+pub enum DeletableMatcherProperty {
     /// Delete `comment`
     Comment,
     /// Delete `disable`
diff --git a/proxmox-notify/src/api_types/sendmail.rs b/proxmox-notify/src/api_types/sendmail.rs
index fd7e457c2..2c22999f5 100644
--- a/proxmox-notify/src/api_types/sendmail.rs
+++ b/proxmox-notify/src/api_types/sendmail.rs
@@ -79,7 +79,7 @@ pub struct SendmailConfig {
 #[derive(Serialize, Deserialize)]
 #[serde(rename_all = "kebab-case")]
 /// The set of properties that can be deleted from a sendmail endpoint configuration.
-pub enum DeleteableSendmailProperty {
+pub enum DeletableSendmailProperty {
     /// Delete `author`
     Author,
     /// Delete `comment`
diff --git a/proxmox-notify/src/api_types/smtp.rs b/proxmox-notify/src/api_types/smtp.rs
index e7dd37ef3..d195fa2a8 100644
--- a/proxmox-notify/src/api_types/smtp.rs
+++ b/proxmox-notify/src/api_types/smtp.rs
@@ -102,7 +102,7 @@ pub struct SmtpConfig {
 #[derive(Serialize, Deserialize)]
 #[serde(rename_all = "kebab-case")]
 /// The set of properties that can be deleted from a smtp endpoint configuration.
-pub enum DeleteableSmtpProperty {
+pub enum DeletableSmtpProperty {
     /// Delete `author`
     Author,
     /// Delete `comment`
diff --git a/proxmox-notify/src/api_types/webhook.rs b/proxmox-notify/src/api_types/webhook.rs
index 68c2f381a..886323e48 100644
--- a/proxmox-notify/src/api_types/webhook.rs
+++ b/proxmox-notify/src/api_types/webhook.rs
@@ -151,7 +151,7 @@ pub struct WebhookPrivateConfig {
 #[derive(Serialize, Deserialize)]
 #[serde(rename_all = "kebab-case")]
 /// Webhook configuration properties that can be deleted.
-pub enum DeleteableWebhookProperty {
+pub enum DeletableWebhookProperty {
     /// Delete `comment`.
     Comment,
     /// Delete `disable`.
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 25/63] notify: context: parse builtin config only once
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (23 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 24/63] notify: api: api types: rename Deleteable* -> Deletable* Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 26/63] notify: context: parse proxy config in trait impl, not at the callsite Lukas Wagner
                   ` (38 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

The builtin config does not change during runtime, thus it makes sense
to change the signature of the context trait to let the `default_config`
method return a &'static SectionConfigData instead of &'static str.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/context/mod.rs  |  5 ++++-
 proxmox-notify/src/context/pbs.rs  | 11 +++++++++--
 proxmox-notify/src/context/pve.rs  | 12 ++++++++++--
 proxmox-notify/src/context/test.rs | 10 ++++++++--
 4 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/proxmox-notify/src/context/mod.rs b/proxmox-notify/src/context/mod.rs
index fd55dca14..edc147f4a 100644
--- a/proxmox-notify/src/context/mod.rs
+++ b/proxmox-notify/src/context/mod.rs
@@ -2,6 +2,9 @@ use std::fmt::{Debug, Display};
 use std::ops::Deref;
 use std::sync::Arc;
 
+use proxmox_section_config::typed::SectionConfigData;
+
+use crate::config::ConfigEntity;
 use crate::error::BoxedError;
 
 #[cfg(any(feature = "pve-context", feature = "pbs-context"))]
@@ -51,7 +54,7 @@ pub trait ContextImpl: Send + Sync + Debug {
     /// Proxy configuration for the current node
     fn http_proxy_config(&self) -> Option<String>;
     /// Return default config for built-in targets/matchers.
-    fn default_config(&self) -> &'static str;
+    fn default_config(&self) -> &'static SectionConfigData<ConfigEntity>;
     /// 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 f16e9ebdd..b76412ad1 100644
--- a/proxmox-notify/src/context/pbs.rs
+++ b/proxmox-notify/src/context/pbs.rs
@@ -1,11 +1,14 @@
 use std::path::Path;
+use std::sync::OnceLock;
 
+use proxmox_section_config::typed::{ApiSectionDataEntry, SectionConfigData};
 use serde::Deserialize;
 use tracing::error;
 
 use proxmox_schema::{ObjectSchema, Schema, StringSchema};
 use proxmox_section_config::{SectionConfig, SectionConfigPlugin};
 
+use crate::config::ConfigEntity;
 use crate::context::{ContextImpl, TemplateSource, common};
 use crate::error::BoxedError;
 
@@ -101,8 +104,12 @@ impl ContextImpl 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<ConfigEntity> {
+        static CONFIG: OnceLock<SectionConfigData<ConfigEntity>> = OnceLock::new();
+        CONFIG.get_or_init(|| {
+            ConfigEntity::parse_section_config("builtin-config", DEFAULT_CONFIG)
+                .expect("built-in notification config must be valid")
+        })
     }
 
     fn lookup_template(
diff --git a/proxmox-notify/src/context/pve.rs b/proxmox-notify/src/context/pve.rs
index bcfa0edff..1a5d33ca1 100644
--- a/proxmox-notify/src/context/pve.rs
+++ b/proxmox-notify/src/context/pve.rs
@@ -1,5 +1,9 @@
 use std::path::Path;
+use std::sync::OnceLock;
 
+use proxmox_section_config::typed::{ApiSectionDataEntry, SectionConfigData};
+
+use crate::config::ConfigEntity;
 use crate::context::{ContextImpl, TemplateSource, common};
 use crate::error::BoxedError;
 
@@ -51,8 +55,12 @@ impl ContextImpl for PVEContext {
         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<ConfigEntity> {
+        static CONFIG: OnceLock<SectionConfigData<ConfigEntity>> = OnceLock::new();
+        CONFIG.get_or_init(|| {
+            ConfigEntity::parse_section_config("builtin-config", DEFAULT_CONFIG)
+                .expect("built-in notification config must be valid")
+        })
     }
 
     fn lookup_template(
diff --git a/proxmox-notify/src/context/test.rs b/proxmox-notify/src/context/test.rs
index 8296dbf62..2e230464b 100644
--- a/proxmox-notify/src/context/test.rs
+++ b/proxmox-notify/src/context/test.rs
@@ -1,4 +1,9 @@
+use std::sync::OnceLock;
+
+use proxmox_section_config::typed::SectionConfigData;
+
 use crate::Context;
+use crate::config::ConfigEntity;
 use crate::context::ContextImpl;
 use crate::error::BoxedError;
 
@@ -30,8 +35,9 @@ impl ContextImpl for TestContext {
         None
     }
 
-    fn default_config(&self) -> &'static str {
-        ""
+    fn default_config(&self) -> &'static SectionConfigData<ConfigEntity> {
+        static CONFIG: OnceLock<SectionConfigData<ConfigEntity>> = OnceLock::new();
+        CONFIG.get_or_init(SectionConfigData::default)
     }
 
     fn lookup_template(
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 26/63] notify: context: parse proxy config in trait impl, not at the callsite
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (24 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 25/63] notify: context: parse builtin config only once Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 27/63] notify: gate sub-modules with the appropriate feature flags Lukas Wagner
                   ` (37 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

This makes it easier to at some point introduce different proxy schemes
for http vs. https URLs, and it also decouples proxmox-notify from the
concrete string format used to configure proxies.

The trait method was renamed to `proxy_config` to preemptively avoid any
confusion if we ever introduce a differentiation between http and https
proxies.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/Cargo.toml               |  5 ++++-
 proxmox-notify/src/context/mod.rs       |  3 ++-
 proxmox-notify/src/context/pbs.rs       | 11 ++++++++---
 proxmox-notify/src/context/pve.rs       |  9 +++++++--
 proxmox-notify/src/context/test.rs      |  5 +++--
 proxmox-notify/src/endpoints/gotify.rs  |  6 ++----
 proxmox-notify/src/endpoints/webhook.rs |  6 ++----
 7 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/proxmox-notify/Cargo.toml b/proxmox-notify/Cargo.toml
index 5f7ea3176..611aebba6 100644
--- a/proxmox-notify/Cargo.toml
+++ b/proxmox-notify/Cargo.toml
@@ -28,7 +28,7 @@ thiserror.workspace = true
 proxmox-api-macro = { workspace = true, optional = true }
 proxmox-base64 = { workspace = true, optional = true }
 proxmox-config-digest = { workspace = true, features = ["openssl"], optional = true }
-proxmox-http = { workspace = true, features = ["client-sync"], optional = true }
+proxmox-http = { workspace = true, optional = true }
 proxmox-http-error = { workspace = true, optional = true }
 proxmox-human-byte = { workspace = true, optional = true }
 proxmox-match-expression = { workspace = true, optional = true }
@@ -48,6 +48,8 @@ default = ["send-impl", "api-types"]
 api-impl = [
     "api-types",
     "dep:proxmox-config-digest",
+    "dep:proxmox-http",
+    "proxmox-http/http-helpers",
     "dep:proxmox-http-error",
     "dep:proxmox-section-config",
 ]
@@ -67,6 +69,7 @@ send-impl = [
     "dep:percent-encoding",
     "dep:proxmox-base64",
     "dep:proxmox-http",
+    "proxmox-http/client-sync",
     "dep:proxmox-human-byte",
     "dep:proxmox-section-config",
     "dep:proxmox-sendmail",
diff --git a/proxmox-notify/src/context/mod.rs b/proxmox-notify/src/context/mod.rs
index edc147f4a..c31e108fd 100644
--- a/proxmox-notify/src/context/mod.rs
+++ b/proxmox-notify/src/context/mod.rs
@@ -2,6 +2,7 @@ use std::fmt::{Debug, Display};
 use std::ops::Deref;
 use std::sync::Arc;
 
+use proxmox_http::ProxyConfig;
 use proxmox_section_config::typed::SectionConfigData;
 
 use crate::config::ConfigEntity;
@@ -52,7 +53,7 @@ pub trait ContextImpl: Send + Sync + Debug {
     /// Default from address for sendmail-based targets
     fn default_sendmail_from(&self) -> String;
     /// Proxy configuration for the current node
-    fn http_proxy_config(&self) -> Option<String>;
+    fn proxy_config(&self) -> Result<Option<ProxyConfig>, BoxedError>;
     /// Return default config for built-in targets/matchers.
     fn default_config(&self) -> &'static SectionConfigData<ConfigEntity>;
     /// Return the path of `filename` from `source` and a certain (optional) `namespace`
diff --git a/proxmox-notify/src/context/pbs.rs b/proxmox-notify/src/context/pbs.rs
index b76412ad1..7d3c51677 100644
--- a/proxmox-notify/src/context/pbs.rs
+++ b/proxmox-notify/src/context/pbs.rs
@@ -1,11 +1,12 @@
 use std::path::Path;
 use std::sync::OnceLock;
 
-use proxmox_section_config::typed::{ApiSectionDataEntry, SectionConfigData};
 use serde::Deserialize;
 use tracing::error;
 
+use proxmox_http::ProxyConfig;
 use proxmox_schema::{ObjectSchema, Schema, StringSchema};
+use proxmox_section_config::typed::{ApiSectionDataEntry, SectionConfigData};
 use proxmox_section_config::{SectionConfig, SectionConfigPlugin};
 
 use crate::config::ConfigEntity;
@@ -99,9 +100,13 @@ impl ContextImpl for PBSContext {
             .unwrap_or_else(|| String::from("root"))
     }
 
-    fn http_proxy_config(&self) -> Option<String> {
+    fn proxy_config(&self) -> Result<Option<ProxyConfig>, BoxedError> {
         let content = common::attempt_file_read(PBS_NODE_CFG_FILENAME);
-        content.and_then(|content| common::lookup_datacenter_config_key(&content, "http-proxy"))
+        content
+            .and_then(|content| common::lookup_datacenter_config_key(&content, "http-proxy"))
+            .map(|url| ProxyConfig::parse_proxy_url(&url))
+            .transpose()
+            .map_err(Into::into)
     }
 
     fn default_config(&self) -> &'static SectionConfigData<ConfigEntity> {
diff --git a/proxmox-notify/src/context/pve.rs b/proxmox-notify/src/context/pve.rs
index 1a5d33ca1..a020b5cb4 100644
--- a/proxmox-notify/src/context/pve.rs
+++ b/proxmox-notify/src/context/pve.rs
@@ -1,6 +1,7 @@
 use std::path::Path;
 use std::sync::OnceLock;
 
+use proxmox_http::ProxyConfig;
 use proxmox_section_config::typed::{ApiSectionDataEntry, SectionConfigData};
 
 use crate::config::ConfigEntity;
@@ -50,9 +51,13 @@ impl ContextImpl for PVEContext {
             .unwrap_or_else(|| String::from("root"))
     }
 
-    fn http_proxy_config(&self) -> Option<String> {
+    fn proxy_config(&self) -> Result<Option<ProxyConfig>, BoxedError> {
         let content = common::attempt_file_read("/etc/pve/datacenter.cfg");
-        content.and_then(|content| common::lookup_datacenter_config_key(&content, "http_proxy"))
+        content
+            .and_then(|content| common::lookup_datacenter_config_key(&content, "http_proxy"))
+            .map(|url| ProxyConfig::parse_proxy_url(&url))
+            .transpose()
+            .map_err(Into::into)
     }
 
     fn default_config(&self) -> &'static SectionConfigData<ConfigEntity> {
diff --git a/proxmox-notify/src/context/test.rs b/proxmox-notify/src/context/test.rs
index 2e230464b..6061e8c4d 100644
--- a/proxmox-notify/src/context/test.rs
+++ b/proxmox-notify/src/context/test.rs
@@ -1,5 +1,6 @@
 use std::sync::OnceLock;
 
+use proxmox_http::ProxyConfig;
 use proxmox_section_config::typed::SectionConfigData;
 
 use crate::Context;
@@ -31,8 +32,8 @@ impl ContextImpl for TestContext {
         "root".into()
     }
 
-    fn http_proxy_config(&self) -> Option<String> {
-        None
+    fn proxy_config(&self) -> Result<Option<ProxyConfig>, BoxedError> {
+        Ok(None)
     }
 
     fn default_config(&self) -> &'static SectionConfigData<ConfigEntity> {
diff --git a/proxmox-notify/src/endpoints/gotify.rs b/proxmox-notify/src/endpoints/gotify.rs
index 5341f822f..cf7d4cc68 100644
--- a/proxmox-notify/src/endpoints/gotify.rs
+++ b/proxmox-notify/src/endpoints/gotify.rs
@@ -4,7 +4,7 @@ use std::time::Duration;
 use serde_json::json;
 
 use proxmox_http::client::sync::Client;
-use proxmox_http::{HttpClient, HttpOptions, ProxyConfig};
+use proxmox_http::{HttpClient, HttpOptions};
 
 use crate::api_types::{GotifyConfig, GotifyPrivateConfig};
 use crate::renderer::TemplateType;
@@ -83,9 +83,7 @@ impl Endpoint for GotifyEndpoint {
         ]);
 
         let proxy_config = context
-            .http_proxy_config()
-            .map(|url| ProxyConfig::parse_proxy_url(&url))
-            .transpose()
+            .proxy_config()
             .map_err(|err| Error::invalid_config_with_source("invalid proxy configuration", err))?;
 
         let options = HttpOptions {
diff --git a/proxmox-notify/src/endpoints/webhook.rs b/proxmox-notify/src/endpoints/webhook.rs
index 49ea29c1e..da2e189b4 100644
--- a/proxmox-notify/src/endpoints/webhook.rs
+++ b/proxmox-notify/src/endpoints/webhook.rs
@@ -18,7 +18,7 @@ use percent_encoding::AsciiSet;
 use serde_json::{Map, Value, json};
 
 use proxmox_http::client::sync::Client;
-use proxmox_http::{HttpClient, HttpOptions, ProxyConfig};
+use proxmox_http::{HttpClient, HttpOptions};
 
 use crate::api_types::{HttpMethod, WebhookConfig, WebhookPrivateConfig};
 use crate::renderer::TemplateType;
@@ -61,9 +61,7 @@ impl Endpoint for WebhookEndpoint {
 impl WebhookEndpoint {
     fn create_client(&self, context: &Context) -> Result<Client, Error> {
         let proxy_config = context
-            .http_proxy_config()
-            .map(|url| ProxyConfig::parse_proxy_url(&url))
-            .transpose()
+            .proxy_config()
             .map_err(|err| Error::invalid_config_with_source("invalid proxy configuration", err))?;
 
         let options = HttpOptions {
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 27/63] notify: gate sub-modules with the appropriate feature flags
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (25 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 26/63] notify: context: parse proxy config in trait impl, not at the callsite Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 28/63] notify: fold mail-forwarder feature into send-impl Lukas Wagner
                   ` (36 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

This is to ensure that we only compile the code that we really need for
the enabled set of features.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/Cargo.toml |  2 +-
 proxmox-notify/src/lib.rs | 33 +++++++++++++++++++++------------
 2 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/proxmox-notify/Cargo.toml b/proxmox-notify/Cargo.toml
index 611aebba6..ca5dc5d45 100644
--- a/proxmox-notify/Cargo.toml
+++ b/proxmox-notify/Cargo.toml
@@ -44,7 +44,7 @@ proxmox-uuid = { workspace = true, features = ["serde"] }
 pretty_assertions.workspace = true
 
 [features]
-default = ["send-impl", "api-types"]
+default = []
 api-impl = [
     "api-types",
     "dep:proxmox-config-digest",
diff --git a/proxmox-notify/src/lib.rs b/proxmox-notify/src/lib.rs
index 925465bf5..c446b52de 100644
--- a/proxmox-notify/src/lib.rs
+++ b/proxmox-notify/src/lib.rs
@@ -4,23 +4,32 @@
 #[cfg(feature = "api-impl")]
 pub mod api;
 
-pub mod config;
-pub mod context;
-pub mod endpoints;
-pub mod renderer;
-
-#[cfg(feature = "send-impl")]
-pub mod send;
-
 #[cfg(feature = "api-types")]
 pub mod api_types;
 
+#[cfg(any(feature = "api-impl", feature = "send-impl"))]
+mod config;
+#[cfg(any(feature = "api-impl", feature = "send-impl"))]
+pub use config::{Config, ConfigEntity, PrivateConfigEntity};
+
+#[cfg(any(feature = "api-impl", feature = "send-impl"))]
+pub mod context;
+#[cfg(any(feature = "api-impl", feature = "send-impl"))]
+pub use context::{Context, ContextImpl};
+
+#[cfg(feature = "send-impl")]
+mod endpoints;
+
+#[cfg(feature = "send-impl")]
+mod renderer;
+
+#[cfg(feature = "send-impl")]
+mod send;
+#[cfg(feature = "send-impl")]
+pub use send::{send, test_target};
+
 mod error;
 pub use error::Error;
 
-pub use config::Config;
-pub use context::Context;
-pub use context::ContextImpl;
-
 mod notification;
 pub use notification::*;
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 28/63] notify: fold mail-forwarder feature into send-impl
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (26 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 27/63] notify: gate sub-modules with the appropriate feature flags Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 29/63] notify: forwarded mails: don't hardcode severity and metadata fields Lukas Wagner
                   ` (35 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

In the future, all users of proxmox-notify will use a single
notification worker to process queued notifications, which includes
forwarded mails as well. Hence it makes sense to merge both features.
The subject and body of the forwarded mail is now only parsed when the
mail is actually processed by an endpoint implementation. This makes
sure that the basic Notification type does not depend on the mail-parser
crate.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/Cargo.toml                   |  3 ++-
 proxmox-notify/src/endpoints/common/mail.rs | 13 +++++++++++++
 proxmox-notify/src/endpoints/gotify.rs      |  5 +++--
 proxmox-notify/src/endpoints/sendmail.rs    |  1 -
 proxmox-notify/src/endpoints/smtp.rs        |  3 ---
 proxmox-notify/src/endpoints/webhook.rs     |  5 +++--
 proxmox-notify/src/notification.rs          | 16 +---------------
 7 files changed, 22 insertions(+), 24 deletions(-)

diff --git a/proxmox-notify/Cargo.toml b/proxmox-notify/Cargo.toml
index ca5dc5d45..1971f5b60 100644
--- a/proxmox-notify/Cargo.toml
+++ b/proxmox-notify/Cargo.toml
@@ -66,6 +66,7 @@ send-impl = [
     "dep:lettre",
     "dep:handlebars",
     "dep:proxmox-config-digest",
+    "dep:mail-parser",
     "dep:percent-encoding",
     "dep:proxmox-base64",
     "dep:proxmox-http",
@@ -73,9 +74,9 @@ send-impl = [
     "dep:proxmox-human-byte",
     "dep:proxmox-section-config",
     "dep:proxmox-sendmail",
+    "proxmox-sendmail/mail-forwarder",
     "dep:proxmox-sys",
 ]
-mail-forwarder = ["dep:mail-parser", "dep:proxmox-sys", "proxmox-sendmail/mail-forwarder"]
 pve-context = ["dep:proxmox-sys", "legacy-matchers"]
 pbs-context = ["dep:proxmox-sys", "legacy-matchers"]
 legacy-matchers = []
diff --git a/proxmox-notify/src/endpoints/common/mail.rs b/proxmox-notify/src/endpoints/common/mail.rs
index 736f2ac66..fac4e759c 100644
--- a/proxmox-notify/src/endpoints/common/mail.rs
+++ b/proxmox-notify/src/endpoints/common/mail.rs
@@ -1,4 +1,5 @@
 use crate::Context;
+use crate::Error;
 
 /// Get list of email recipients from a list of email addresses and users.
 ///
@@ -34,6 +35,18 @@ pub(crate) fn get_recipients(
     recipients
 }
 
+/// Parse raw email message and return subject and plaintext body
+pub(crate) fn parse_subject_and_plaintext_body(raw_mail: &[u8]) -> Result<(String, String), Error> {
+    let message = mail_parser::MessageParser::default()
+        .parse(raw_mail)
+        .ok_or_else(|| Error::invalid_forwarded_message("could not parse forwarded email"))?;
+
+    let title = message.subject().unwrap_or_default().into();
+    let body = message.body_text(0).unwrap_or_default().into();
+
+    Ok((title, body))
+}
+
 #[cfg(test)]
 mod tests {
     use crate::context::test;
diff --git a/proxmox-notify/src/endpoints/gotify.rs b/proxmox-notify/src/endpoints/gotify.rs
index cf7d4cc68..bdb1e487d 100644
--- a/proxmox-notify/src/endpoints/gotify.rs
+++ b/proxmox-notify/src/endpoints/gotify.rs
@@ -7,6 +7,7 @@ use proxmox_http::client::sync::Client;
 use proxmox_http::{HttpClient, HttpOptions};
 
 use crate::api_types::{GotifyConfig, GotifyPrivateConfig};
+use crate::endpoints::common::mail;
 use crate::renderer::TemplateType;
 use crate::{Content, Context, Error, Notification, Severity, renderer};
 
@@ -48,8 +49,8 @@ impl Endpoint for GotifyEndpoint {
 
                 (rendered_title, rendered_message)
             }
-            #[cfg(feature = "mail-forwarder")]
-            Content::ForwardedMail { title, body, .. } => (title.clone(), body.clone()),
+
+            Content::ForwardedMail { raw, .. } => mail::parse_subject_and_plaintext_body(raw)?,
         };
 
         // We don't have a TemplateRenderer::Markdown yet, so simply put everything
diff --git a/proxmox-notify/src/endpoints/sendmail.rs b/proxmox-notify/src/endpoints/sendmail.rs
index bbed31b4f..0bad792f7 100644
--- a/proxmox-notify/src/endpoints/sendmail.rs
+++ b/proxmox-notify/src/endpoints/sendmail.rs
@@ -63,7 +63,6 @@ impl Endpoint for SendmailEndpoint {
                     Error::other_with_source("could not send mail via sendmail", err)
                 })
             }
-            #[cfg(feature = "mail-forwarder")]
             Content::ForwardedMail { raw, uid, .. } => {
                 Mail::forward(&recipients_str, &mailfrom, raw, *uid).map_err(|err| {
                     Error::other_with_source("could not forward mail via sendmail", err)
diff --git a/proxmox-notify/src/endpoints/smtp.rs b/proxmox-notify/src/endpoints/smtp.rs
index fa0810fbb..43dc1f7f4 100644
--- a/proxmox-notify/src/endpoints/smtp.rs
+++ b/proxmox-notify/src/endpoints/smtp.rs
@@ -132,7 +132,6 @@ impl Endpoint for SmtpEndpoint {
                         Error::invalid_config_with_source("could not build email message", err)
                     })?
             }
-            #[cfg(feature = "mail-forwarder")]
             Content::ForwardedMail { raw, .. } => build_forwarded_message(email_builder, raw)?,
         };
 
@@ -161,7 +160,6 @@ impl Endpoint for SmtpEndpoint {
 }
 
 /// Construct a lettre `Message` from a raw email message.
-#[cfg(feature = "mail-forwarder")]
 fn build_forwarded_message(
     email_builder: lettre::message::MessageBuilder,
     raw: &[u8],
@@ -312,7 +310,6 @@ mod tests {
         );
     }
 
-    #[cfg(feature = "mail-forwarder")]
     #[test]
     fn test_forward_message_from_raw() {
         use lettre::message::header::Date;
diff --git a/proxmox-notify/src/endpoints/webhook.rs b/proxmox-notify/src/endpoints/webhook.rs
index da2e189b4..2eaa71633 100644
--- a/proxmox-notify/src/endpoints/webhook.rs
+++ b/proxmox-notify/src/endpoints/webhook.rs
@@ -21,6 +21,7 @@ use proxmox_http::client::sync::Client;
 use proxmox_http::{HttpClient, HttpOptions};
 
 use crate::api_types::{HttpMethod, WebhookConfig, WebhookPrivateConfig};
+use crate::endpoints::common::mail;
 use crate::renderer::TemplateType;
 use crate::{Content, Context, Error, Notification, renderer};
 
@@ -93,8 +94,8 @@ impl WebhookEndpoint {
 
                 (rendered_title, rendered_message)
             }
-            #[cfg(feature = "mail-forwarder")]
-            Content::ForwardedMail { title, body, .. } => (title.clone(), body.clone()),
+
+            Content::ForwardedMail { raw, .. } => mail::parse_subject_and_plaintext_body(raw)?,
         };
 
         let mut fields = Map::new();
diff --git a/proxmox-notify/src/notification.rs b/proxmox-notify/src/notification.rs
index 426a2259a..f5b6ab6a6 100644
--- a/proxmox-notify/src/notification.rs
+++ b/proxmox-notify/src/notification.rs
@@ -62,15 +62,10 @@ pub enum Content {
         /// Data that can be used for template rendering.
         data: Value,
     },
-    #[cfg(feature = "mail-forwarder")]
     #[serde(rename_all = "kebab-case")]
     ForwardedMail {
         /// Raw mail contents
         raw: Vec<u8>,
-        /// Fallback title
-        title: String,
-        /// Fallback body
-        body: String,
         /// UID to use when calling sendmail
         #[allow(dead_code)] // Unused in some feature flag permutations
         uid: Option<u32>,
@@ -120,15 +115,8 @@ impl Notification {
             id: Uuid::generate(),
         }
     }
-    #[cfg(feature = "mail-forwarder")]
+
     pub fn new_forwarded_mail(raw_mail: &[u8], uid: Option<u32>) -> Result<Self, Error> {
-        let message = mail_parser::MessageParser::default()
-            .parse(raw_mail)
-            .ok_or_else(|| Error::invalid_forwarded_message("could not parse forwarded email"))?;
-
-        let title = message.subject().unwrap_or_default().into();
-        let body = message.body_text(0).unwrap_or_default().into();
-
         let mut additional_fields = HashMap::new();
         additional_fields.insert("hostname".into(), proxmox_sys::nodename().into());
         additional_fields.insert("type".into(), "system-mail".into());
@@ -139,8 +127,6 @@ impl Notification {
             // it is not filtered out.
             content: Content::ForwardedMail {
                 raw: raw_mail.into(),
-                title,
-                body,
                 uid,
             },
             metadata: Metadata {
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 29/63] notify: forwarded mails: don't hardcode severity and metadata fields
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (27 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 28/63] notify: fold mail-forwarder feature into send-impl Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 30/63] notify: don't pass uid when instantiating forwarded mail notifications Lukas Wagner
                   ` (34 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

These should rather be passed by proxmox-mail-forward as function
parameters.

Also, since we need to take ownership of the mail contents, pass a Vec
directly instead of calling `.into()`.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/notification.rs | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/proxmox-notify/src/notification.rs b/proxmox-notify/src/notification.rs
index f5b6ab6a6..e814ce97f 100644
--- a/proxmox-notify/src/notification.rs
+++ b/proxmox-notify/src/notification.rs
@@ -116,22 +116,17 @@ impl Notification {
         }
     }
 
-    pub fn new_forwarded_mail(raw_mail: &[u8], uid: Option<u32>) -> Result<Self, Error> {
-        let mut additional_fields = HashMap::new();
-        additional_fields.insert("hostname".into(), proxmox_sys::nodename().into());
-        additional_fields.insert("type".into(), "system-mail".into());
-
+    pub fn new_forwarded_mail(
+        severity: Severity,
+        raw_mail: Vec<u8>,
+        fields: HashMap<String, String>,
+        uid: Option<u32>,
+    ) -> Result<Self, Error> {
         Ok(Self {
-            // Unfortunately we cannot reasonably infer the severity from the
-            // mail contents, so just set it to the highest for now so that
-            // it is not filtered out.
-            content: Content::ForwardedMail {
-                raw: raw_mail.into(),
-                uid,
-            },
+            content: Content::ForwardedMail { raw: raw_mail, uid },
             metadata: Metadata {
-                severity: Severity::Unknown,
-                additional_fields,
+                severity,
+                additional_fields: fields,
                 timestamp: proxmox_time::epoch_i64(),
             },
             id: Uuid::generate(),
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 30/63] notify: don't pass uid when instantiating forwarded mail notifications
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (28 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 29/63] notify: forwarded mails: don't hardcode severity and metadata fields Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 31/63] notify: derive PartialEq for Notification type Lukas Wagner
                   ` (33 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

In the future, forwarded mails will be sent by the notification worker,
not proxmox-mail-forward. Sendmail shows a warning when called from a
setuid process (such as proxmox-mail-forward). Previously the fix was to
pass the real uid when spawning the sendmail process. With the worker
process, this is not needed anymore.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/endpoints/sendmail.rs | 4 ++--
 proxmox-notify/src/notification.rs       | 6 +-----
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/proxmox-notify/src/endpoints/sendmail.rs b/proxmox-notify/src/endpoints/sendmail.rs
index 0bad792f7..e12fc4a20 100644
--- a/proxmox-notify/src/endpoints/sendmail.rs
+++ b/proxmox-notify/src/endpoints/sendmail.rs
@@ -63,8 +63,8 @@ impl Endpoint for SendmailEndpoint {
                     Error::other_with_source("could not send mail via sendmail", err)
                 })
             }
-            Content::ForwardedMail { raw, uid, .. } => {
-                Mail::forward(&recipients_str, &mailfrom, raw, *uid).map_err(|err| {
+            Content::ForwardedMail { raw, .. } => {
+                Mail::forward(&recipients_str, &mailfrom, raw, None).map_err(|err| {
                     Error::other_with_source("could not forward mail via sendmail", err)
                 })
             }
diff --git a/proxmox-notify/src/notification.rs b/proxmox-notify/src/notification.rs
index e814ce97f..187163d29 100644
--- a/proxmox-notify/src/notification.rs
+++ b/proxmox-notify/src/notification.rs
@@ -66,9 +66,6 @@ pub enum Content {
     ForwardedMail {
         /// Raw mail contents
         raw: Vec<u8>,
-        /// UID to use when calling sendmail
-        #[allow(dead_code)] // Unused in some feature flag permutations
-        uid: Option<u32>,
     },
 }
 
@@ -120,10 +117,9 @@ impl Notification {
         severity: Severity,
         raw_mail: Vec<u8>,
         fields: HashMap<String, String>,
-        uid: Option<u32>,
     ) -> Result<Self, Error> {
         Ok(Self {
-            content: Content::ForwardedMail { raw: raw_mail, uid },
+            content: Content::ForwardedMail { raw: raw_mail },
             metadata: Metadata {
                 severity,
                 additional_fields: fields,
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 31/63] notify: derive PartialEq for Notification type
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (29 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 30/63] notify: don't pass uid when instantiating forwarded mail notifications Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 32/63] notify: add getters for severity and fields on " Lukas Wagner
                   ` (32 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/notification.rs | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/proxmox-notify/src/notification.rs b/proxmox-notify/src/notification.rs
index 187163d29..571be534c 100644
--- a/proxmox-notify/src/notification.rs
+++ b/proxmox-notify/src/notification.rs
@@ -51,7 +51,7 @@ impl FromStr for Severity {
     }
 }
 
-#[derive(Debug, Clone, Serialize, Deserialize)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
 #[serde(rename_all = "kebab-case")]
 pub enum Content {
     /// Title and body will be rendered as a template
@@ -69,7 +69,7 @@ pub enum Content {
     },
 }
 
-#[derive(Debug, Clone, Serialize, Deserialize)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
 #[serde(rename_all = "kebab-case")]
 pub struct Metadata {
     /// Notification severity
@@ -80,7 +80,7 @@ pub struct Metadata {
     pub(crate) additional_fields: HashMap<String, String>,
 }
 
-#[derive(Debug, Clone, Serialize, Deserialize)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
 #[serde(rename_all = "kebab-case")]
 /// Notification which can be sent
 pub struct Notification {
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 32/63] notify: add getters for severity and fields on Notification type
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (30 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 31/63] notify: derive PartialEq for Notification type Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 33/63] notify: add test suite for " Lukas Wagner
                   ` (31 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/notification.rs | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/proxmox-notify/src/notification.rs b/proxmox-notify/src/notification.rs
index 571be534c..4d938b846 100644
--- a/proxmox-notify/src/notification.rs
+++ b/proxmox-notify/src/notification.rs
@@ -138,4 +138,19 @@ impl Notification {
     pub fn timestamp(&self) -> i64 {
         self.metadata.timestamp
     }
+
+    /// Return the notification's severity.
+    pub fn severity(&self) -> Severity {
+        self.metadata.severity
+    }
+
+    /// Get access to the notification's metadata fields.
+    pub fn fields(&self) -> &HashMap<String, String> {
+        &self.metadata.additional_fields
+    }
+
+    /// Get mutable access to the notification's metadata fields.
+    pub fn fields_mut(&mut self) -> &mut HashMap<String, String> {
+        &mut self.metadata.additional_fields
+    }
 }
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 33/63] notify: add test suite for Notification type
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (31 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 32/63] notify: add getters for severity and fields on " Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 34/63] notify: serialize raw, forwarded mail content as base64 Lukas Wagner
                   ` (30 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/notification.rs | 110 +++++++++++++++++++++++++++++
 1 file changed, 110 insertions(+)

diff --git a/proxmox-notify/src/notification.rs b/proxmox-notify/src/notification.rs
index 4d938b846..45ab08b87 100644
--- a/proxmox-notify/src/notification.rs
+++ b/proxmox-notify/src/notification.rs
@@ -154,3 +154,113 @@ impl Notification {
         &mut self.metadata.additional_fields
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use serde_json::json;
+
+    use super::*;
+
+    const TEST_MAIL: &[u8] = include_bytes!("../testdata/test1.msg");
+
+    const ALL_SEVERITIES: [Severity; 5] = [
+        Severity::Info,
+        Severity::Notice,
+        Severity::Warning,
+        Severity::Error,
+        Severity::Unknown,
+    ];
+
+    #[test]
+    fn severity_string_roundtrip() {
+        for severity in ALL_SEVERITIES {
+            let parsed: Severity = severity.to_string().parse().unwrap();
+            assert_eq!(parsed, severity);
+        }
+    }
+
+    #[test]
+    fn severity_display_matches_serde() {
+        for severity in ALL_SEVERITIES {
+            let serialized = serde_json::to_value(severity).unwrap();
+            assert_eq!(serialized, Value::String(severity.to_string()));
+        }
+    }
+
+    #[test]
+    fn severity_from_invalid_str() {
+        assert!("".parse::<Severity>().is_err());
+        assert!("Info".parse::<Severity>().is_err());
+        assert!("critical".parse::<Severity>().is_err());
+    }
+
+    #[test]
+    fn severity_ordering() {
+        assert!(Severity::Info < Severity::Notice);
+        assert!(Severity::Notice < Severity::Warning);
+        assert!(Severity::Warning < Severity::Error);
+    }
+
+    #[test]
+    fn from_template() {
+        let fields = HashMap::from([("hostname".to_string(), "pve".to_string())]);
+        let data = json!({"key": "value"});
+
+        let notification =
+            Notification::from_template(Severity::Warning, "test", data.clone(), fields.clone());
+
+        assert_eq!(notification.severity(), Severity::Warning);
+        assert_eq!(notification.fields(), &fields);
+        assert_eq!(
+            notification.content,
+            Content::Template {
+                template_name: "test".into(),
+                data,
+            }
+        );
+    }
+
+    #[test]
+    fn new_forwarded_mail() {
+        let raw = TEST_MAIL.to_vec();
+
+        let notification =
+            Notification::new_forwarded_mail(Severity::Unknown, raw.clone(), HashMap::new())
+                .unwrap();
+
+        assert_eq!(notification.severity(), Severity::Unknown);
+        assert!(notification.fields().is_empty());
+        assert_eq!(notification.content, Content::ForwardedMail { raw });
+    }
+
+    #[test]
+    fn fields_mut() {
+        let mut notification =
+            Notification::from_template(Severity::Info, "test", Value::Null, HashMap::new());
+
+        notification
+            .fields_mut()
+            .insert("type".into(), "vzdump".into());
+
+        assert_eq!(
+            notification.fields().get("type").map(String::as_str),
+            Some("vzdump")
+        );
+    }
+
+    #[test]
+    fn serde_roundtrip() {
+        let fields = HashMap::from([("hostname".to_string(), "pve".to_string())]);
+        let notifications = [
+            Notification::from_template(Severity::Error, "test", json!({"a": [1, 2]}), fields),
+            Notification::new_forwarded_mail(Severity::Info, TEST_MAIL.to_vec(), HashMap::new())
+                .unwrap(),
+        ];
+
+        for notification in notifications {
+            let serialized = serde_json::to_string(&notification).unwrap();
+            let deserialized: Notification = serde_json::from_str(&serialized).unwrap();
+            assert_eq!(deserialized, notification);
+        }
+    }
+}
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 34/63] notify: serialize raw, forwarded mail content as base64
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (32 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 33/63] notify: add test suite for " Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 35/63] notify: unify code paths for legacy-sendmail and regular notifications Lukas Wagner
                   ` (29 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

base64 is much more space-efficient than a JSON number array for
storing binary data. In an array of numbers, each byte consumes 2-4
bytes of space (1-3 digits plus a comma), while base64 has a constant
1.33x overhead.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/Cargo.toml          |  4 +---
 proxmox-notify/src/notification.rs | 37 ++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/proxmox-notify/Cargo.toml b/proxmox-notify/Cargo.toml
index 1971f5b60..e47912d11 100644
--- a/proxmox-notify/Cargo.toml
+++ b/proxmox-notify/Cargo.toml
@@ -26,7 +26,7 @@ serde_regex = { workspace = true, optional = true }
 thiserror.workspace = true
 
 proxmox-api-macro = { workspace = true, optional = true }
-proxmox-base64 = { workspace = true, optional = true }
+proxmox-base64 = { workspace = true, features = ["serde"]}
 proxmox-config-digest = { workspace = true, features = ["openssl"], optional = true }
 proxmox-http = { workspace = true, optional = true }
 proxmox-http-error = { workspace = true, optional = true }
@@ -55,7 +55,6 @@ api-impl = [
 ]
 api-types = [
     "dep:proxmox-api-macro",
-    "dep:proxmox-base64",
     "dep:proxmox-match-expression",
     "dep:regex",
     "dep:serde_regex",
@@ -68,7 +67,6 @@ send-impl = [
     "dep:proxmox-config-digest",
     "dep:mail-parser",
     "dep:percent-encoding",
-    "dep:proxmox-base64",
     "dep:proxmox-http",
     "proxmox-http/client-sync",
     "dep:proxmox-human-byte",
diff --git a/proxmox-notify/src/notification.rs b/proxmox-notify/src/notification.rs
index 45ab08b87..06b6e67e7 100644
--- a/proxmox-notify/src/notification.rs
+++ b/proxmox-notify/src/notification.rs
@@ -65,6 +65,10 @@ pub enum Content {
     #[serde(rename_all = "kebab-case")]
     ForwardedMail {
         /// Raw mail contents
+        #[serde(
+            serialize_with = "proxmox_base64::serialize_as_base64",
+            deserialize_with = "proxmox_base64::deserialize_from_base64"
+        )]
         raw: Vec<u8>,
     },
 }
@@ -248,6 +252,39 @@ mod tests {
         );
     }
 
+    #[test]
+    fn forwarded_mail_base64_roundtrip() {
+        // Not valid UTF-8 and not a multiple of three bytes, so the encoding needs padding.
+        let content = Content::ForwardedMail {
+            raw: b"\xff\x00mai".to_vec(),
+        };
+
+        let serialized = serde_json::to_value(&content).unwrap();
+        assert_eq!(serialized, json!({"forwarded-mail": {"raw": "/wBtYWk="}}));
+
+        let deserialized: Content = serde_json::from_value(serialized).unwrap();
+        assert_eq!(deserialized, content);
+
+        let content = Content::ForwardedMail {
+            raw: TEST_MAIL.to_vec(),
+        };
+
+        let serialized = serde_json::to_value(&content).unwrap();
+        assert_eq!(
+            serialized["forwarded-mail"]["raw"],
+            proxmox_base64::encode(TEST_MAIL)
+        );
+
+        let deserialized: Content = serde_json::from_value(serialized).unwrap();
+        assert_eq!(deserialized, content);
+    }
+
+    #[test]
+    fn forwarded_mail_base64_invalid() {
+        let result = serde_json::from_value::<Content>(json!({"forwarded-mail": {"raw": "$$$"}}));
+        assert!(result.is_err());
+    }
+
     #[test]
     fn serde_roundtrip() {
         let fields = HashMap::from([("hostname".to_string(), "pve".to_string())]);
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 35/63] notify: unify code paths for legacy-sendmail and regular notifications
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (33 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 34/63] notify: serialize raw, forwarded mail content as base64 Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 36/63] notify: add backwards-compat note to Notification type Lukas Wagner
                   ` (28 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

In the future, we will introduce a per-product notification queue and
notification history. Given these changed semantics, it is much easier
if 'legacy-style', regular, and test notifications can be handled
through the same code paths.

This is achieved by introducing a 'recipient' field in the Notification
struct. It defaults to 'matcher', which just uses the configured
matchers to determine which targets shall receive the notification. The
'email' variant allows us to pass a subset of `SendmailConfig`; when
sending there will be an implicitly created sendmail target that is the
sole notified endpoint for this notification. Finally, there is also a
'target' mode, which allows us to deliver a notification straight to a
single configured target, which will be useful to unify the code paths
for test notifications.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/notification.rs | 40 +++++++++++++
 proxmox-notify/src/send.rs         | 93 ++++++++++++++++++++++--------
 2 files changed, 108 insertions(+), 25 deletions(-)

diff --git a/proxmox-notify/src/notification.rs b/proxmox-notify/src/notification.rs
index 06b6e67e7..b3b93b545 100644
--- a/proxmox-notify/src/notification.rs
+++ b/proxmox-notify/src/notification.rs
@@ -84,6 +84,36 @@ pub struct Metadata {
     pub(crate) additional_fields: HashMap<String, String>,
 }
 
+#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq)]
+#[serde(rename_all = "kebab-case")]
+/// Determine how the notification shall be sent.
+pub enum Recipient {
+    /// Use matchers to determine which targets shall be notified.
+    ///
+    /// This is the default mode of operation, use this unless you have a good
+    /// reason not to.
+    #[default]
+    Matcher,
+    /// Deliver notification directly to a target, identified by its ID.
+    ///
+    /// This is useful for test notifications.
+    Target(String),
+    /// Deliver notification to an ephemeral sendmail target with given list of recipients.
+    ///
+    /// This is mainly for handling the legacy-sendmail mode in PVE and PBS.
+    Email(EmailRecipient),
+}
+
+#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)]
+#[serde(rename_all = "kebab-case")]
+/// Parameters for [`Recipient::Email`]-based recipients.
+pub struct EmailRecipient {
+    /// List of email addresses to send mails to.
+    pub mailto: Vec<String>,
+    /// Email author
+    pub author: Option<String>,
+}
+
 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
 #[serde(rename_all = "kebab-case")]
 /// Notification which can be sent
@@ -94,6 +124,9 @@ pub struct Notification {
     pub(crate) metadata: Metadata,
     /// Unique ID
     pub(crate) id: Uuid,
+    #[serde(default)]
+    /// The recipient of the notification.
+    pub(crate) recipient: Recipient,
 }
 
 impl Notification {
@@ -114,6 +147,7 @@ impl Notification {
                 data: template_data,
             },
             id: Uuid::generate(),
+            recipient: Recipient::Matcher,
         }
     }
 
@@ -130,6 +164,7 @@ impl Notification {
                 timestamp: proxmox_time::epoch_i64(),
             },
             id: Uuid::generate(),
+            recipient: Recipient::Matcher,
         })
     }
 
@@ -157,6 +192,11 @@ impl Notification {
     pub fn fields_mut(&mut self) -> &mut HashMap<String, String> {
         &mut self.metadata.additional_fields
     }
+
+    /// Return the recipient of the notification.
+    pub fn recipient(&self) -> &Recipient {
+        &self.recipient
+    }
 }
 
 #[cfg(test)]
diff --git a/proxmox-notify/src/send.rs b/proxmox-notify/src/send.rs
index 210a42599..f05661367 100644
--- a/proxmox-notify/src/send.rs
+++ b/proxmox-notify/src/send.rs
@@ -5,14 +5,16 @@ use proxmox_uuid::Uuid;
 use serde_json::json;
 use tracing::{error, info};
 
-use crate::api_types::MatcherConfig;
+use crate::api_types::{MatcherConfig, SendmailConfig};
 use crate::config::{ConfigEntity, PrivateConfigEntity};
 use crate::endpoints::Endpoint;
 use crate::endpoints::gotify::GotifyEndpoint;
 use crate::endpoints::sendmail::SendmailEndpoint;
 use crate::endpoints::smtp::SmtpEndpoint;
 use crate::endpoints::webhook::WebhookEndpoint;
-use crate::{Config, Content, Context, Error, Metadata, Notification, Severity};
+use crate::{
+    Config, Content, Context, EmailRecipient, Error, Metadata, Notification, Recipient, Severity,
+};
 
 /// Send a notification to a given target.
 ///
@@ -143,30 +145,70 @@ impl Bus {
     ///
     /// Any errors will not be returned but only logged.
     pub fn send(&self, context: &Context, notification: &Notification) {
-        let targets = self.check_matches(notification);
-
-        for target in targets {
-            if let Some(endpoint) = self.endpoints.get(target) {
-                let name = endpoint.name();
-
-                if endpoint.disabled() {
-                    // Skip this target if it is disabled
-                    info!("skipping disabled target '{name}'");
-                    continue;
-                }
-
-                match endpoint.send(context, notification) {
-                    Ok(_) => {
-                        info!("notified via target `{name}`");
-                    }
-                    Err(e) => {
-                        // Only log on errors, do not propagate fail to the caller.
-                        error!("could not notify via target `{name}`: {e}");
-                    }
-                }
-            } else {
-                error!("could not notify via target '{target}', it does not exist");
+        match notification.recipient() {
+            Recipient::Email(params) => self.send_to_email(context, notification, params),
+            Recipient::Target(target) => {
+                self.send_to_target(context, notification, target);
             }
+            Recipient::Matcher => {
+                let targets = self.check_matches(notification);
+
+                for target in targets {
+                    self.send_to_target(context, notification, target);
+                }
+            }
+        }
+    }
+
+    fn send_to_email(
+        &self,
+        context: &Context,
+        notification: &Notification,
+        email_recipient: &EmailRecipient,
+    ) {
+        let recipient_list = email_recipient.mailto.join(", ");
+
+        let endpoint = SendmailEndpoint {
+            config: SendmailConfig {
+                name: "legacy-sendmail".into(),
+                mailto: email_recipient.mailto.clone(),
+                author: email_recipient.author.clone(),
+                ..Default::default()
+            },
+        };
+
+        match endpoint.send(context, notification) {
+            Ok(_) => {
+                info!("notified via `{recipient_list}`");
+            }
+            Err(e) => {
+                // Only log on errors, do not propagate fail to the caller.
+                error!("could not notify via `{recipient_list}`: {e}");
+            }
+        }
+    }
+
+    fn send_to_target(&self, context: &Context, notification: &Notification, target: &str) {
+        if let Some(endpoint) = self.endpoints.get(target) {
+            let name = endpoint.name();
+
+            if endpoint.disabled() {
+                // Skip this target if it is disabled
+                info!("skipping disabled target '{name}'");
+                return;
+            }
+
+            match endpoint.send(context, notification) {
+                Ok(_) => {
+                    info!("notified via target `{name}`");
+                }
+                Err(e) => {
+                    // Only log on errors, do not propagate fail to the caller.
+                    error!("could not notify via target `{name}`: {e}");
+                }
+            }
+        } else {
+            error!("could not notify via target '{target}', it does not exist");
         }
     }
 
@@ -187,6 +229,7 @@ impl Bus {
                 data: json!({ "target": target }),
             },
             id: Uuid::generate(),
+            recipient: Recipient::Target(target.into()),
         };
 
         if let Some(endpoint) = self.endpoints.get(target) {
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 36/63] notify: add backwards-compat note to Notification type
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (34 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 35/63] notify: unify code paths for legacy-sendmail and regular notifications Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 37/63] notify: remove 'test_target' API Lukas Wagner
                   ` (27 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

This type will be serialized on disk for the notification queue and
later for the notification history, hence any future change must ensure
backwards compatibility.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/notification.rs | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/proxmox-notify/src/notification.rs b/proxmox-notify/src/notification.rs
index b3b93b545..455982c61 100644
--- a/proxmox-notify/src/notification.rs
+++ b/proxmox-notify/src/notification.rs
@@ -114,6 +114,9 @@ pub struct EmailRecipient {
     pub author: Option<String>,
 }
 
+// NOTE: This type is serialized on disk as part of the notification queue and
+// notification history, any changes to the type must be kept backwards-compatible (only add
+// optional fields or fields which have a default value).
 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
 #[serde(rename_all = "kebab-case")]
 /// Notification which can be sent
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 37/63] notify: remove 'test_target' API
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (35 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 36/63] notify: add backwards-compat note to Notification type Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 38/63] notify: replace notification instantiation with builder pattern Lukas Wagner
                   ` (26 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

Test notifications are now handled via a regular 'send', this is now
possible via the new recipient property of a notification, which allows
us to notify a target directly. This shifts some of the aspects of test
notifications towards the application code, such as the name of the
template, template data and metadata.

Since testing a target should also work when the target is set disabled,
a new generic 'set_entity_disabled' API method is added. This allows us
to temporarily enable the target in the product code, just before
sending the test notification. The modified entity is never persisted.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/api/mod.rs | 58 +++++++++++++++++++++++++++++++++++
 proxmox-notify/src/lib.rs     |  2 +-
 proxmox-notify/src/send.rs    | 47 ++--------------------------
 3 files changed, 61 insertions(+), 46 deletions(-)

diff --git a/proxmox-notify/src/api/mod.rs b/proxmox-notify/src/api/mod.rs
index fb6ba9ad9..b09c9e536 100644
--- a/proxmox-notify/src/api/mod.rs
+++ b/proxmox-notify/src/api/mod.rs
@@ -5,6 +5,7 @@ use proxmox_http_error::HttpError;
 
 use crate::Config;
 use crate::api_types::{EndpointType, Origin, Target};
+use crate::config::ConfigEntity;
 
 pub mod common;
 pub mod gotify;
@@ -84,6 +85,34 @@ pub fn get_targets(config: &Config) -> Result<Vec<Target>, HttpError> {
     Ok(targets)
 }
 
+/// Set the `disable` property of an entity.
+///
+/// The caller is responsible for any needed permission checks.
+/// The caller also responsible for locking the configuration files.
+///
+/// Returns a `HttpError` if:
+///   - the entity does not exist (`404 Not found`)
+///
+pub fn set_entity_disabled(
+    config: &mut Config,
+    name: &str,
+    disable: bool,
+) -> Result<(), HttpError> {
+    if let Some(entity) = config.config.get_mut(name) {
+        match entity {
+            ConfigEntity::Sendmail(config) => config.disable = Some(disable),
+            ConfigEntity::Gotify(config) => config.disable = Some(disable),
+            ConfigEntity::Matcher(config) => config.disable = Some(disable),
+            ConfigEntity::Smtp(config) => config.disable = Some(disable),
+            ConfigEntity::Webhook(config) => config.disable = Some(disable),
+        }
+    } else {
+        http_bail!(NOT_FOUND, "entity '{name}' not found");
+    }
+
+    Ok(())
+}
+
 fn verify_digest(config: &Config, digest: Option<ConfigDigest>) -> Result<(), HttpError> {
     config
         .digest()
@@ -318,4 +347,33 @@ mod tests {
 
         assert!(ensure_endpoints_exist(&config, &["sendmail", "gotify", "builtin"]).is_ok());
     }
+
+    #[test]
+    fn test_set_target_disabled() -> Result<(), HttpError> {
+        let mut config = prepare_config()?;
+
+        set_entity_disabled(&mut config, "matcher", true)?;
+        assert_eq!(
+            matcher::get_matcher(&config, "matcher")?.disable,
+            Some(true)
+        );
+
+        set_entity_disabled(&mut config, "sendmail", true)?;
+        set_entity_disabled(&mut config, "gotify", true)?;
+        assert_eq!(
+            sendmail::get_endpoint(&config, "sendmail")?.disable,
+            Some(true)
+        );
+        assert_eq!(gotify::get_endpoint(&config, "gotify")?.disable, Some(true));
+
+        set_entity_disabled(&mut config, "sendmail", false)?;
+        assert_eq!(
+            sendmail::get_endpoint(&config, "sendmail")?.disable,
+            Some(false)
+        );
+
+        assert!(set_entity_disabled(&mut config, "nonexistent", true).is_err());
+
+        Ok(())
+    }
 }
diff --git a/proxmox-notify/src/lib.rs b/proxmox-notify/src/lib.rs
index c446b52de..4304e2977 100644
--- a/proxmox-notify/src/lib.rs
+++ b/proxmox-notify/src/lib.rs
@@ -26,7 +26,7 @@ mod renderer;
 #[cfg(feature = "send-impl")]
 mod send;
 #[cfg(feature = "send-impl")]
-pub use send::{send, test_target};
+pub use send::send;
 
 mod error;
 pub use error::Error;
diff --git a/proxmox-notify/src/send.rs b/proxmox-notify/src/send.rs
index f05661367..42cd0bb1a 100644
--- a/proxmox-notify/src/send.rs
+++ b/proxmox-notify/src/send.rs
@@ -1,8 +1,6 @@
 use std::collections::{HashMap, HashSet};
 
 use proxmox_section_config::typed::{convert_to_typed_array, lookup};
-use proxmox_uuid::Uuid;
-use serde_json::json;
 use tracing::{error, info};
 
 use crate::api_types::{MatcherConfig, SendmailConfig};
@@ -12,9 +10,7 @@ use crate::endpoints::gotify::GotifyEndpoint;
 use crate::endpoints::sendmail::SendmailEndpoint;
 use crate::endpoints::smtp::SmtpEndpoint;
 use crate::endpoints::webhook::WebhookEndpoint;
-use crate::{
-    Config, Content, Context, EmailRecipient, Error, Metadata, Notification, Recipient, Severity,
-};
+use crate::{Config, Context, EmailRecipient, Error, Notification, Recipient};
 
 /// Send a notification to a given target.
 ///
@@ -27,17 +23,6 @@ pub fn send(context: &Context, config: &Config, notification: &Notification) ->
     Ok(())
 }
 
-/// Test target (group or single endpoint) identified by its `name`.
-///
-/// The caller is responsible for any needed permission checks.
-/// Returns an `anyhow::Error` if sending via the endpoint failed.
-pub fn test_target(context: &Context, config: &Config, endpoint: &str) -> Result<(), Error> {
-    let bus = Bus::from_config(config)?;
-    bus.test_target(context, endpoint)?;
-
-    Ok(())
-}
-
 /// Notification bus - distributes notifications to all registered endpoints
 // The reason for the split between `Config` and this struct is to make testing with mocked
 // endpoints a bit easier.
@@ -212,35 +197,6 @@ impl Bus {
         }
     }
 
-    /// Send a test notification to a target (endpoint or group).
-    ///
-    /// In contrast to the `send` function, this function will return
-    /// any errors to the caller.
-    pub fn test_target(&self, context: &Context, target: &str) -> Result<(), Error> {
-        let notification = Notification {
-            metadata: Metadata {
-                severity: Severity::Info,
-                // TODO: what fields would make sense for test notifications?
-                additional_fields: Default::default(),
-                timestamp: proxmox_time::epoch_i64(),
-            },
-            content: Content::Template {
-                template_name: "test".to_string(),
-                data: json!({ "target": target }),
-            },
-            id: Uuid::generate(),
-            recipient: Recipient::Target(target.into()),
-        };
-
-        if let Some(endpoint) = self.endpoints.get(target) {
-            endpoint.send(context, &notification)?;
-        } else {
-            return Err(Error::target_does_not_exist(target));
-        }
-
-        Ok(())
-    }
-
     fn check_matches(&self, notification: &Notification) -> HashSet<&str> {
         let mut targets = HashSet::new();
         let mut matching_matchers = Vec::new();
@@ -285,6 +241,7 @@ mod tests {
     use proxmox_match_expression::Expression;
 
     use crate::{
+        Severity,
         api_types::{expression::NotificationMatcher, severity::SeverityMatcher},
         context::{Context, test},
     };
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 38/63] notify: replace notification instantiation with builder pattern
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (36 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 37/63] notify: remove 'test_target' API Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 39/63] notify: add send receipts Lukas Wagner
                   ` (25 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

This makes constructing a notification quite a bit more ergonomic, and
allows us to add new optional fields later without issues.

For the template data, we now handle serialization ourselves instead of
taking serde_json::Value.

It would have been possible to provide the old functions alongside the
new ones, but since this change is performed in the context of larger,
breaking changes anyway, a clean break seemed appropriate.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 .../src/api_types/matcher/calendar.rs         |   6 +-
 proxmox-notify/src/api_types/matcher/field.rs |  27 ++-
 proxmox-notify/src/api_types/matcher/mod.rs   |   6 +-
 .../src/api_types/matcher/severity.rs         |  10 +-
 proxmox-notify/src/endpoints/webhook.rs       |  14 +-
 proxmox-notify/src/error.rs                   |  28 +++
 proxmox-notify/src/notification.rs            | 174 +++++++++++++-----
 proxmox-notify/src/send.rs                    |  20 +-
 8 files changed, 200 insertions(+), 85 deletions(-)

diff --git a/proxmox-notify/src/api_types/matcher/calendar.rs b/proxmox-notify/src/api_types/matcher/calendar.rs
index 65fd9bb4b..772e9832b 100644
--- a/proxmox-notify/src/api_types/matcher/calendar.rs
+++ b/proxmox-notify/src/api_types/matcher/calendar.rs
@@ -149,8 +149,10 @@ mod test {
 
     #[test]
     fn test_calendar_matcher() {
-        let mut notification =
-            Notification::from_template(Severity::Notice, "test", Value::Null, Default::default());
+        let mut notification = Notification::template_builder("test", Value::Null)
+            .severity(Severity::Notice)
+            .build()
+            .unwrap();
 
         // Fr 22 Mai 2026 12:45:00 CEST
         notification.metadata.timestamp = 1779446700;
diff --git a/proxmox-notify/src/api_types/matcher/field.rs b/proxmox-notify/src/api_types/matcher/field.rs
index a00d46c3e..0bd0e5387 100644
--- a/proxmox-notify/src/api_types/matcher/field.rs
+++ b/proxmox-notify/src/api_types/matcher/field.rs
@@ -231,10 +231,13 @@ pub mod inline {
         #[test]
         fn test_matching() {
             let mut fields = HashMap::new();
-            fields.insert("foo".into(), "bar".into());
+            fields.insert("foo".to_string(), "bar".to_string());
 
-            let notification =
-                Notification::from_template(Severity::Notice, "test", Value::Null, fields);
+            let notification = Notification::template_builder("test", Value::Null)
+                .fields(fields)
+                .severity(Severity::Notice)
+                .build()
+                .unwrap();
 
             let matcher: InlineFieldMatcher = "exact:foo=bar".parse().unwrap();
             assert!(matcher.matches(&notification).unwrap());
@@ -249,17 +252,23 @@ pub mod inline {
             assert!(matcher.matches(&notification).unwrap());
 
             let mut fields = HashMap::new();
-            fields.insert("foo".into(), "test".into());
+            fields.insert("foo".to_string(), "test".to_string());
 
-            let notification =
-                Notification::from_template(Severity::Notice, "test", Value::Null, fields);
+            let notification = Notification::template_builder("test", Value::Null)
+                .fields(fields)
+                .severity(Severity::Notice)
+                .build()
+                .unwrap();
             assert!(matcher.matches(&notification).unwrap());
 
             let mut fields = HashMap::new();
-            fields.insert("foo".into(), "notthere".into());
+            fields.insert("foo".to_string(), "notthere".to_string());
 
-            let notification =
-                Notification::from_template(Severity::Notice, "test", Value::Null, fields);
+            let notification = Notification::template_builder("test", Value::Null)
+                .fields(fields)
+                .severity(Severity::Notice)
+                .build()
+                .unwrap();
             assert!(!matcher.matches(&notification).unwrap());
 
             assert!("regex:'3=b.*".parse::<InlineFieldMatcher>().is_err());
diff --git a/proxmox-notify/src/api_types/matcher/mod.rs b/proxmox-notify/src/api_types/matcher/mod.rs
index e65063c5e..fe2b61a9d 100644
--- a/proxmox-notify/src/api_types/matcher/mod.rs
+++ b/proxmox-notify/src/api_types/matcher/mod.rs
@@ -395,8 +395,10 @@ mod tests {
         use crate::Severity;
         use serde_json::Value;
 
-        let notification =
-            Notification::from_template(Severity::Notice, "test", Value::Null, Default::default());
+        let notification = Notification::template_builder("test", Value::Null)
+            .severity(Severity::Notice)
+            .build()
+            .unwrap();
 
         for mode in [MatchModeOperator::All, MatchModeOperator::Any] {
             let config = MatcherConfig {
diff --git a/proxmox-notify/src/api_types/matcher/severity.rs b/proxmox-notify/src/api_types/matcher/severity.rs
index ed0278888..9bd3019f1 100644
--- a/proxmox-notify/src/api_types/matcher/severity.rs
+++ b/proxmox-notify/src/api_types/matcher/severity.rs
@@ -103,12 +103,10 @@ pub mod inline {
 
         #[test]
         fn test_severities() {
-            let notification = Notification::from_template(
-                Severity::Notice,
-                "test",
-                Value::Null,
-                Default::default(),
-            );
+            let notification = Notification::template_builder("test", Value::Null)
+                .severity(Severity::Notice)
+                .build()
+                .unwrap();
 
             let matcher: InlineSeverityMatcher = "info,notice,warning,error".parse().unwrap();
             assert!(matcher.matches(&notification).unwrap());
diff --git a/proxmox-notify/src/endpoints/webhook.rs b/proxmox-notify/src/endpoints/webhook.rs
index 2eaa71633..05ae325ea 100644
--- a/proxmox-notify/src/endpoints/webhook.rs
+++ b/proxmox-notify/src/endpoints/webhook.rs
@@ -309,18 +309,11 @@ fn handlebars_escape(
 
 #[cfg(test)]
 mod tests {
-    use std::collections::HashMap;
-
     use super::*;
     use crate::{Severity, api_types::KeyAndBase64Val, context::test};
 
     #[test]
     fn test_build_request() {
-        let data = HashMap::from_iter([
-            ("hello".into(), "hello world".into()),
-            ("test".into(), "escaped\nstring".into()),
-        ]);
-
         let body_template = r#"
 {{ fields.test }}
 {{ escape fields.test }}
@@ -365,7 +358,12 @@ hello%20world
             },
         };
 
-        let notification = Notification::from_template(Severity::Info, "foo", json!({}), data);
+        let notification = Notification::template_builder("foo", json!({}))
+            .severity(Severity::Info)
+            .field("hello", "hello world")
+            .field("test", "escaped\nstring")
+            .build()
+            .unwrap();
 
         let context = test::test_context();
 
diff --git a/proxmox-notify/src/error.rs b/proxmox-notify/src/error.rs
index 9655a02de..c8747f39f 100644
--- a/proxmox-notify/src/error.rs
+++ b/proxmox-notify/src/error.rs
@@ -38,6 +38,15 @@ pub enum Error {
     #[error("SMTP request failed: {0}")]
     SmtpError(#[source] BoxedError),
 
+    /// A notification passed to proxmox_notify is invalid.
+    #[error("notification is invalid: {err}", err = print_optional_error(.message, .source))]
+    InvalidNotification {
+        /// Description of the error.
+        message: String,
+        /// Underlying error, if any.
+        source: Option<BoxedError>,
+    },
+
     /// A mail message to be forwarded could not be parsed or rebuilt.
     #[error("forwarded email message is invalid: {err}", err = print_optional_error(.message, .source))]
     InvalidForwardedMessage {
@@ -127,6 +136,25 @@ impl Error {
         }
     }
 
+    /// Create an [`Error::InvalidNotification`] without an underlying error.
+    pub(crate) fn invalid_notification(s: impl Into<String>) -> Self {
+        Self::InvalidNotification {
+            message: s.into(),
+            source: None,
+        }
+    }
+
+    /// Create an [`Error::InvalidNotification`] with an underlying error.
+    pub(crate) fn invalid_notification_with_source(
+        s: impl Into<String>,
+        source: impl Into<BoxedError>,
+    ) -> Self {
+        Self::InvalidNotification {
+            message: s.into(),
+            source: Some(source.into()),
+        }
+    }
+
     /// Create an [`Error::ConfigDeserialization`] from the given error.
     pub(crate) fn config_deserialization(err: impl Into<BoxedError>) -> Self {
         Self::ConfigDeserialization(err.into())
diff --git a/proxmox-notify/src/notification.rs b/proxmox-notify/src/notification.rs
index 455982c61..b1756a5d7 100644
--- a/proxmox-notify/src/notification.rs
+++ b/proxmox-notify/src/notification.rs
@@ -133,42 +133,41 @@ pub struct Notification {
 }
 
 impl Notification {
-    pub fn from_template<S: AsRef<str>>(
-        severity: Severity,
+    /// Create a builder for a notification that is rendered from a template.
+    pub fn template_builder<S: Into<String>, D: Serialize>(
         template_name: S,
-        template_data: Value,
-        fields: HashMap<String, String>,
-    ) -> Self {
-        Self {
-            metadata: Metadata {
-                severity,
-                additional_fields: fields,
-                timestamp: proxmox_time::epoch_i64(),
-            },
-            content: Content::Template {
-                template_name: template_name.as_ref().to_string(),
-                data: template_data,
-            },
-            id: Uuid::generate(),
-            recipient: Recipient::Matcher,
+        template_data: D,
+    ) -> NotificationBuilder {
+        let template_name = template_name.into();
+
+        let content = serde_json::to_value(template_data)
+            .map_err(|err| {
+                Error::invalid_notification_with_source(
+                    "could not serialize template data type",
+                    err,
+                )
+            })
+            .map(move |value| Content::Template {
+                template_name,
+                data: value,
+            });
+
+        NotificationBuilder {
+            severity: None,
+            content,
+            fields: Default::default(),
+            recipient: Default::default(),
         }
     }
 
-    pub fn new_forwarded_mail(
-        severity: Severity,
-        raw_mail: Vec<u8>,
-        fields: HashMap<String, String>,
-    ) -> Result<Self, Error> {
-        Ok(Self {
-            content: Content::ForwardedMail { raw: raw_mail },
-            metadata: Metadata {
-                severity,
-                additional_fields: fields,
-                timestamp: proxmox_time::epoch_i64(),
-            },
-            id: Uuid::generate(),
-            recipient: Recipient::Matcher,
-        })
+    /// Create a builder for a notification that forwards a raw mail.
+    pub fn forwarded_mail_builder(raw_mail: Vec<u8>) -> NotificationBuilder {
+        NotificationBuilder {
+            severity: None,
+            content: Ok(Content::ForwardedMail { raw: raw_mail }),
+            fields: Default::default(),
+            recipient: Default::default(),
+        }
     }
 
     /// Return the unique ID of this notification.
@@ -202,6 +201,65 @@ impl Notification {
     }
 }
 
+/// Builder for [`Notification`].
+///
+/// Created via [`Notification::template_builder`] or [`Notification::forwarded_mail_builder`].
+#[derive(Debug)]
+pub struct NotificationBuilder {
+    severity: Option<Severity>,
+    content: Result<Content, Error>,
+    fields: HashMap<String, String>,
+    recipient: Recipient,
+}
+
+impl NotificationBuilder {
+    /// Set the severity of the notification.
+    ///
+    /// If not set, the severity will default to [`Severity::Unknown`].
+    pub fn severity(mut self, severity: Severity) -> Self {
+        self.severity = Some(severity);
+        self
+    }
+
+    /// Add a single metadata field, replacing any previous value for the same key.
+    pub fn field<K: Into<String>, V: Into<String>>(mut self, key: K, value: V) -> Self {
+        self.fields.insert(key.into(), value.into());
+        self
+    }
+
+    /// Add multiple metadata fields, replacing any previous values for the same keys.
+    pub fn fields<I, K, V>(mut self, fields: I) -> Self
+    where
+        I: IntoIterator<Item = (K, V)>,
+        K: Into<String>,
+        V: Into<String>,
+    {
+        self.fields
+            .extend(fields.into_iter().map(|(k, v)| (k.into(), v.into())));
+        self
+    }
+
+    /// Set the recipient of the notification. Defaults to [`Recipient::Matcher`].
+    pub fn recipient(mut self, recipient: Recipient) -> Self {
+        self.recipient = recipient;
+        self
+    }
+
+    /// Build the notification, assigning a new unique ID and the current time as timestamp.
+    pub fn build(self) -> Result<Notification, Error> {
+        Ok(Notification {
+            content: self.content?,
+            metadata: Metadata {
+                severity: self.severity.unwrap_or(Severity::Unknown),
+                timestamp: proxmox_time::epoch_i64(),
+                additional_fields: self.fields,
+            },
+            id: Uuid::generate(),
+            recipient: self.recipient,
+        })
+    }
+}
+
 #[cfg(test)]
 mod tests {
     use serde_json::json;
@@ -249,15 +307,29 @@ mod tests {
     }
 
     #[test]
-    fn from_template() {
-        let fields = HashMap::from([("hostname".to_string(), "pve".to_string())]);
+    fn template_builder() {
         let data = json!({"key": "value"});
 
-        let notification =
-            Notification::from_template(Severity::Warning, "test", data.clone(), fields.clone());
+        let notification = Notification::template_builder("test", data.clone())
+            .severity(Severity::Error)
+            .field("hostname", "pve")
+            .fields([("type", "vzdump"), ("hostname", "pbs")])
+            .recipient(Recipient::Target("mail-to-root".into()))
+            .build()
+            .unwrap();
 
-        assert_eq!(notification.severity(), Severity::Warning);
-        assert_eq!(notification.fields(), &fields);
+        assert_eq!(notification.severity(), Severity::Error);
+        assert_eq!(
+            notification.fields(),
+            &HashMap::from([
+                ("hostname".to_string(), "pbs".to_string()),
+                ("type".to_string(), "vzdump".to_string()),
+            ])
+        );
+        assert_eq!(
+            notification.recipient,
+            Recipient::Target("mail-to-root".into())
+        );
         assert_eq!(
             notification.content,
             Content::Template {
@@ -268,22 +340,24 @@ mod tests {
     }
 
     #[test]
-    fn new_forwarded_mail() {
+    fn forwarded_mail_builder() {
         let raw = TEST_MAIL.to_vec();
 
-        let notification =
-            Notification::new_forwarded_mail(Severity::Unknown, raw.clone(), HashMap::new())
-                .unwrap();
+        let notification = Notification::forwarded_mail_builder(raw.clone())
+            .build()
+            .unwrap();
 
         assert_eq!(notification.severity(), Severity::Unknown);
         assert!(notification.fields().is_empty());
+        assert_eq!(notification.recipient, Recipient::Matcher);
         assert_eq!(notification.content, Content::ForwardedMail { raw });
     }
 
     #[test]
     fn fields_mut() {
-        let mut notification =
-            Notification::from_template(Severity::Info, "test", Value::Null, HashMap::new());
+        let mut notification = Notification::template_builder("test", Value::Null)
+            .build()
+            .unwrap();
 
         notification
             .fields_mut()
@@ -331,9 +405,17 @@ mod tests {
     #[test]
     fn serde_roundtrip() {
         let fields = HashMap::from([("hostname".to_string(), "pve".to_string())]);
+
         let notifications = [
-            Notification::from_template(Severity::Error, "test", json!({"a": [1, 2]}), fields),
-            Notification::new_forwarded_mail(Severity::Info, TEST_MAIL.to_vec(), HashMap::new())
+            Notification::template_builder("test", json!({"a": [1, 2]}))
+                .severity(Severity::Info)
+                .fields(fields.clone())
+                .build()
+                .unwrap(),
+            Notification::forwarded_mail_builder(TEST_MAIL.to_vec())
+                .severity(Severity::Unknown)
+                .fields(fields)
+                .build()
                 .unwrap(),
         ];
 
diff --git a/proxmox-notify/src/send.rs b/proxmox-notify/src/send.rs
index 42cd0bb1a..d08d5af30 100644
--- a/proxmox-notify/src/send.rs
+++ b/proxmox-notify/src/send.rs
@@ -308,12 +308,10 @@ mod tests {
         // Send directly to endpoint
         bus.send(
             &context,
-            &Notification::from_template(
-                Severity::Info,
-                "test",
-                Default::default(),
-                Default::default(),
-            ),
+            &Notification::template_builder("test", None::<()>)
+                .severity(Severity::Info)
+                .build()
+                .unwrap(),
         );
         let messages = mock.messages();
         assert_eq!(messages.len(), 1);
@@ -358,12 +356,10 @@ mod tests {
         });
 
         let send_with_severity = |severity| {
-            let notification = Notification::from_template(
-                severity,
-                "test",
-                Default::default(),
-                Default::default(),
-            );
+            let notification = Notification::template_builder("test", None::<()>)
+                .severity(severity)
+                .build()
+                .unwrap();
 
             bus.send(&context, &notification);
         };
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 39/63] notify: add send receipts
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (37 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 38/63] notify: replace notification instantiation with builder pattern Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 40/63] notify: make sure that template name matches SAFE_ID_REGEX Lukas Wagner
                   ` (24 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

Instead of only logging errors on proxmox_notify::send, return a receipt
that includes information such as:
  - the evaluation results of matchers
  - which targets these matchers yielded
  - a per-target status, including errors if there were any

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/api_types/matcher/mod.rs |  13 +-
 proxmox-notify/src/api_types/mod.rs         |   3 +
 proxmox-notify/src/api_types/receipt.rs     | 138 ++++++++++++++++
 proxmox-notify/src/send.rs                  | 172 ++++++++++++++++----
 4 files changed, 287 insertions(+), 39 deletions(-)
 create mode 100644 proxmox-notify/src/api_types/receipt.rs

diff --git a/proxmox-notify/src/api_types/matcher/mod.rs b/proxmox-notify/src/api_types/matcher/mod.rs
index fe2b61a9d..6dd6d5bc5 100644
--- a/proxmox-notify/src/api_types/matcher/mod.rs
+++ b/proxmox-notify/src/api_types/matcher/mod.rs
@@ -1,6 +1,6 @@
 use std::fmt::Debug;
 
-use proxmox_match_expression::Expression;
+use proxmox_match_expression::{EvaluatedExpressionWithResult, Expression};
 use serde::{Deserialize, Serialize};
 
 use proxmox_api_macro::api;
@@ -150,7 +150,10 @@ trait MatchDirective {
 }
 
 impl MatcherConfig {
-    pub fn matches(&self, notification: &Notification) -> Result<Option<&[String]>, Error> {
+    pub fn matches(
+        &self,
+        notification: &Notification,
+    ) -> Result<EvaluatedExpressionWithResult<NotificationMatcher>, Error> {
         #[cfg(feature = "legacy-matchers")]
         self.warn_about_invalid_configuration();
 
@@ -178,9 +181,7 @@ impl MatcherConfig {
         // This gives the user a trace of which rules matched and which did not.
         let evaluated_expression = expression.evaluate(notification)?;
 
-        Ok(evaluated_expression
-            .is_match()
-            .then_some(self.target.as_slice()))
+        Ok(evaluated_expression)
     }
 
     #[cfg(feature = "legacy-matchers")]
@@ -407,7 +408,7 @@ mod tests {
                 ..Default::default()
             };
 
-            assert!(config.matches(&notification).unwrap().is_some())
+            assert!(config.matches(&notification).unwrap().is_match())
         }
     }
 
diff --git a/proxmox-notify/src/api_types/mod.rs b/proxmox-notify/src/api_types/mod.rs
index f3b381a8b..f445618c1 100644
--- a/proxmox-notify/src/api_types/mod.rs
+++ b/proxmox-notify/src/api_types/mod.rs
@@ -27,6 +27,9 @@ pub use matcher::*;
 mod schema;
 pub use schema::*;
 
+mod receipt;
+pub use receipt::*;
+
 #[api]
 #[derive(Clone, Debug, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd)]
 #[serde(rename_all = "kebab-case")]
diff --git a/proxmox-notify/src/api_types/receipt.rs b/proxmox-notify/src/api_types/receipt.rs
new file mode 100644
index 000000000..d05135ba3
--- /dev/null
+++ b/proxmox-notify/src/api_types/receipt.rs
@@ -0,0 +1,138 @@
+//! Types describing the outcome of sending a notification.
+//!
+//! Sending a notification yields a [`Receipt`], which records how the notification was routed and
+//! whether it reached its destinations:
+//!
+//! - One [`MatcherReceipt`] per configured matcher, if the notification was routed through the
+//!   matchers. It states whether the matcher matched, did not match, was disabled or failed to
+//!   be evaluated. For evaluated matchers, it also contains the evaluated match expression, which
+//!   shows why the notification was or was not matched.
+//! - One [`TargetReceipt`] per target the notification was dispatched to, stating whether the
+//!   notification was delivered, the target was disabled, or delivery failed.
+//!
+//! Delivery failures are reported in the receipt rather than as an error, so that the caller can
+//! inspect the result of every single target, even if only some of them failed.
+
+use serde::{Deserialize, Serialize};
+
+use proxmox_match_expression::EvaluatedExpressionWithResult;
+
+use crate::api_types::expression::NotificationMatcher;
+
+/// Outcome of sending a single notification.
+///
+/// Records which matchers were evaluated and which targets the notification was dispatched to,
+/// together with the result for each of them.
+#[derive(Clone, Debug, Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case")]
+pub struct Receipt {
+    pub(crate) target_receipts: Vec<TargetReceipt>,
+    pub(crate) matcher_receipts: Vec<MatcherReceipt>,
+}
+
+impl Receipt {
+    /// Returns the receipts of all targets the notification was dispatched to.
+    pub fn target_receipts(&self) -> &[TargetReceipt] {
+        &self.target_receipts
+    }
+
+    /// Returns the receipts of all matchers that were evaluated for the notification.
+    ///
+    /// This is empty if the notification was sent to a target or email recipient directly,
+    /// without going through the matchers.
+    pub fn matcher_receipts(&self) -> &[MatcherReceipt] {
+        &self.matcher_receipts
+    }
+}
+
+/// Result of dispatching a notification to a single target.
+#[derive(Clone, Debug, Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case")]
+pub struct TargetReceipt {
+    pub(crate) target: String,
+    #[serde(flatten)]
+    pub(crate) status: TargetReceiptStatus,
+    pub(crate) timestamp: i64,
+}
+
+impl TargetReceipt {
+    /// Returns the name of the target.
+    pub fn target(&self) -> &str {
+        &self.target
+    }
+
+    /// Returns the delivery status for this target.
+    pub fn status(&self) -> &TargetReceiptStatus {
+        &self.status
+    }
+
+    /// Returns the time the delivery attempt finished, as seconds since the UNIX epoch.
+    pub fn timestamp(&self) -> i64 {
+        self.timestamp
+    }
+}
+
+/// Delivery status of a notification for a single target.
+#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case", tag = "status")]
+pub enum TargetReceiptStatus {
+    /// The notification was -- to the best of our knowledge -- delivered successfully.
+    Delivered,
+    /// Target was disabled.
+    Disabled,
+    /// The notification was -- to the best of our knowledge -- not delivered to the recipient.
+    #[serde(rename_all = "kebab-case")]
+    Error {
+        /// Human-readable description of the error.
+        error_message: String,
+    },
+}
+
+/// Result of evaluating a single notification matcher.
+#[derive(Clone, Debug, Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case", tag = "status")]
+pub enum MatcherReceiptStatus {
+    /// The matcher's expression matched the notification.
+    #[serde(rename_all = "kebab-case")]
+    Matched {
+        /// The evaluated match expression, including the results of its sub-expressions.
+        evaluated_expression: EvaluatedExpressionWithResult<NotificationMatcher>,
+        /// Targets configured for this matcher, which the notification is dispatched to.
+        targets: Vec<String>,
+    },
+    /// The matcher's expression did not match the notification.
+    #[serde(rename_all = "kebab-case")]
+    NoMatch {
+        /// The evaluated match expression, including the results of its sub-expressions.
+        evaluated_expression: EvaluatedExpressionWithResult<NotificationMatcher>,
+    },
+    /// Matcher was disabled and therefore not evaluated.
+    Disabled,
+    /// The matcher could not be evaluated. Its targets were not notified on its behalf.
+    #[serde(rename_all = "kebab-case")]
+    Error {
+        /// Human-readable description of the error.
+        error_message: String,
+    },
+}
+
+/// Result of evaluating a single notification matcher, identified by its name.
+#[derive(Clone, Debug, Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case")]
+pub struct MatcherReceipt {
+    pub(crate) matcher: String,
+    #[serde(flatten)]
+    pub(crate) status: MatcherReceiptStatus,
+}
+
+impl MatcherReceipt {
+    /// Returns the name of the matcher.
+    pub fn matcher(&self) -> &str {
+        &self.matcher
+    }
+
+    /// Returns the evaluation result of the matcher.
+    pub fn status(&self) -> &MatcherReceiptStatus {
+        &self.status
+    }
+}
diff --git a/proxmox-notify/src/send.rs b/proxmox-notify/src/send.rs
index d08d5af30..9fc3864ed 100644
--- a/proxmox-notify/src/send.rs
+++ b/proxmox-notify/src/send.rs
@@ -3,7 +3,10 @@ use std::collections::{HashMap, HashSet};
 use proxmox_section_config::typed::{convert_to_typed_array, lookup};
 use tracing::{error, info};
 
-use crate::api_types::{MatcherConfig, SendmailConfig};
+use crate::api_types::{
+    MatcherConfig, MatcherReceipt, MatcherReceiptStatus, Receipt, SendmailConfig, TargetReceipt,
+    TargetReceiptStatus,
+};
 use crate::config::{ConfigEntity, PrivateConfigEntity};
 use crate::endpoints::Endpoint;
 use crate::endpoints::gotify::GotifyEndpoint;
@@ -16,11 +19,13 @@ use crate::{Config, Context, EmailRecipient, Error, Notification, Recipient};
 ///
 /// The caller is responsible for any needed permission checks.
 /// Returns an `anyhow::Error` in case of an error.
-pub fn send(context: &Context, config: &Config, notification: &Notification) -> Result<(), Error> {
+pub fn send(
+    context: &Context,
+    config: &Config,
+    notification: &Notification,
+) -> Result<Receipt, Error> {
     let bus = Bus::from_config(config)?;
-    bus.send(context, notification);
-
-    Ok(())
+    Ok(bus.send(context, notification))
 }
 
 /// Notification bus - distributes notifications to all registered endpoints
@@ -129,20 +134,43 @@ impl Bus {
     /// the notification.
     ///
     /// Any errors will not be returned but only logged.
-    pub fn send(&self, context: &Context, notification: &Notification) {
+    pub fn send(&self, context: &Context, notification: &Notification) -> Receipt {
+        let mut target_receipts = Vec::new();
+        let mut matcher_receipts = Vec::new();
+
         match notification.recipient() {
-            Recipient::Email(params) => self.send_to_email(context, notification, params),
+            Recipient::Email(params) => {
+                target_receipts.push(self.send_to_email(context, notification, params))
+            }
             Recipient::Target(target) => {
-                self.send_to_target(context, notification, target);
+                target_receipts.push(self.send_to_target(context, notification, target));
             }
             Recipient::Matcher => {
-                let targets = self.check_matches(notification);
+                matcher_receipts = self.check_matches(notification);
 
-                for target in targets {
-                    self.send_to_target(context, notification, target);
+                let (matching_matchers, targets) =
+                    Self::matching_matchers_and_targets_from_receipts(&matcher_receipts);
+
+                if !matching_matchers.is_empty() {
+                    info!(
+                        "notification matched the following matchers: {}. The following targets will be notified: {}",
+                        matching_matchers.join(", "),
+                        targets.join(", ")
+                    );
+                } else {
+                    info!("notification was not matched by any matcher");
+                }
+
+                for target in &targets {
+                    target_receipts.push(self.send_to_target(context, notification, target));
                 }
             }
         }
+
+        Receipt {
+            target_receipts,
+            matcher_receipts,
+        }
     }
 
     fn send_to_email(
@@ -150,7 +178,7 @@ impl Bus {
         context: &Context,
         notification: &Notification,
         email_recipient: &EmailRecipient,
-    ) {
+    ) -> TargetReceipt {
         let recipient_list = email_recipient.mailto.join(", ");
 
         let endpoint = SendmailEndpoint {
@@ -165,72 +193,150 @@ impl Bus {
         match endpoint.send(context, notification) {
             Ok(_) => {
                 info!("notified via `{recipient_list}`");
+                TargetReceipt {
+                    target: "legacy-sendmail".into(),
+                    status: TargetReceiptStatus::Delivered,
+                    timestamp: proxmox_time::epoch_i64(),
+                }
             }
             Err(e) => {
                 // Only log on errors, do not propagate fail to the caller.
                 error!("could not notify via `{recipient_list}`: {e}");
+                TargetReceipt {
+                    target: "legacy-sendmail".into(),
+                    status: TargetReceiptStatus::Error {
+                        error_message: e.to_string(),
+                    },
+                    timestamp: proxmox_time::epoch_i64(),
+                }
             }
         }
     }
 
-    fn send_to_target(&self, context: &Context, notification: &Notification, target: &str) {
+    fn send_to_target(
+        &self,
+        context: &Context,
+        notification: &Notification,
+        target: &str,
+    ) -> TargetReceipt {
         if let Some(endpoint) = self.endpoints.get(target) {
             let name = endpoint.name();
 
             if endpoint.disabled() {
                 // Skip this target if it is disabled
                 info!("skipping disabled target '{name}'");
-                return;
+
+                return TargetReceipt {
+                    target: name.to_string(),
+                    status: TargetReceiptStatus::Disabled,
+                    timestamp: proxmox_time::epoch_i64(),
+                };
             }
 
             match endpoint.send(context, notification) {
                 Ok(_) => {
                     info!("notified via target `{name}`");
+                    TargetReceipt {
+                        target: name.to_string(),
+                        status: TargetReceiptStatus::Delivered,
+                        timestamp: proxmox_time::epoch_i64(),
+                    }
                 }
                 Err(e) => {
                     // Only log on errors, do not propagate fail to the caller.
                     error!("could not notify via target `{name}`: {e}");
+                    TargetReceipt {
+                        target: name.to_string(),
+                        status: TargetReceiptStatus::Error {
+                            error_message: e.to_string(),
+                        },
+                        timestamp: proxmox_time::epoch_i64(),
+                    }
                 }
             }
         } else {
             error!("could not notify via target '{target}', it does not exist");
+            TargetReceipt {
+                target: target.to_string(),
+                status: TargetReceiptStatus::Error {
+                    error_message: Error::target_does_not_exist(target).to_string(),
+                },
+                timestamp: proxmox_time::epoch_i64(),
+            }
         }
     }
 
-    fn check_matches(&self, notification: &Notification) -> HashSet<&str> {
-        let mut targets = HashSet::new();
-        let mut matching_matchers = Vec::new();
+    fn check_matches(&self, notification: &Notification) -> Vec<MatcherReceipt> {
+        let mut receipts = Vec::new();
 
         for matcher in &self.matchers {
+            let name = matcher.name.clone();
+
             if matcher.disable.unwrap_or_default() {
                 // Skip this matcher if it is disabled
-                info!("skipping disabled matcher '{name}'", name = matcher.name);
+                info!("skipping disabled matcher '{name}'");
+
+                receipts.push(MatcherReceipt {
+                    matcher: name,
+                    status: MatcherReceiptStatus::Disabled,
+                });
+
                 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(evaluated_expression) => {
+                    if evaluated_expression.is_match() {
+                        receipts.push(MatcherReceipt {
+                            matcher: name,
+                            status: MatcherReceiptStatus::Matched {
+                                evaluated_expression,
+                                targets: matcher.target.clone(),
+                            },
+                        });
+                    } else {
+                        receipts.push(MatcherReceipt {
+                            matcher: name,
+                            status: MatcherReceiptStatus::NoMatch {
+                                evaluated_expression,
+                            },
+                        });
+                    }
+                }
+                Err(err) => {
+                    receipts.push(MatcherReceipt {
+                        matcher: name,
+                        status: MatcherReceiptStatus::Error {
+                            error_message: err.to_string(),
+                        },
+                    });
+                    error!("matcher '{matcher}' failed: {err}", matcher = matcher.name);
                 }
-                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());
+        receipts
+    }
 
-            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");
+    fn matching_matchers_and_targets_from_receipts(
+        matcher_receipts: &[MatcherReceipt],
+    ) -> (Vec<String>, Vec<String>) {
+        let mut matchers = Vec::new();
+        let mut deduplicated_targets = HashSet::new();
+
+        for receipt in matcher_receipts {
+            if let MatcherReceiptStatus::Matched { targets, .. } = &receipt.status {
+                matchers.push(receipt.matcher.clone());
+                deduplicated_targets.extend(targets);
+            }
         }
 
-        targets
+        let mut targets = Vec::from_iter(deduplicated_targets.into_iter().cloned());
+        targets.sort();
+
+        matchers.sort();
+
+        (matchers, targets)
     }
 }
 
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 40/63] notify: make sure that template name matches SAFE_ID_REGEX
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (38 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 39/63] notify: add send receipts Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 41/63] notify: implement notification queue submitter Lukas Wagner
                   ` (23 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

This avoids malformed template identifiers which could read from outside
the template base directory.

The template name is checked when constructing a notification, but also
on `send`.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---

Notes:
    New in v2.

 proxmox-notify/src/notification.rs | 54 ++++++++++++++++++++++++++++--
 proxmox-notify/src/send.rs         |  2 ++
 2 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/proxmox-notify/src/notification.rs b/proxmox-notify/src/notification.rs
index b1756a5d7..efb3508f1 100644
--- a/proxmox-notify/src/notification.rs
+++ b/proxmox-notify/src/notification.rs
@@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
 use serde_json::Value;
 
 use proxmox_schema::api;
+use proxmox_schema::api_types::{SAFE_ID_REGEX, SAFE_ID_REGEX_STR};
 use proxmox_uuid::Uuid;
 
 use crate::Error;
@@ -199,6 +200,15 @@ impl Notification {
     pub fn recipient(&self) -> &Recipient {
         &self.recipient
     }
+
+    /// Validate this notification.
+    pub fn validate(&self) -> Result<(), Error> {
+        if let Content::Template { template_name, .. } = &self.content {
+            verify_template_name(template_name)?;
+        }
+
+        Ok(())
+    }
 }
 
 /// Builder for [`Notification`].
@@ -247,7 +257,7 @@ impl NotificationBuilder {
 
     /// Build the notification, assigning a new unique ID and the current time as timestamp.
     pub fn build(self) -> Result<Notification, Error> {
-        Ok(Notification {
+        let notification = Notification {
             content: self.content?,
             metadata: Metadata {
                 severity: self.severity.unwrap_or(Severity::Unknown),
@@ -256,10 +266,24 @@ impl NotificationBuilder {
             },
             id: Uuid::generate(),
             recipient: self.recipient,
-        })
+        };
+
+        notification.validate()?;
+
+        Ok(notification)
     }
 }
 
+pub(crate) fn verify_template_name(name: &str) -> Result<(), Error> {
+    if !SAFE_ID_REGEX.is_match(name) {
+        return Err(Error::invalid_notification(format!(
+            "template name '{name}' does not match regex '{SAFE_ID_REGEX_STR}'"
+        )));
+    }
+
+    Ok(())
+}
+
 #[cfg(test)]
 mod tests {
     use serde_json::json;
@@ -425,4 +449,30 @@ mod tests {
             assert_eq!(deserialized, notification);
         }
     }
+
+    #[test]
+    /// Verify that it is not possible to construct notifications
+    /// with invalid template names.
+    fn invalid_template_name() {
+        assert!(
+            Notification::template_builder("../something", ())
+                .build()
+                .is_err()
+        );
+        assert!(
+            Notification::template_builder("/foo/bar", ())
+                .build()
+                .is_err()
+        );
+        assert!(
+            Notification::template_builder("../../foo/bar", ())
+                .build()
+                .is_err()
+        );
+        assert!(
+            Notification::template_builder("invälid", ())
+                .build()
+                .is_err()
+        );
+    }
 }
diff --git a/proxmox-notify/src/send.rs b/proxmox-notify/src/send.rs
index 9fc3864ed..c11ff1b76 100644
--- a/proxmox-notify/src/send.rs
+++ b/proxmox-notify/src/send.rs
@@ -24,6 +24,8 @@ pub fn send(
     config: &Config,
     notification: &Notification,
 ) -> Result<Receipt, Error> {
+    notification.validate()?;
+
     let bus = Bus::from_config(config)?;
     Ok(bus.send(context, notification))
 }
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 41/63] notify: implement notification queue submitter
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (39 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 40/63] notify: make sure that template name matches SAFE_ID_REGEX Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 42/63] notify: context: add read_config Lukas Wagner
                   ` (22 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

Each product will be switched to a queue/worker approach, where each
sender simply drops the notification in serialized form into a queue
directory. Each notification has a unique UUID which is used as the
filename, making filename collisions not an issue in practice.

The new QueueSubmitter has a single method `submit`, which serialized
the notification and atomically places it in the pre-existing queue
directory.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 Cargo.toml                            |   1 +
 proxmox-notify/Cargo.toml             |   2 +
 proxmox-notify/src/error.rs           |  16 +++
 proxmox-notify/src/lib.rs             |   3 +
 proxmox-notify/src/queue/mod.rs       |  18 +++
 proxmox-notify/src/queue/submitter.rs | 171 ++++++++++++++++++++++++++
 6 files changed, 211 insertions(+)
 create mode 100644 proxmox-notify/src/queue/mod.rs
 create mode 100644 proxmox-notify/src/queue/submitter.rs

diff --git a/Cargo.toml b/Cargo.toml
index 091f585d1..c1ce30ee0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -146,6 +146,7 @@ signal-hook-registry = "1"
 syn = { version = "2", features = [ "full", "visit-mut" ] }
 sync_wrapper = "1"
 tar = "0.4"
+tempfile = "3.15"
 termcolor = "1.1.2"
 thiserror = "2"
 tokio = "1.6"
diff --git a/proxmox-notify/Cargo.toml b/proxmox-notify/Cargo.toml
index e47912d11..4cfb1f2eb 100644
--- a/proxmox-notify/Cargo.toml
+++ b/proxmox-notify/Cargo.toml
@@ -42,6 +42,7 @@ proxmox-uuid = { workspace = true, features = ["serde"] }
 
 [dev-dependencies]
 pretty_assertions.workspace = true
+tempfile.workspace = true
 
 [features]
 default = []
@@ -78,3 +79,4 @@ send-impl = [
 pve-context = ["dep:proxmox-sys", "legacy-matchers"]
 pbs-context = ["dep:proxmox-sys", "legacy-matchers"]
 legacy-matchers = []
+queue-submitter = ["dep:proxmox-sys"]
diff --git a/proxmox-notify/src/error.rs b/proxmox-notify/src/error.rs
index c8747f39f..bab240506 100644
--- a/proxmox-notify/src/error.rs
+++ b/proxmox-notify/src/error.rs
@@ -56,6 +56,14 @@ pub enum Error {
         source: Option<BoxedError>,
     },
 
+    #[error("notification queue error: {err}", err = print_optional_error(.message, .source))]
+    Queue {
+        /// Description of the error.
+        message: String,
+        /// Underlying error, if any.
+        source: Option<BoxedError>,
+    },
+
     /// The notification configuration could not be serialized.
     #[error("could not serialize config: {0}")]
     ConfigSerialization(#[source] BoxedError),
@@ -155,6 +163,14 @@ impl Error {
         }
     }
 
+    /// Create an [`Error::Queue`] with an underlying error.
+    pub(crate) fn queue_with_source(s: impl Into<String>, source: impl Into<BoxedError>) -> Self {
+        Self::Queue {
+            message: s.into(),
+            source: Some(source.into()),
+        }
+    }
+
     /// Create an [`Error::ConfigDeserialization`] from the given error.
     pub(crate) fn config_deserialization(err: impl Into<BoxedError>) -> Self {
         Self::ConfigDeserialization(err.into())
diff --git a/proxmox-notify/src/lib.rs b/proxmox-notify/src/lib.rs
index 4304e2977..ab5a929c1 100644
--- a/proxmox-notify/src/lib.rs
+++ b/proxmox-notify/src/lib.rs
@@ -28,6 +28,9 @@ mod send;
 #[cfg(feature = "send-impl")]
 pub use send::send;
 
+#[cfg(feature = "queue-submitter")]
+pub mod queue;
+
 mod error;
 pub use error::Error;
 
diff --git a/proxmox-notify/src/queue/mod.rs b/proxmox-notify/src/queue/mod.rs
new file mode 100644
index 000000000..25137e123
--- /dev/null
+++ b/proxmox-notify/src/queue/mod.rs
@@ -0,0 +1,18 @@
+use std::path::Path;
+
+use crate::Error;
+
+mod submitter;
+pub use submitter::QueueSubmitter;
+
+/// Maximum size of a queued notification file.
+///
+/// Well above what legitimate producers submit, e.g. forwarded mails or backup logs limited to
+/// 1 MiB, but bounds the memory a bogus file written directly to the queue can consume.
+const MAX_NOTIFICATION_SIZE: u64 = 16 * 1024 * 1024;
+
+fn fsync_queue_dir(queue_dir: &Path) -> Result<(), Error> {
+    std::fs::File::open(queue_dir)
+        .and_then(|dir| dir.sync_all())
+        .map_err(|err| Error::queue_with_source("fsync of queue directory failed", err))
+}
diff --git a/proxmox-notify/src/queue/submitter.rs b/proxmox-notify/src/queue/submitter.rs
new file mode 100644
index 000000000..3f96a2152
--- /dev/null
+++ b/proxmox-notify/src/queue/submitter.rs
@@ -0,0 +1,171 @@
+//! Submission of notifications to the queue.
+
+use std::path::PathBuf;
+
+use proxmox_sys::fs::CreateOptions;
+
+use crate::{Error, Notification};
+
+use super::MAX_NOTIFICATION_SIZE;
+
+/// Writes notifications to the queue directory.
+pub struct QueueSubmitter {
+    queue_dir: PathBuf,
+    create_options: CreateOptions,
+}
+
+impl QueueSubmitter {
+    /// Create a new submitter for the queue directory `base_dir`.
+    ///
+    /// Queued notification files are created with `create_options`.
+    pub fn new<P: Into<PathBuf>>(base_dir: P, create_options: CreateOptions) -> Self {
+        Self {
+            queue_dir: base_dir.into(),
+            create_options,
+        }
+    }
+
+    /// Add a notification to the queue.
+    ///
+    /// The file is written atomically and the queue directory is synced before returning.
+    pub fn submit(&self, notification: &Notification) -> Result<(), Error> {
+        let filename = format!("notification-{}", notification.id());
+        let path = self.queue_dir.join(filename);
+
+        let bytes = serde_json::to_vec(notification).map_err(|err| {
+            Error::other_with_source(
+                format!("failed to serialize notification {}", notification.id()),
+                err,
+            )
+        })?;
+
+        let serialized_size = bytes.len();
+        if serialized_size as u64 > MAX_NOTIFICATION_SIZE {
+            return Err(Error::invalid_notification(format!(
+                "serialized notification too large ({serialized_size} > {MAX_NOTIFICATION_SIZE} bytes)"
+            )));
+        }
+
+        proxmox_sys::fs::replace_file(&path, &bytes, self.create_options, true).map_err(|err| {
+            Error::queue_with_source(
+                format!(
+                    "failed to store serialized notification {}",
+                    notification.id()
+                ),
+                err,
+            )
+        })?;
+
+        super::fsync_queue_dir(&self.queue_dir)?;
+
+        tracing::info!(
+            "submitted notification {} to notification queue",
+            notification.id()
+        );
+
+        Ok(())
+    }
+}
+
+#[cfg(test)]
+mod test {
+    use proxmox_uuid::Uuid;
+    use serde_json::json;
+    use tempfile::tempdir;
+
+    use crate::notification::Content;
+
+    use super::*;
+
+    /// Build a notification that serializes to exactly `size` bytes.
+    fn notification_with_size(size: u64) -> Notification {
+        let mut notification = Notification::template_builder("foo", json!({ "pad": "" }))
+            .build()
+            .unwrap();
+
+        let base_size = serde_json::to_vec(&notification).unwrap().len() as u64;
+        let Content::Template { data, .. } = &mut notification.content else {
+            unreachable!();
+        };
+        data["pad"] = "a".repeat((size - base_size) as usize).into();
+
+        assert_eq!(
+            serde_json::to_vec(&notification).unwrap().len() as u64,
+            size
+        );
+
+        notification
+    }
+
+    #[test]
+    fn test_submit_multiple() {
+        let base_dir = tempdir().unwrap();
+        let submitter = QueueSubmitter::new(base_dir.path(), CreateOptions::new());
+
+        let notifications: Vec<_> = (0..3)
+            .map(|_| Notification::template_builder("foo", ()).build().unwrap())
+            .collect();
+
+        for notification in &notifications {
+            submitter.submit(notification).unwrap();
+        }
+
+        let entries: Vec<_> = std::fs::read_dir(base_dir.path())
+            .unwrap()
+            .map(|entry| entry.unwrap())
+            .collect();
+        assert_eq!(entries.len(), notifications.len());
+
+        for entry in entries {
+            let filename = entry.file_name().into_string().unwrap();
+            let id: Uuid = filename
+                .strip_prefix("notification-")
+                .unwrap()
+                .parse()
+                .unwrap();
+
+            let submitted = notifications.iter().find(|n| n.id() == &id).unwrap();
+
+            let content = std::fs::read(entry.path()).unwrap();
+            let queued: Notification = serde_json::from_slice(&content).unwrap();
+            assert_eq!(&queued, submitted);
+        }
+    }
+
+    #[test]
+    fn test_submit_missing_queue_dir() {
+        let base_dir = tempdir().unwrap();
+        let submitter = QueueSubmitter::new(base_dir.path().join("missing"), CreateOptions::new());
+
+        let notification = Notification::template_builder("foo", ()).build().unwrap();
+        assert!(submitter.submit(&notification).is_err());
+    }
+
+    #[test]
+    fn test_submit_max_size() {
+        let base_dir = tempdir().unwrap();
+        let submitter = QueueSubmitter::new(base_dir.path(), CreateOptions::new());
+
+        let notification = notification_with_size(MAX_NOTIFICATION_SIZE);
+        submitter.submit(&notification).unwrap();
+
+        let path = base_dir
+            .path()
+            .join(format!("notification-{}", notification.id()));
+        assert_eq!(
+            std::fs::metadata(path).unwrap().len(),
+            MAX_NOTIFICATION_SIZE
+        );
+    }
+
+    #[test]
+    fn test_submit_oversized() {
+        let base_dir = tempdir().unwrap();
+        let submitter = QueueSubmitter::new(base_dir.path(), CreateOptions::new());
+
+        let notification = notification_with_size(MAX_NOTIFICATION_SIZE + 1);
+        assert!(submitter.submit(&notification).is_err());
+
+        assert_eq!(std::fs::read_dir(base_dir.path()).unwrap().count(), 0);
+    }
+}
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 42/63] notify: context: add read_config
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (40 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 41/63] notify: implement notification queue submitter Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 43/63] notify: queue: add queue consumer Lukas Wagner
                   ` (21 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

The worker needs the ability to read the notification configuration,
which is implemented by adding a 'read_config' method to the ContextImpl
trait.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/src/context/mod.rs  |  4 ++++
 proxmox-notify/src/context/pbs.rs  | 19 +++++++++++++++++++
 proxmox-notify/src/context/pve.rs  | 17 +++++++++++++++++
 proxmox-notify/src/context/test.rs | 21 ++++++++++++++++++---
 4 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/proxmox-notify/src/context/mod.rs b/proxmox-notify/src/context/mod.rs
index c31e108fd..eb8011cf3 100644
--- a/proxmox-notify/src/context/mod.rs
+++ b/proxmox-notify/src/context/mod.rs
@@ -5,6 +5,7 @@ use std::sync::Arc;
 use proxmox_http::ProxyConfig;
 use proxmox_section_config::typed::SectionConfigData;
 
+use crate::Config;
 use crate::config::ConfigEntity;
 use crate::error::BoxedError;
 
@@ -63,6 +64,9 @@ pub trait ContextImpl: Send + Sync + Debug {
         namespace: Option<&str>,
         source: TemplateSource,
     ) -> Result<Option<String>, BoxedError>;
+
+    /// Read notification config.
+    fn read_config(&self) -> Result<Config, BoxedError>;
 }
 
 /// Choose between the provided `vendor` template or its by the user optionally created `override`
diff --git a/proxmox-notify/src/context/pbs.rs b/proxmox-notify/src/context/pbs.rs
index 7d3c51677..046d37055 100644
--- a/proxmox-notify/src/context/pbs.rs
+++ b/proxmox-notify/src/context/pbs.rs
@@ -9,6 +9,7 @@ use proxmox_schema::{ObjectSchema, Schema, StringSchema};
 use proxmox_section_config::typed::{ApiSectionDataEntry, SectionConfigData};
 use proxmox_section_config::{SectionConfig, SectionConfigPlugin};
 
+use crate::Config;
 use crate::config::ConfigEntity;
 use crate::context::{ContextImpl, TemplateSource, common};
 use crate::error::BoxedError;
@@ -136,6 +137,24 @@ impl ContextImpl for PBSContext {
 
         Ok(template_string)
     }
+
+    fn read_config(&self) -> Result<Config, BoxedError> {
+        let raw_config =
+            proxmox_sys::fs::file_read_optional_string("/etc/proxmox-backup/notifications.cfg")?
+                .unwrap_or_default();
+        let raw_private_config = proxmox_sys::fs::file_read_optional_string(
+            "/etc/proxmox-backup/notifications-priv.cfg",
+        )?
+        .unwrap_or_default();
+
+        let config = Config::parse_section_config(
+            &raw_config,
+            &raw_private_config,
+            Some(self.default_config()),
+        )?;
+
+        Ok(config)
+    }
 }
 
 #[cfg(test)]
diff --git a/proxmox-notify/src/context/pve.rs b/proxmox-notify/src/context/pve.rs
index a020b5cb4..f7d2ac13c 100644
--- a/proxmox-notify/src/context/pve.rs
+++ b/proxmox-notify/src/context/pve.rs
@@ -4,6 +4,7 @@ use std::sync::OnceLock;
 use proxmox_http::ProxyConfig;
 use proxmox_section_config::typed::{ApiSectionDataEntry, SectionConfigData};
 
+use crate::Config;
 use crate::config::ConfigEntity;
 use crate::context::{ContextImpl, TemplateSource, common};
 use crate::error::BoxedError;
@@ -87,6 +88,22 @@ impl ContextImpl for PVEContext {
 
         Ok(template_string)
     }
+
+    fn read_config(&self) -> Result<Config, BoxedError> {
+        let raw_config = proxmox_sys::fs::file_read_optional_string("/etc/pve/notifications.cfg")?
+            .unwrap_or_default();
+        let raw_private_config =
+            proxmox_sys::fs::file_read_optional_string("/etc/pve/priv/notifications.cfg")?
+                .unwrap_or_default();
+
+        let config = Config::parse_section_config(
+            &raw_config,
+            &raw_private_config,
+            Some(self.default_config()),
+        )?;
+
+        Ok(config)
+    }
 }
 
 pub static PVE_CONTEXT: PVEContext = PVEContext;
diff --git a/proxmox-notify/src/context/test.rs b/proxmox-notify/src/context/test.rs
index 6061e8c4d..bc68b6e41 100644
--- a/proxmox-notify/src/context/test.rs
+++ b/proxmox-notify/src/context/test.rs
@@ -3,6 +3,7 @@ use std::sync::OnceLock;
 use proxmox_http::ProxyConfig;
 use proxmox_section_config::typed::SectionConfigData;
 
+use crate::Config;
 use crate::Context;
 use crate::config::ConfigEntity;
 use crate::context::ContextImpl;
@@ -10,8 +11,11 @@ use crate::error::BoxedError;
 
 use super::TemplateSource;
 
-#[derive(Debug)]
-pub(crate) struct TestContext;
+#[derive(Debug, Default)]
+pub(crate) struct TestContext {
+    /// Make [`ContextImpl::read_config`] fail, to test how callers handle an unreadable config.
+    pub(crate) fail_read_config: bool,
+}
 
 impl ContextImpl for TestContext {
     fn lookup_email_for_user(&self, user: &str) -> Option<String> {
@@ -49,8 +53,19 @@ impl ContextImpl for TestContext {
     ) -> Result<Option<String>, BoxedError> {
         Ok(Some(String::new()))
     }
+
+    fn read_config(&self) -> Result<Config, BoxedError> {
+        if self.fail_read_config {
+            return Err(Box::new(crate::Error::other(
+                "injected config read failure",
+            )));
+        }
+
+        // An empty config has no targets and no matchers.
+        Ok(Config::parse_section_config("", "", None)?)
+    }
 }
 
 pub(crate) fn test_context() -> Context {
-    Context::new(TestContext)
+    Context::new(TestContext::default())
 }
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 43/63] notify: queue: add queue consumer
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (41 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 42/63] notify: context: add read_config Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox v2 44/63] notify: queue: add worker task Lukas Wagner
                   ` (20 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

Add a QueueConsumer type which allows one to consume queued
notifications from the product-specific notification queue.

When consuming a notification, it first goes to a 'claimed' state, which
atomically renames the notification queue file to record the state
change. If the worker is unexpectedly terminated or crashes while a
notification is being sent, the renamed notification file allows us to
detect this and attempt recovery by retrying the send. We don't ever
want to get caught in a 'send-crash-recover' loop where the same
notification is sent over and over again, so a retry counter is also
encoded in the file name of the notification. This allows the worker to
give up on retrying after a configurable number of attempts.

The queue consumer is gated behind the 'queue-worker' flag for now,
since the worker will the only consumer for now. Later, with a
notification history that would maybe also show queued notifications, a
separate feature could be in order.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/Cargo.toml            |   6 +
 proxmox-notify/src/error.rs          |  28 ++
 proxmox-notify/src/lib.rs            |   2 +-
 proxmox-notify/src/queue/consumer.rs | 513 +++++++++++++++++++++++++++
 proxmox-notify/src/queue/mod.rs      |  12 +
 5 files changed, 560 insertions(+), 1 deletion(-)
 create mode 100644 proxmox-notify/src/queue/consumer.rs

diff --git a/proxmox-notify/Cargo.toml b/proxmox-notify/Cargo.toml
index 4cfb1f2eb..fbdd5e601 100644
--- a/proxmox-notify/Cargo.toml
+++ b/proxmox-notify/Cargo.toml
@@ -16,6 +16,7 @@ const_format.workspace = true
 handlebars = { workspace = true, optional = true }
 http = { workspace = true, optional = true }
 lettre = { workspace = true, optional = true }
+libc = { workspace = true, optional = true }
 tracing.workspace = true
 mail-parser = { workspace = true, optional = true }
 percent-encoding = { workspace = true, optional = true }
@@ -41,6 +42,7 @@ proxmox-time.workspace = true
 proxmox-uuid = { workspace = true, features = ["serde"] }
 
 [dev-dependencies]
+nix = { workspace = true, features = ["fs"] }
 pretty_assertions.workspace = true
 tempfile.workspace = true
 
@@ -80,3 +82,7 @@ pve-context = ["dep:proxmox-sys", "legacy-matchers"]
 pbs-context = ["dep:proxmox-sys", "legacy-matchers"]
 legacy-matchers = []
 queue-submitter = ["dep:proxmox-sys"]
+queue-worker = [
+    "dep:libc",
+    "proxmox-sys/timer",
+]
diff --git a/proxmox-notify/src/error.rs b/proxmox-notify/src/error.rs
index bab240506..98e08a898 100644
--- a/proxmox-notify/src/error.rs
+++ b/proxmox-notify/src/error.rs
@@ -56,6 +56,15 @@ pub enum Error {
         source: Option<BoxedError>,
     },
 
+    /// A queued notification is invalid.
+    #[error("invalid file in notification queue: {err}", err = print_optional_error(.message, .source))]
+    InvalidQueuedNotification {
+        /// Description of the error.
+        message: String,
+        /// Underlying error, if any.
+        source: Option<BoxedError>,
+    },
+
     #[error("notification queue error: {err}", err = print_optional_error(.message, .source))]
     Queue {
         /// Description of the error.
@@ -163,6 +172,25 @@ impl Error {
         }
     }
 
+    /// Create an [`Error::InvalidQueuedNotification`] without an underlying error.
+    pub(crate) fn invalid_queued_notification(s: impl Into<String>) -> Self {
+        Self::InvalidQueuedNotification {
+            message: s.into(),
+            source: None,
+        }
+    }
+
+    /// Create an [`Error::InvalidQueuedNotification`] with an underlying error.
+    pub(crate) fn invalid_queued_notification_with_source(
+        s: impl Into<String>,
+        source: impl Into<BoxedError>,
+    ) -> Self {
+        Self::InvalidQueuedNotification {
+            message: s.into(),
+            source: Some(source.into()),
+        }
+    }
+
     /// Create an [`Error::Queue`] with an underlying error.
     pub(crate) fn queue_with_source(s: impl Into<String>, source: impl Into<BoxedError>) -> Self {
         Self::Queue {
diff --git a/proxmox-notify/src/lib.rs b/proxmox-notify/src/lib.rs
index ab5a929c1..6460e69ed 100644
--- a/proxmox-notify/src/lib.rs
+++ b/proxmox-notify/src/lib.rs
@@ -28,7 +28,7 @@ mod send;
 #[cfg(feature = "send-impl")]
 pub use send::send;
 
-#[cfg(feature = "queue-submitter")]
+#[cfg(any(feature = "queue-submitter", feature = "queue-worker"))]
 pub mod queue;
 
 mod error;
diff --git a/proxmox-notify/src/queue/consumer.rs b/proxmox-notify/src/queue/consumer.rs
new file mode 100644
index 000000000..2ee8a9b8c
--- /dev/null
+++ b/proxmox-notify/src/queue/consumer.rs
@@ -0,0 +1,513 @@
+//! Consumer side of the notification queue.
+
+use std::fs::File;
+use std::io::{self, Read};
+use std::os::unix::fs::OpenOptionsExt;
+use std::path::PathBuf;
+use std::time::Duration;
+
+use crate::{Error, Notification};
+
+use super::MAX_NOTIFICATION_SIZE;
+
+use proxmox_uuid::Uuid;
+
+/// Reads and manages queued notifications in the queue directory.
+///
+/// All state changes are done by renaming or removing the notification files, followed by an fsync
+/// of the queue directory.
+pub struct QueueConsumer {
+    queue_dir: PathBuf,
+}
+
+impl QueueConsumer {
+    /// Create a new consumer for the queue directory `base_dir`.
+    pub fn new<P: Into<PathBuf>>(base_dir: P) -> Self {
+        Self {
+            queue_dir: base_dir.into(),
+        }
+    }
+
+    /// Try to acquire an exclusive lock on the queue directory without blocking.
+    ///
+    /// The lock is held until the returned guard is dropped. Returns `None` if the lock is
+    /// currently held by someone else.
+    pub fn try_lock(&self) -> Result<Option<QueueLockGuard>, Error> {
+        let mut dir = File::open(&self.queue_dir).map_err(|err| {
+            Error::queue_with_source("could not open queue directory for locking", err)
+        })?;
+
+        match proxmox_sys::fs::lock_file(&mut dir, true, Some(Duration::ZERO)) {
+            Ok(()) => Ok(Some(QueueLockGuard { _dir: dir })),
+            Err(err) if err.kind() == io::ErrorKind::WouldBlock => Ok(None),
+            Err(err) => Err(Error::queue_with_source(
+                "could not lock queue directory",
+                err,
+            )),
+        }
+    }
+
+    /// Claim a notification for sending by incrementing its attempt counter.
+    ///
+    /// Returns the updated handle, which must be used for further operations.
+    pub fn claim(&self, queued: QueuedNotification) -> Result<QueuedNotification, Error> {
+        let claimed = queued.with_attempt(queued.attempt() + 1);
+
+        let old_path = self.queue_dir.join(queued.filename());
+        let new_path = self.queue_dir.join(claimed.filename());
+
+        std::fs::rename(old_path, new_path).map_err(|err| {
+            Error::queue_with_source("could not rename notification file when claiming it", err)
+        })?;
+
+        super::fsync_queue_dir(&self.queue_dir)?;
+
+        Ok(claimed)
+    }
+
+    /// Put a claimed notification back into the queue by decrementing its attempt counter.
+    ///
+    /// Used when sending failed without notifying any target, so that the attempt does not count
+    /// towards the retry limit. Returns the updated handle.
+    pub fn requeue(&self, queued: QueuedNotification) -> Result<QueuedNotification, Error> {
+        let requeued = queued.with_attempt(queued.attempt().saturating_sub(1));
+
+        let old_path = self.queue_dir.join(queued.filename());
+        let new_path = self.queue_dir.join(requeued.filename());
+
+        std::fs::rename(old_path, new_path).map_err(|err| {
+            Error::queue_with_source("could not rename notification file when requeuing it", err)
+        })?;
+
+        super::fsync_queue_dir(&self.queue_dir)?;
+
+        Ok(requeued)
+    }
+
+    /// Remove a notification from the queue.
+    pub fn resolve(&self, queued: QueuedNotification) -> Result<(), Error> {
+        let path = self.queue_dir.join(queued.filename());
+
+        std::fs::remove_file(path)
+            .map_err(|err| Error::queue_with_source("could not remove notification file", err))?;
+
+        super::fsync_queue_dir(&self.queue_dir)?;
+
+        Ok(())
+    }
+
+    /// Mark a notification as broken by appending `.broken` to its file name.
+    ///
+    /// Broken notifications are ignored by [`QueueConsumer::queued_notifications`], but kept for
+    /// later inspection.
+    pub fn mark_broken(&self, queued: QueuedNotification) -> Result<(), Error> {
+        let old_name = queued.filename();
+        let old_path = self.queue_dir.join(old_name);
+        let new_name = format!("{old_name}.broken");
+        let new_path = self.queue_dir.join(new_name);
+
+        std::fs::rename(old_path, new_path).map_err(|err| {
+            Error::queue_with_source(
+                "could not rename notification file when marking it as broken",
+                err,
+            )
+        })?;
+
+        super::fsync_queue_dir(&self.queue_dir)?;
+
+        Ok(())
+    }
+
+    /// Return all queued notifications, oldest submission first.
+    ///
+    /// Files that are not valid queued notifications are skipped.
+    pub fn queued_notifications(&self) -> Result<Vec<QueuedNotification>, Error> {
+        let read_dir = std::fs::read_dir(&self.queue_dir).map_err(|err| {
+            Error::queue_with_source("could not read notification queue directory", err)
+        })?;
+
+        let mut queued = Vec::new();
+
+        for entry in read_dir.flatten() {
+            let filename = entry.file_name();
+            let name = filename.to_string_lossy();
+
+            let Some(notification) = QueuedNotification::parse(&name) else {
+                continue;
+            };
+
+            // Renaming a file does not touch its mtime, so it reflects when the notification was
+            // submitted, regardless of how often it has been claimed or requeued since. Entries
+            // whose metadata cannot be read have most likely been removed concurrently.
+            if let Ok(mtime) = entry.metadata().and_then(|metadata| metadata.modified()) {
+                queued.push((mtime, notification));
+            }
+        }
+
+        queued.sort_by_key(|(mtime, _)| *mtime);
+
+        Ok(queued
+            .into_iter()
+            .map(|(_, notification)| notification)
+            .collect())
+    }
+
+    /// Read and deserialize the contents of a queued notification.
+    ///
+    /// Fails if the file is a symlink, not a regular file, or larger than
+    /// [`MAX_NOTIFICATION_SIZE`].
+    pub fn read_notification(&self, queued: &QueuedNotification) -> Result<Notification, Error> {
+        let path = self.queue_dir.join(queued.filename());
+
+        // Anybody allowed to submit can write to the queue directory directly, so neither follow
+        // symlinks nor block on opening a FIFO. The file type is checked on the opened file, as
+        // checking the path beforehand would race with the file being replaced.
+        let file = File::options()
+            .read(true)
+            .custom_flags(libc::O_NOFOLLOW | libc::O_NONBLOCK)
+            .open(path)
+            .map_err(|err| Error::queue_with_source("could not open queued notification", err))?;
+
+        let metadata = file
+            .metadata()
+            .map_err(|err| Error::queue_with_source("could not stat queued notification", err))?;
+
+        if !metadata.file_type().is_file() {
+            return Err(Error::invalid_queued_notification("not a regular file"));
+        }
+
+        let mut buf = Vec::new();
+        // Read one additional byte to detect whether the file exceeds the limit.
+        file.take(MAX_NOTIFICATION_SIZE + 1)
+            .read_to_end(&mut buf)
+            .map_err(|err| Error::queue_with_source("could not read queued notification", err))?;
+
+        if buf.len() as u64 > MAX_NOTIFICATION_SIZE {
+            return Err(Error::invalid_queued_notification(format!(
+                "exceeds maximum size of {MAX_NOTIFICATION_SIZE} bytes"
+            )));
+        }
+
+        let notification = serde_json::from_slice(&buf).map_err(|err| {
+            Error::invalid_queued_notification_with_source("could not deserialize JSON", err)
+        })?;
+
+        Ok(notification)
+    }
+}
+
+/// Exclusive lock on the queue directory, released on drop.
+pub struct QueueLockGuard {
+    _dir: File,
+}
+
+/// A notification in the queue directory, identified by its file name.
+///
+/// The file name encodes the whole queue state of a notification. A freshly submitted notification
+/// is stored as `notification-<uuid>`. Claiming it for sending renames it to
+/// `notification-<uuid>.attempt-<n>`.
+///
+/// The parser accepts some variations of these names, such as an uppercase UUID or a counter with
+/// leading zeros. The actual file name is therefore kept as found, so that it can always be
+/// accessed, and only renames write the canonical form.
+pub struct QueuedNotification {
+    id: Uuid,
+    attempt: Option<u32>,
+    filename: String,
+}
+
+impl QueuedNotification {
+    fn parse(filename: &str) -> Option<Self> {
+        if let Some(s) = filename.strip_prefix("notification-") {
+            let (uuid, attempt) = if let Some((uuid_str, attempt_str)) = s.split_once('.') {
+                let uuid = uuid_str.parse::<Uuid>().ok()?;
+                let attempt = attempt_str.strip_prefix("attempt-")?.parse::<u32>().ok()?;
+
+                (uuid, Some(attempt))
+            } else {
+                let uuid = s.parse::<Uuid>().ok()?;
+
+                (uuid, None)
+            };
+
+            Some(Self {
+                id: uuid,
+                attempt,
+                filename: filename.to_string(),
+            })
+        } else {
+            None
+        }
+    }
+
+    /// Return the same notification with the given attempt counter and the canonical file name
+    /// for it.
+    fn with_attempt(&self, attempt: u32) -> Self {
+        Self {
+            id: self.id.clone(),
+            attempt: Some(attempt),
+            filename: format!("notification-{}.attempt-{attempt}", self.id),
+        }
+    }
+
+    /// Return the filename of this queued notification.
+    fn filename(&self) -> &str {
+        &self.filename
+    }
+
+    /// Return the attempt counter.
+    pub fn attempt(&self) -> u32 {
+        self.attempt.unwrap_or(0)
+    }
+
+    /// Return the ID of the notification.
+    ///
+    /// The ID is only derived from the filename of the notification, not from
+    /// the contents.
+    pub fn id(&self) -> &Uuid {
+        &self.id
+    }
+}
+
+#[cfg(all(test, feature = "queue-submitter"))]
+mod test {
+    use std::time::{Duration, SystemTime};
+
+    use tempfile::tempdir;
+
+    use proxmox_sys::fs::CreateOptions;
+
+    use crate::queue::QueueSubmitter;
+
+    use super::*;
+
+    #[test]
+    fn test_enqueue() {
+        let base_dir = tempdir().unwrap();
+
+        let consumer = QueueConsumer::new(base_dir.path());
+        let queued = consumer.queued_notifications().unwrap();
+        assert!(queued.is_empty());
+
+        let submitter = QueueSubmitter::new(base_dir.path(), CreateOptions::new());
+        let notification = Notification::template_builder("foo", ()).build().unwrap();
+
+        submitter.submit(&notification).unwrap();
+
+        let mut queued = consumer.queued_notifications().unwrap();
+        assert_eq!(queued.len(), 1);
+
+        let n = queued.pop().unwrap();
+
+        assert_eq!(n.attempt(), 0);
+        let n = consumer.claim(n).unwrap();
+
+        assert_eq!(notification, consumer.read_notification(&n).unwrap());
+
+        consumer.resolve(n).unwrap();
+
+        let queued = consumer.queued_notifications().unwrap();
+        assert!(queued.is_empty());
+    }
+
+    #[test]
+    fn test_requeue() {
+        let base_dir = tempdir().unwrap();
+
+        let consumer = QueueConsumer::new(base_dir.path());
+
+        let submitter = QueueSubmitter::new(base_dir.path(), CreateOptions::new());
+        let notification = Notification::template_builder("foo", ()).build().unwrap();
+
+        submitter.submit(&notification).unwrap();
+
+        let mut queued = consumer.queued_notifications().unwrap();
+        assert_eq!(queued.len(), 1);
+
+        let n = queued.pop().unwrap();
+
+        let n = consumer.claim(n).unwrap();
+        let n = consumer.requeue(n).unwrap();
+
+        let queued = consumer.queued_notifications().unwrap();
+        assert_eq!(queued[0].attempt(), 0);
+
+        // Requeueing again must cap the attempt counter at 0
+        consumer.requeue(n).unwrap();
+        let queued = consumer.queued_notifications().unwrap();
+        assert_eq!(queued[0].attempt(), 0);
+    }
+
+    #[test]
+    fn test_attempt_counter() {
+        let base_dir = tempdir().unwrap();
+
+        let consumer = QueueConsumer::new(base_dir.path());
+
+        let submitter = QueueSubmitter::new(base_dir.path(), CreateOptions::new());
+        let notification = Notification::template_builder("foo", ()).build().unwrap();
+
+        submitter.submit(&notification).unwrap();
+
+        let mut queued = consumer.queued_notifications().unwrap();
+        assert_eq!(queued.len(), 1);
+        assert_eq!(queued[0].attempt(), 0);
+        consumer.claim(queued.pop().unwrap()).unwrap();
+
+        let mut queued = consumer.queued_notifications().unwrap();
+        assert_eq!(queued[0].attempt(), 1);
+        let _ = consumer.claim(queued.pop().unwrap()).unwrap();
+
+        let queued = consumer.queued_notifications().unwrap();
+        assert_eq!(queued[0].attempt(), 2);
+    }
+
+    #[test]
+    fn test_sorted_by_mtime() {
+        let base_dir = tempdir().unwrap();
+
+        let consumer = QueueConsumer::new(base_dir.path());
+        let submitter = QueueSubmitter::new(base_dir.path(), CreateOptions::new());
+
+        let notifications: Vec<_> = (0..5)
+            .map(|_| Notification::template_builder("foo", ()).build().unwrap())
+            .collect();
+
+        let now = SystemTime::now();
+
+        // Submit in order, but make earlier submissions appear newer
+        for (i, notification) in notifications.iter().enumerate() {
+            submitter.submit(notification).unwrap();
+
+            let path = base_dir
+                .path()
+                .join(format!("notification-{}", notification.id()));
+            let file = std::fs::File::options().write(true).open(path).unwrap();
+            file.set_modified(now - Duration::from_secs(i as u64 * 60))
+                .unwrap();
+        }
+
+        let queued = consumer.queued_notifications().unwrap();
+        let queued_ids: Vec<_> = queued.iter().map(|n| n.id().clone()).collect();
+        let expected_ids: Vec<_> = notifications.iter().rev().map(|n| n.id().clone()).collect();
+
+        assert_eq!(queued_ids, expected_ids);
+
+        // Claiming renames the file, which must not affect the order
+        let oldest = queued.into_iter().next().unwrap();
+        consumer.claim(oldest).unwrap();
+
+        let queued = consumer.queued_notifications().unwrap();
+        let queued_ids: Vec<_> = queued.iter().map(|n| n.id().clone()).collect();
+
+        assert_eq!(queued_ids, expected_ids);
+    }
+
+    #[test]
+    fn test_non_canonical_filenames() {
+        let base_dir = tempdir().unwrap();
+
+        let consumer = QueueConsumer::new(base_dir.path());
+
+        let notification = Notification::template_builder("foo", ()).build().unwrap();
+        let contents = serde_json::to_vec(&notification).unwrap();
+
+        // Uppercase UUID without an attempt counter, and a counter with a leading zero.
+        let uppercase_id = Uuid::generate();
+        let padded_id = Uuid::generate();
+        let filenames = [
+            format!("notification-{}", uppercase_id.to_string().to_uppercase()),
+            format!("notification-{padded_id}.attempt-01"),
+        ];
+        for filename in &filenames {
+            std::fs::write(base_dir.path().join(filename), &contents).unwrap();
+        }
+
+        let queued = consumer.queued_notifications().unwrap();
+        assert_eq!(queued.len(), 2);
+
+        for n in queued {
+            assert_eq!(consumer.read_notification(&n).unwrap(), notification);
+
+            let n = consumer.claim(n).unwrap();
+            assert_eq!(consumer.read_notification(&n).unwrap(), notification);
+
+            let n = consumer.requeue(n).unwrap();
+            consumer.resolve(n).unwrap();
+        }
+
+        assert!(consumer.queued_notifications().unwrap().is_empty());
+        assert_eq!(std::fs::read_dir(base_dir.path()).unwrap().count(), 0);
+    }
+
+    fn single_queued(consumer: &QueueConsumer) -> QueuedNotification {
+        let mut queued = consumer.queued_notifications().unwrap();
+        assert_eq!(queued.len(), 1);
+        queued.pop().unwrap()
+    }
+
+    #[test]
+    fn test_read_symlink() {
+        let base_dir = tempdir().unwrap();
+        let other_dir = tempdir().unwrap();
+
+        let consumer = QueueConsumer::new(base_dir.path());
+
+        let notification = Notification::template_builder("foo", ()).build().unwrap();
+        let target = other_dir.path().join("target");
+        std::fs::write(&target, serde_json::to_vec(&notification).unwrap()).unwrap();
+
+        let link = base_dir
+            .path()
+            .join(format!("notification-{}", notification.id()));
+        std::os::unix::fs::symlink(&target, link).unwrap();
+
+        let n = single_queued(&consumer);
+        assert!(consumer.read_notification(&n).is_err());
+    }
+
+    #[test]
+    fn test_read_fifo() {
+        let base_dir = tempdir().unwrap();
+
+        let consumer = QueueConsumer::new(base_dir.path());
+
+        let path = base_dir
+            .path()
+            .join(format!("notification-{}", Uuid::generate()));
+        nix::unistd::mkfifo(
+            &path,
+            nix::sys::stat::Mode::S_IRUSR | nix::sys::stat::Mode::S_IWUSR,
+        )
+        .unwrap();
+
+        // Without a writer, a blocking open would hang here.
+        let n = single_queued(&consumer);
+        assert!(consumer.read_notification(&n).is_err());
+    }
+
+    #[test]
+    fn test_read_oversized() {
+        let base_dir = tempdir().unwrap();
+
+        let consumer = QueueConsumer::new(base_dir.path());
+
+        let notification = Notification::template_builder("foo", ()).build().unwrap();
+        let path = base_dir
+            .path()
+            .join(format!("notification-{}", notification.id()));
+
+        // Trailing whitespace keeps the contents valid JSON, so only the size limit can reject it.
+        let mut contents = serde_json::to_vec(&notification).unwrap();
+        contents.resize(MAX_NOTIFICATION_SIZE as usize, b' ');
+        std::fs::write(&path, &contents).unwrap();
+
+        let n = single_queued(&consumer);
+        assert_eq!(consumer.read_notification(&n).unwrap(), notification);
+
+        contents.push(b' ');
+        std::fs::write(&path, &contents).unwrap();
+
+        assert!(consumer.read_notification(&n).is_err());
+    }
+}
diff --git a/proxmox-notify/src/queue/mod.rs b/proxmox-notify/src/queue/mod.rs
index 25137e123..11317aa04 100644
--- a/proxmox-notify/src/queue/mod.rs
+++ b/proxmox-notify/src/queue/mod.rs
@@ -1,16 +1,28 @@
+//! File-based notification queue and accompanying worker task.
+
+#[cfg(any(feature = "queue-submitter", feature = "queue-worker"))]
 use std::path::Path;
 
+#[cfg(any(feature = "queue-submitter", feature = "queue-worker"))]
 use crate::Error;
 
+#[cfg(feature = "queue-submitter")]
 mod submitter;
+#[cfg(feature = "queue-submitter")]
 pub use submitter::QueueSubmitter;
 
+#[cfg(feature = "queue-worker")]
+mod consumer;
+#[cfg(feature = "queue-worker")]
+pub use consumer::QueueConsumer;
+
 /// Maximum size of a queued notification file.
 ///
 /// Well above what legitimate producers submit, e.g. forwarded mails or backup logs limited to
 /// 1 MiB, but bounds the memory a bogus file written directly to the queue can consume.
 const MAX_NOTIFICATION_SIZE: u64 = 16 * 1024 * 1024;
 
+#[cfg(any(feature = "queue-submitter", feature = "queue-worker"))]
 fn fsync_queue_dir(queue_dir: &Path) -> Result<(), Error> {
     std::fs::File::open(queue_dir)
         .and_then(|dir| dir.sync_all())
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox v2 44/63] notify: queue: add worker task
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (42 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 43/63] notify: queue: add queue consumer Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox-backup v2 45/63] notifications: don't ignore verification errors in legacy-sendmail mode Lukas Wagner
                   ` (19 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

Add a QueueWorker which periodically polls the notification queue and
sends any queued notifications according to the current notification
configuration. The worker is meant to run as a long-lived task in each
product's daemon and is built via a QueueWorkerBuilder.

The configuration is re-read before each notification. In most cycles
there will be at most one notification to handle, but if sending one ran
into long SMTP or HTTP timeouts, the config might have changed in the
meantime. The notification is only claimed after the config was read
successfully. Otherwise, a temporarily broken config could make
notifications exceed their retry limit and be dropped, even though
sending was never attempted. A config error also aborts the rest of the
cycle, since all remaining notifications would fail the same way.

Retry attempts only cover the case where a previous worker got
interrupted after claiming a notification but before resolving it, for
example due to a crash. Notifications that exceed the configured limit
are dropped to avoid a send-crash-recover loop. By default, no retries
are performed. If crate::send returns an error, no target was notified
at all, so the notification is put back into the queue for the next
cycle. Notifications that cannot be deserialized are marked as broken
and are not picked up again.

To avoid spamming the logs every few seconds while something is
persistently broken, the polling interval is raised by a factor of 10
after more than 10 consecutive cycles with errors, and reset to the
default after the first successful cycle.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 proxmox-notify/Cargo.toml          |   3 +
 proxmox-notify/src/queue/mod.rs    |   5 +
 proxmox-notify/src/queue/worker.rs | 640 +++++++++++++++++++++++++++++
 3 files changed, 648 insertions(+)
 create mode 100644 proxmox-notify/src/queue/worker.rs

diff --git a/proxmox-notify/Cargo.toml b/proxmox-notify/Cargo.toml
index fbdd5e601..20bd3e7d4 100644
--- a/proxmox-notify/Cargo.toml
+++ b/proxmox-notify/Cargo.toml
@@ -25,6 +25,7 @@ serde = { workspace = true, features = ["derive"] }
 serde_json.workspace = true
 serde_regex = { workspace = true, optional = true }
 thiserror.workspace = true
+tokio = { workspace = true, optional = true, features = ["time", "rt"] }
 
 proxmox-api-macro = { workspace = true, optional = true }
 proxmox-base64 = { workspace = true, features = ["serde"]}
@@ -84,5 +85,7 @@ legacy-matchers = []
 queue-submitter = ["dep:proxmox-sys"]
 queue-worker = [
     "dep:libc",
+    "dep:tokio",
     "proxmox-sys/timer",
+    "send-impl",
 ]
diff --git a/proxmox-notify/src/queue/mod.rs b/proxmox-notify/src/queue/mod.rs
index 11317aa04..627cd43f6 100644
--- a/proxmox-notify/src/queue/mod.rs
+++ b/proxmox-notify/src/queue/mod.rs
@@ -16,6 +16,11 @@ mod consumer;
 #[cfg(feature = "queue-worker")]
 pub use consumer::QueueConsumer;
 
+#[cfg(feature = "queue-worker")]
+mod worker;
+#[cfg(feature = "queue-worker")]
+pub use worker::{QueueWorker, QueueWorkerBuilder};
+
 /// Maximum size of a queued notification file.
 ///
 /// Well above what legitimate producers submit, e.g. forwarded mails or backup logs limited to
diff --git a/proxmox-notify/src/queue/worker.rs b/proxmox-notify/src/queue/worker.rs
new file mode 100644
index 000000000..8d646c392
--- /dev/null
+++ b/proxmox-notify/src/queue/worker.rs
@@ -0,0 +1,640 @@
+//! Worker task that sends queued notifications.
+
+use std::sync::Arc;
+use std::time::Duration;
+
+use proxmox_uuid::Uuid;
+
+use crate::{Context, Error};
+
+use crate::queue::consumer::{QueueConsumer, QueueLockGuard, QueuedNotification};
+
+const DEFAULT_INTERVAL: Duration = Duration::from_secs(5);
+
+/// Builder for the [`QueueWorker`] type.
+///
+/// Construct this via [`QueueWorker::builder`] and
+/// finalize via [`QueueWorkerBuilder::build`].
+pub struct QueueWorkerBuilder {
+    context: Context,
+    queue: Arc<QueueConsumer>,
+
+    interval: Option<Duration>,
+    retry_attempts: Option<u32>,
+}
+
+impl QueueWorkerBuilder {
+    /// Set the interval at which the queue directory shall be polled
+    /// for new notifications.
+    ///
+    /// If not set, the interval defaults to 5 seconds.
+    pub fn interval(mut self, interval: Duration) -> Self {
+        self.interval = Some(interval);
+        self
+    }
+
+    /// Number of retry attempts before dropping the notification entirely.
+    ///
+    /// This is not for retries after failing to deliver a notification
+    /// to one or more targets individually, but for when the worker
+    /// got interrupted during sending before removing the notification
+    /// from the queue.
+    ///
+    /// If set to e.g. 2, then sending a notification would be retried *twice*
+    /// after the first attempt, so in total three attempts.
+    ///
+    /// If not set, no retries are performed.
+    pub fn retry_attempts(mut self, attempts: u32) -> Self {
+        self.retry_attempts = Some(attempts);
+        self
+    }
+
+    /// Build the final [`QueueWorker`].
+    ///
+    /// All optional fields that were not initialized are set to
+    /// their defaults.
+    pub fn build(self) -> QueueWorker {
+        QueueWorker {
+            context: self.context,
+            queue: self.queue,
+            polling_backoff: PollingBackoff::new(self.interval.unwrap_or(DEFAULT_INTERVAL)),
+            retry_attempts: self.retry_attempts.unwrap_or(0),
+
+            #[cfg(test)]
+            history: Vec::new(),
+        }
+    }
+}
+
+/// Worker task that sends queued notifications.
+///
+/// The worker periodically polls the notification queue, claims each queued notification, sends it
+/// according to the current notification configuration and removes it from the queue afterwards.
+/// On startup, notifications that were still in flight when the previous worker stopped are sent
+/// again, unless they have already reached the attempt limit, in which case they are dropped.
+pub struct QueueWorker {
+    context: Context,
+    queue: Arc<QueueConsumer>,
+    polling_backoff: PollingBackoff,
+    retry_attempts: u32,
+
+    #[cfg(test)]
+    history: Vec<HistoryEntry>,
+}
+
+impl QueueWorker {
+    /// Create the builder to instantiate this worker task.
+    pub fn builder(context: Context, consumer: QueueConsumer) -> QueueWorkerBuilder {
+        QueueWorkerBuilder {
+            context,
+            queue: Arc::new(consumer),
+            interval: None,
+            retry_attempts: None,
+        }
+    }
+
+    /// Run the worker.
+    ///
+    /// The queue is polled at the defined interval (see [`QueueWorkerBuilder::interval`]).
+    ///
+    /// This function does not return.
+    pub async fn run(mut self) -> ! {
+        loop {
+            self.process_queued_notifications().await;
+            self.wait().await;
+        }
+    }
+
+    async fn process_queued_notifications(&mut self) {
+        // Hold the queue lock for the whole cycle, so that no other consumer of the same queue
+        // directory claims, requeues or resolves notifications concurrently.
+        let lock_guard = match self.lock_queue().await {
+            Ok(Some(guard)) => Arc::new(guard),
+            Ok(None) => {
+                tracing::debug!("queue directory is locked by another consumer, skipping cycle");
+                return;
+            }
+            Err(err) => {
+                tracing::error!("failed to lock queue: {err}");
+                self.polling_backoff.increment_error_count();
+                return;
+            }
+        };
+
+        let mut any_error = false;
+
+        let queued_notifications = self
+            .queued_notifications()
+            .await
+            .inspect_err(|err| {
+                tracing::error!("failed to read queue: {err}");
+                any_error = true
+            })
+            .unwrap_or_default();
+
+        for queued_notification in queued_notifications {
+            let id = queued_notification.id().clone();
+            let queue = Arc::clone(&self.queue);
+            let context = self.context.clone();
+            let max_retries = self.retry_attempts;
+            // The blocking task keeps running if this future is dropped, e.g. on daemon shutdown.
+            // Keep the queue locked until it finishes, so that no other worker can pick up the
+            // same notification while it is still being sent.
+            let lock_guard = Arc::clone(&lock_guard);
+
+            let res = tokio::task::spawn_blocking(move || {
+                let _lock_guard = lock_guard;
+                let current_attempt = queued_notification.attempt();
+                let id = queued_notification.id().clone();
+
+                if current_attempt > max_retries {
+                    tracing::warn!("dropping notification {id} after attempt {current_attempt}");
+                    queue.resolve(queued_notification)?;
+
+                    return Ok(HistoryEntry {
+                        status: HistoryStatus::Dropped,
+                        id,
+                    });
+                }
+
+                // In most cases, we handle at most one notification in each cycle. If there are
+                // multiple to handle, it makes sense to re-read the config after each one, in case
+                // sending of one notification ran into long SMTP/HTTP timeouts.
+                let config = context
+                    .read_config()
+                    .map_err(Error::config_deserialization)?;
+
+                // The notification is claimed *after* the configuration was read, to ensure
+                // that a temporarily broken notification config does *not* lead to notifications
+                // being dropped because they have exceeded the maximum number of retries.
+                let queued_notification = queue.claim(queued_notification)?;
+
+                let notification = match queue.read_notification(&queued_notification) {
+                    Ok(notification) => notification,
+                    Err(err) => {
+                        if matches!(err, Error::InvalidQueuedNotification { .. }) {
+                            tracing::error!("marking notification as broken: {err}");
+                            // If the notification itself is bad, we move it aside and don't
+                            // process it again.
+                            queue.mark_broken(queued_notification)?;
+                        }
+                        return Err(err);
+                    }
+                };
+
+                tracing::info!("handling notification {}", queued_notification.id());
+
+                match crate::send(&context, &config, &notification) {
+                    Ok(_receipt) => {
+                        queue.resolve(queued_notification)?;
+
+                        Ok(HistoryEntry {
+                            id,
+                            status: HistoryStatus::Sent,
+                        })
+                    }
+                    Err(err) => {
+                        // An error here means that the notification for sure was
+                        // not sent to anyone, because sending failed at some point
+                        // *before* a single target was notified.
+                        //
+                        // The notification itself is fine, so we keep it around by
+                        // putting it back into the queue.
+                        // The returned error leads to the backoff error count being
+                        // increased, triggering the backoff mechanism to avoid spamming
+                        // logs every couple seconds.
+                        queue.requeue(queued_notification)?;
+
+                        Err(err)
+                    }
+                }
+            })
+            .await;
+
+            match res {
+                Ok(Ok(_history_entry)) => {
+                    #[cfg(test)]
+                    self.history.push(_history_entry);
+                }
+                Ok(Err(err)) => {
+                    tracing::error!(
+                        "notification worker failed to handle notification {id}: {err}"
+                    );
+                    any_error = true;
+
+                    if matches!(err, Error::ConfigDeserialization(_)) {
+                        // There is no point in processing the remaining queue if the config
+                        // does not parse, let's just retry at the next cycle.
+                        break;
+                    }
+                }
+                Err(err) => {
+                    tracing::error!(
+                        "failed to join task in notification worker for notification {id}: {err}"
+                    );
+                    any_error = true;
+                }
+            }
+        }
+
+        if any_error {
+            self.polling_backoff.increment_error_count();
+        } else {
+            self.polling_backoff.reset_error_count();
+        }
+    }
+
+    async fn lock_queue(&self) -> Result<Option<QueueLockGuard>, Error> {
+        let queue = Arc::clone(&self.queue);
+        tokio::task::spawn_blocking(move || queue.try_lock())
+            .await
+            .map_err(|err| Error::other_with_source("could not join tokio task", err))?
+    }
+
+    async fn queued_notifications(&self) -> Result<Vec<QueuedNotification>, Error> {
+        let queue = Arc::clone(&self.queue);
+        tokio::task::spawn_blocking(move || queue.queued_notifications())
+            .await
+            .map_err(|err| Error::other_with_source("could not join tokio task", err))?
+    }
+
+    async fn wait(&self) {
+        tokio::time::sleep(self.polling_backoff.active_interval()).await;
+    }
+}
+
+#[derive(Debug, PartialEq)]
+enum HistoryStatus {
+    Sent,
+    Dropped,
+}
+
+#[derive(Debug, PartialEq)]
+// Added for better testability, once the notification history is implemented,
+// this would be extended and moved to api_types.
+struct HistoryEntry {
+    id: Uuid,
+    status: HistoryStatus,
+}
+
+/// Number of consecutive erroneous cycles after which the polling interval is raised.
+const BACKOFF_THRESHOLD: u64 = 10;
+/// Factor by which the polling interval is raised while backing off.
+const BACKOFF_FACTOR: u32 = 10;
+
+struct PollingBackoff {
+    default_interval: Duration,
+    error_count: u64,
+}
+
+impl PollingBackoff {
+    fn new(interval: Duration) -> Self {
+        Self {
+            default_interval: interval,
+            error_count: 0,
+        }
+    }
+
+    fn is_backing_off(&self) -> bool {
+        self.error_count > BACKOFF_THRESHOLD
+    }
+
+    fn increment_error_count(&mut self) {
+        let was_backing_off = self.is_backing_off();
+        self.error_count = self.error_count.saturating_add(1);
+
+        if !was_backing_off && self.is_backing_off() {
+            tracing::info!(
+                "notification worker encountered several errors in succession, raising polling interval to {:?}",
+                self.active_interval()
+            );
+        }
+    }
+
+    fn reset_error_count(&mut self) {
+        let was_backing_off = self.is_backing_off();
+        self.error_count = 0;
+
+        if was_backing_off {
+            tracing::info!(
+                "notification worker resetting queue polling interval to default of {:?}",
+                self.default_interval
+            );
+        }
+    }
+
+    fn active_interval(&self) -> Duration {
+        if self.is_backing_off() {
+            self.default_interval.saturating_mul(BACKOFF_FACTOR)
+        } else {
+            self.default_interval
+        }
+    }
+}
+
+#[cfg(all(test, feature = "queue-submitter"))]
+mod test {
+    use std::cell::Cell;
+    use std::time::SystemTime;
+
+    use proxmox_sys::fs::CreateOptions;
+    use tempfile::{TempDir, tempdir};
+
+    use crate::Notification;
+    use crate::context::test::TestContext;
+    use crate::queue::QueueSubmitter;
+
+    use super::*;
+
+    struct WorkerTestSetup {
+        dir: TempDir,
+        consumer: QueueConsumer,
+        submitter: QueueSubmitter,
+        submitted: Cell<u64>,
+    }
+
+    impl WorkerTestSetup {
+        fn new() -> Self {
+            let dir = tempdir().unwrap();
+
+            Self {
+                consumer: QueueConsumer::new(dir.path()),
+                submitter: QueueSubmitter::new(dir.path(), CreateOptions::new()),
+                submitted: Cell::new(0),
+                dir,
+            }
+        }
+
+        fn submit_notification(&self) -> Uuid {
+            let notification = Notification::template_builder("foo", ()).build().unwrap();
+            self.submitter.submit(&notification).unwrap();
+
+            // Notifications submitted in quick succession may share the same mtime, so give each one
+            // a distinct one to have them handled in submission order.
+            let count = self.submitted.get();
+            self.submitted.set(count + 1);
+
+            let path = self
+                .dir
+                .path()
+                .join(format!("notification-{}", notification.id()));
+            std::fs::File::options()
+                .write(true)
+                .open(path)
+                .unwrap()
+                .set_modified(SystemTime::UNIX_EPOCH + Duration::from_secs(count))
+                .unwrap();
+
+            notification.id().clone()
+        }
+
+        /// Claim all queued notifications without resolving them, like a worker that got
+        /// interrupted while sending.
+        fn claim_all(&self) {
+            for queued in self.consumer.queued_notifications().unwrap() {
+                self.consumer.claim(queued).unwrap();
+            }
+        }
+
+        fn attempts(&self) -> Vec<u32> {
+            self.consumer
+                .queued_notifications()
+                .unwrap()
+                .iter()
+                .map(QueuedNotification::attempt)
+                .collect()
+        }
+
+        fn create_worker(
+            &self,
+            config_readable: bool,
+            retries_before_drop: Option<u32>,
+        ) -> QueueWorker {
+            // With the default empty config, sending succeeds without reaching any target.
+            let context = Context::new(TestContext {
+                fail_read_config: !config_readable,
+            });
+            let mut builder = QueueWorker::builder(context, QueueConsumer::new(self.dir.path()));
+
+            if let Some(attempts) = retries_before_drop {
+                builder = builder.retry_attempts(attempts);
+            }
+
+            builder.build()
+        }
+    }
+
+    fn run_single_cycle(worker: &mut QueueWorker) {
+        tokio::runtime::Builder::new_current_thread()
+            .build()
+            .unwrap()
+            .block_on(worker.process_queued_notifications());
+    }
+
+    #[test]
+    fn test_send_with_defaults() {
+        let setup = WorkerTestSetup::new();
+        let ids = [setup.submit_notification(), setup.submit_notification()];
+
+        let mut worker = setup.create_worker(true, None);
+        run_single_cycle(&mut worker);
+
+        assert!(setup.attempts().is_empty());
+        // Queued notifications are handled oldest first.
+        assert_eq!(
+            worker.history,
+            ids.map(|id| HistoryEntry {
+                id,
+                status: HistoryStatus::Sent,
+            })
+        );
+        assert_eq!(worker.polling_backoff.error_count, 0);
+    }
+
+    #[test]
+    fn test_skip_cycle_while_locked() {
+        let setup = WorkerTestSetup::new();
+        let id = setup.submit_notification();
+
+        let mut worker = setup.create_worker(true, None);
+
+        let guard = setup.consumer.try_lock().unwrap().unwrap();
+        run_single_cycle(&mut worker);
+
+        // Another consumer holds the lock, so the notification must not be touched.
+        assert_eq!(setup.attempts(), [0]);
+        assert!(worker.history.is_empty());
+        assert_eq!(worker.polling_backoff.error_count, 0);
+
+        drop(guard);
+        run_single_cycle(&mut worker);
+
+        assert!(setup.attempts().is_empty());
+        assert_eq!(
+            worker.history,
+            [HistoryEntry {
+                id,
+                status: HistoryStatus::Sent,
+            }]
+        );
+    }
+
+    #[test]
+    fn test_config_error_keeps_notification() {
+        let setup = WorkerTestSetup::new();
+        let id = setup.submit_notification();
+
+        let mut worker = setup.create_worker(false, None);
+        run_single_cycle(&mut worker);
+
+        // A config error must not count as an interrupted send.
+        assert_eq!(setup.attempts(), [0]);
+        assert!(worker.history.is_empty());
+        assert_eq!(worker.polling_backoff.error_count, 1);
+
+        // Once the config can be read again, the notification is sent.
+        let mut worker = setup.create_worker(true, None);
+        run_single_cycle(&mut worker);
+
+        assert!(setup.attempts().is_empty());
+        assert_eq!(
+            worker.history,
+            [HistoryEntry {
+                id,
+                status: HistoryStatus::Sent,
+            }]
+        );
+    }
+
+    #[test]
+    fn test_recover_interrupted_send() {
+        let setup = WorkerTestSetup::new();
+        let id = setup.submit_notification();
+        setup.claim_all();
+        assert_eq!(setup.attempts(), [1]);
+
+        let mut worker = setup.create_worker(true, Some(1));
+        run_single_cycle(&mut worker);
+
+        assert!(setup.attempts().is_empty());
+        assert_eq!(
+            worker.history,
+            [HistoryEntry {
+                id,
+                status: HistoryStatus::Sent,
+            }]
+        );
+        assert_eq!(worker.polling_backoff.error_count, 0);
+    }
+
+    #[test]
+    fn test_drop_after_recovery_attempts() {
+        let setup = WorkerTestSetup::new();
+        let id = setup.submit_notification();
+        setup.claim_all();
+        setup.claim_all();
+        assert_eq!(setup.attempts(), [2]);
+
+        let mut worker = setup.create_worker(true, Some(1));
+        run_single_cycle(&mut worker);
+
+        assert!(setup.attempts().is_empty());
+        assert_eq!(
+            worker.history,
+            [HistoryEntry {
+                id,
+                status: HistoryStatus::Dropped,
+            }]
+        );
+    }
+
+    #[test]
+    fn test_default_drops_interrupted_send() {
+        let setup = WorkerTestSetup::new();
+        let id = setup.submit_notification();
+        setup.claim_all();
+
+        let mut worker = setup.create_worker(true, None);
+        run_single_cycle(&mut worker);
+
+        assert!(setup.attempts().is_empty());
+        assert_eq!(
+            worker.history,
+            [HistoryEntry {
+                id,
+                status: HistoryStatus::Dropped,
+            }]
+        );
+    }
+
+    #[test]
+    fn test_unreadable_notification_marked_broken() {
+        let setup = WorkerTestSetup::new();
+        let valid_id = setup.submit_notification();
+
+        let broken_id = Uuid::generate();
+        std::fs::write(
+            setup.dir.path().join(format!("notification-{broken_id}")),
+            b"not json",
+        )
+        .unwrap();
+
+        let mut worker = setup.create_worker(true, None);
+        run_single_cycle(&mut worker);
+
+        // The broken notification is moved aside and does not keep the other one from being sent.
+        assert!(setup.attempts().is_empty());
+        assert_eq!(
+            worker.history,
+            [HistoryEntry {
+                id: valid_id,
+                status: HistoryStatus::Sent,
+            }]
+        );
+        assert!(
+            setup
+                .dir
+                .path()
+                .join(format!("notification-{broken_id}.attempt-1.broken"))
+                .exists()
+        );
+
+        // A broken notification is not picked up again.
+        run_single_cycle(&mut worker);
+
+        assert_eq!(worker.history.len(), 1);
+    }
+
+    #[test]
+    fn test_interval_backoff() {
+        let interval = Duration::from_secs(1);
+        let mut backoff = PollingBackoff::new(interval);
+
+        for _ in 0..10 {
+            backoff.increment_error_count();
+        }
+        assert_eq!(backoff.active_interval(), interval);
+
+        backoff.increment_error_count();
+        assert_eq!(backoff.active_interval(), interval * 10);
+
+        backoff.reset_error_count();
+        assert_eq!(backoff.active_interval(), interval);
+
+        // Backoff must trigger again after another series of errors.
+        for _ in 0..11 {
+            backoff.increment_error_count();
+        }
+        assert_eq!(backoff.active_interval(), interval * 10);
+    }
+
+    #[test]
+    fn test_interval_backoff_saturates() {
+        let mut backoff = PollingBackoff::new(Duration::MAX);
+
+        for _ in 0..11 {
+            backoff.increment_error_count();
+        }
+        assert_eq!(backoff.active_interval(), Duration::MAX);
+    }
+}
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox-backup v2 45/63] notifications: don't ignore verification errors in legacy-sendmail mode
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (43 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox v2 44/63] notify: queue: add worker task Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox-backup v2 46/63] notifications: adapt to proxmox-notify API changes Lukas Wagner
                   ` (18 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

A verification job that fails to verify some snapshots still returns
Ok, with the failed snapshots in the returned list. The legacy-sendmail
code path only checked result.is_ok(), so with 'notify=error' no mail
was sent for such jobs, even though a 'verify-err' notification had
been generated.

Treat the job as successful only if the list of failed snapshots is
empty, consistent with how the notification itself is built.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 src/server/notifications/mod.rs | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/server/notifications/mod.rs b/src/server/notifications/mod.rs
index cd200a44d..21bec254b 100644
--- a/src/server/notifications/mod.rs
+++ b/src/server/notifications/mod.rs
@@ -256,7 +256,9 @@ pub fn send_verify_status(
         NotificationMode::LegacySendmail => {
             let notify = notify.verify.unwrap_or(Notify::Always);
 
-            if notify == Notify::Never || (result.is_ok() && notify == Notify::Error) {
+            if notify == Notify::Never
+                || (matches!(result, Ok(errors) if errors.is_empty()) && notify == Notify::Error)
+            {
                 return Ok(());
             }
 
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox-backup v2 46/63] notifications: adapt to proxmox-notify API changes
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (44 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox-backup v2 45/63] notifications: don't ignore verification errors in legacy-sendmail mode Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox-backup v2 47/63] api: notification: send test notification via proxmox_notify::send Lukas Wagner
                   ` (17 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

proxmox-notify no longer keeps a global context. Instead, a Context
instance is passed explicitly when parsing the configuration and
sending notifications. Keep a lazily initialized PBS context in
server::notifications and drop the explicit init() calls from the
daemons and proxmox-daily-update.

Notifications are now created via Notification::template_builder and
carry an explicit recipient: either a set of email addresses for
datastores and tape jobs in legacy-sendmail mode, or the matchers when
using the notification system. Determining the recipient, including
the legacy notify=never/error filtering, is moved into shared helpers.
Since legacy-sendmail notifications are no longer sent by calling the
sendmail endpoint directly, they now take the same path as all other
notifications, including being queued when sent from an unprivileged
process.

The remaining changes are mechanical: API types now live in
proxmox_notify::api_types, the Deleteable* types were renamed to
Deletable*, and config digests are passed as ConfigDigest instead of
hex-encoded strings. The 'api-types', 'api-impl' and 'send-impl'
features of proxmox-notify are enabled accordingly.

This changes should not have any observable effect for the user, with
one tiny exception. Now, notifications sent via the 'legacy-sendmail'
mode still read and parse the config, due to the unified code paths
while sending. As a result, unlike before, a broken notification config
would also cause a failed delivery for 'legacy-sendmail' notifications.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 Cargo.toml                                    |   2 +-
 pbs-config/Cargo.toml                         |  10 +-
 pbs-config/src/notifications.rs               |  10 +-
 src/api2/config/notifications/gotify.rs       |  31 +-
 src/api2/config/notifications/matchers.rs     |  29 +-
 src/api2/config/notifications/sendmail.rs     |  29 +-
 src/api2/config/notifications/smtp.rs         |  29 +-
 src/api2/config/notifications/targets.rs      |  13 +-
 src/api2/config/notifications/webhook.rs      |  29 +-
 src/bin/docgen.rs                             |   7 +-
 src/bin/proxmox-backup-api.rs                 |   1 -
 src/bin/proxmox-backup-manager.rs             |   1 -
 src/bin/proxmox-backup-proxy.rs               |   1 -
 src/bin/proxmox-daily-update.rs               |   3 -
 .../notifications/gotify.rs                   |   2 +-
 .../notifications/matchers.rs                 |   2 +-
 .../notifications/sendmail.rs                 |   2 +-
 .../notifications/smtp.rs                     |   2 +-
 .../notifications/webhook.rs                  |   2 +-
 src/server/notifications/mod.rs               | 449 ++++++++----------
 20 files changed, 301 insertions(+), 353 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 67245fede..b83924a85 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -230,7 +230,7 @@ proxmox-ldap.workspace = true
 proxmox-metrics.workspace = true
 proxmox-network-api = { workspace = true, features = [ "impl" ] }
 proxmox-network-types.workspace = true
-proxmox-notify = { workspace = true, features = [ "pbs-context", "legacy-matchers" ] }
+proxmox-notify = { workspace = true, features = [ "pbs-context", "legacy-matchers", "api-impl", "send-impl", "api-types" ]}
 proxmox-openid.workspace = true
 proxmox-product-config.workspace = true
 proxmox-parallel-handler.workspace = true
diff --git a/pbs-config/Cargo.toml b/pbs-config/Cargo.toml
index dfc1acf61..8cc9102a2 100644
--- a/pbs-config/Cargo.toml
+++ b/pbs-config/Cargo.toml
@@ -21,7 +21,15 @@ serde_json.workspace = true
 
 proxmox-http.workspace = true
 proxmox-lang.workspace = true
-proxmox-notify.workspace = true
+proxmox-notify = {
+    workspace = true,
+    features = [
+        "pbs-context",
+        "legacy-matchers",
+        "api-impl",
+        "api-types",
+    ]
+}
 proxmox-router = { workspace = true, default-features = false }
 proxmox-product-config.workspace = true
 proxmox-s3-client.workspace = true
diff --git a/pbs-config/src/notifications.rs b/pbs-config/src/notifications.rs
index 53555bda9..9031feafb 100644
--- a/pbs-config/src/notifications.rs
+++ b/pbs-config/src/notifications.rs
@@ -22,19 +22,23 @@ pub fn lock_config() -> Result<BackupLockGuard, Error> {
 }
 
 /// Load notification config.
-pub fn config() -> Result<Config, Error> {
+pub fn config(context: &proxmox_notify::Context) -> Result<Config, Error> {
     let content =
         proxmox_sys::fs::file_read_optional_string(NOTIFICATION_CONFIG_PATH)?.unwrap_or_default();
 
     let priv_content = proxmox_sys::fs::file_read_optional_string(NOTIFICATION_PRIV_CONFIG_PATH)?
         .unwrap_or_default();
 
-    Ok(Config::new(&content, &priv_content)?)
+    Ok(Config::parse_section_config(
+        &content,
+        &priv_content,
+        Some(context.default_config()),
+    )?)
 }
 
 /// Save notification config.
 pub fn save_config(config: Config) -> Result<(), Error> {
-    let (cfg, priv_cfg) = config.write()?;
+    let (cfg, priv_cfg) = config.to_section_config()?;
     replace_privileged_config(NOTIFICATION_CONFIG_PATH, cfg.as_bytes())?;
     proxmox_product_config::replace_secret_config(
         NOTIFICATION_PRIV_CONFIG_PATH,
diff --git a/src/api2/config/notifications/gotify.rs b/src/api2/config/notifications/gotify.rs
index 1f14b377b..99f93cb77 100644
--- a/src/api2/config/notifications/gotify.rs
+++ b/src/api2/config/notifications/gotify.rs
@@ -1,16 +1,18 @@
 use anyhow::Error;
 use serde_json::Value;
 
-use proxmox_notify::endpoints::gotify::{
-    DeleteableGotifyProperty, GotifyConfig, GotifyConfigUpdater, GotifyPrivateConfig,
-    GotifyPrivateConfigUpdater,
+use proxmox_config_digest::ConfigDigest;
+use proxmox_notify::api_types::{
+    DeletableGotifyProperty, ENTITY_NAME_SCHEMA, GotifyConfig, GotifyConfigUpdater,
+    GotifyPrivateConfig, GotifyPrivateConfigUpdater,
 };
-use proxmox_notify::schema::ENTITY_NAME_SCHEMA;
 use proxmox_router::{Permission, Router, RpcEnvironment};
 use proxmox_schema::api;
 
 use pbs_api_types::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY, PROXMOX_CONFIG_DIGEST_SCHEMA};
 
+use crate::server;
+
 #[api(
     protected: true,
     input: {
@@ -30,7 +32,7 @@ pub fn list_endpoints(
     _param: Value,
     _rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<Vec<GotifyConfig>, Error> {
-    let config = pbs_config::notifications::config()?;
+    let config = pbs_config::notifications::config(server::notifications::context())?;
 
     let endpoints = proxmox_notify::api::gotify::get_endpoints(&config)?;
 
@@ -53,10 +55,10 @@ pub fn list_endpoints(
 )]
 /// Get a gotify endpoint.
 pub fn get_endpoint(name: String, rpcenv: &mut dyn RpcEnvironment) -> Result<GotifyConfig, Error> {
-    let config = pbs_config::notifications::config()?;
+    let config = pbs_config::notifications::config(server::notifications::context())?;
     let endpoint = proxmox_notify::api::gotify::get_endpoint(&config, &name)?;
 
-    rpcenv["digest"] = hex::encode(config.digest()).into();
+    rpcenv["digest"] = config.digest().to_hex().into();
 
     Ok(endpoint)
 }
@@ -85,7 +87,7 @@ pub fn add_endpoint(
     _rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<(), Error> {
     let _lock = pbs_config::notifications::lock_config()?;
-    let mut config = pbs_config::notifications::config()?;
+    let mut config = pbs_config::notifications::config(server::notifications::context())?;
     let private_endpoint_config = GotifyPrivateConfig {
         name: endpoint.name.clone(),
         token,
@@ -117,7 +119,7 @@ pub fn add_endpoint(
                 type: Array,
                 optional: true,
                 items: {
-                    type: DeleteableGotifyProperty,
+                    type: DeletableGotifyProperty,
                 }
             },
             digest: {
@@ -135,13 +137,12 @@ pub fn update_endpoint(
     name: String,
     updater: GotifyConfigUpdater,
     token: Option<String>,
-    delete: Option<Vec<DeleteableGotifyProperty>>,
-    digest: Option<String>,
+    delete: Option<Vec<DeletableGotifyProperty>>,
+    digest: Option<ConfigDigest>,
     _rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<(), Error> {
     let _lock = pbs_config::notifications::lock_config()?;
-    let mut config = pbs_config::notifications::config()?;
-    let digest = digest.map(hex::decode).transpose()?;
+    let mut config = pbs_config::notifications::config(server::notifications::context())?;
 
     proxmox_notify::api::gotify::update_endpoint(
         &mut config,
@@ -149,7 +150,7 @@ pub fn update_endpoint(
         updater,
         GotifyPrivateConfigUpdater { token },
         delete.as_deref(),
-        digest.as_deref(),
+        digest,
     )?;
 
     pbs_config::notifications::save_config(config)?;
@@ -172,7 +173,7 @@ pub fn update_endpoint(
 /// Delete gotify endpoint.
 pub fn delete_endpoint(name: String, _rpcenv: &mut dyn RpcEnvironment) -> Result<(), Error> {
     let _lock = pbs_config::notifications::lock_config()?;
-    let mut config = pbs_config::notifications::config()?;
+    let mut config = pbs_config::notifications::config(server::notifications::context())?;
     proxmox_notify::api::gotify::delete_gotify_endpoint(&mut config, &name)?;
 
     pbs_config::notifications::save_config(config)?;
diff --git a/src/api2/config/notifications/matchers.rs b/src/api2/config/notifications/matchers.rs
index 504d26d40..d639ef36d 100644
--- a/src/api2/config/notifications/matchers.rs
+++ b/src/api2/config/notifications/matchers.rs
@@ -1,13 +1,17 @@
 use anyhow::Error;
 use serde_json::Value;
 
-use proxmox_notify::matcher::{DeleteableMatcherProperty, MatcherConfig, MatcherConfigUpdater};
-use proxmox_notify::schema::ENTITY_NAME_SCHEMA;
+use proxmox_config_digest::ConfigDigest;
+use proxmox_notify::api_types::{
+    DeletableMatcherProperty, ENTITY_NAME_SCHEMA, MatcherConfig, MatcherConfigUpdater,
+};
 use proxmox_router::{Permission, Router, RpcEnvironment};
 use proxmox_schema::api;
 
 use pbs_api_types::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY, PROXMOX_CONFIG_DIGEST_SCHEMA};
 
+use crate::server;
+
 #[api(
     protected: true,
     input: {
@@ -27,7 +31,7 @@ pub fn list_matchers(
     _param: Value,
     _rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<Vec<MatcherConfig>, Error> {
-    let config = pbs_config::notifications::config()?;
+    let config = pbs_config::notifications::config(server::notifications::context())?;
 
     let matchers = proxmox_notify::api::matcher::get_matchers(&config)?;
 
@@ -59,7 +63,7 @@ pub fn get_matcher(
     migrate_to_expression: bool,
     rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<MatcherConfig, Error> {
-    let config = pbs_config::notifications::config()?;
+    let config = pbs_config::notifications::config(server::notifications::context())?;
 
     let matcher = if migrate_to_expression {
         proxmox_notify::api::matcher::get_matcher_as_expression(&config, &name)?
@@ -67,7 +71,7 @@ pub fn get_matcher(
         proxmox_notify::api::matcher::get_matcher(&config, &name)?
     };
 
-    rpcenv["digest"] = hex::encode(config.digest()).into();
+    rpcenv["digest"] = config.digest().to_hex().into();
 
     Ok(matcher)
 }
@@ -89,7 +93,7 @@ pub fn get_matcher(
 /// Add a new notification matcher.
 pub fn add_matcher(matcher: MatcherConfig, _rpcenv: &mut dyn RpcEnvironment) -> Result<(), Error> {
     let _lock = pbs_config::notifications::lock_config()?;
-    let mut config = pbs_config::notifications::config()?;
+    let mut config = pbs_config::notifications::config(server::notifications::context())?;
 
     proxmox_notify::api::matcher::add_matcher(&mut config, matcher)?;
 
@@ -113,7 +117,7 @@ pub fn add_matcher(matcher: MatcherConfig, _rpcenv: &mut dyn RpcEnvironment) ->
                 type: Array,
                 optional: true,
                 items: {
-                    type: DeleteableMatcherProperty,
+                    type: DeletableMatcherProperty,
                 }
             },
             digest: {
@@ -130,20 +134,19 @@ pub fn add_matcher(matcher: MatcherConfig, _rpcenv: &mut dyn RpcEnvironment) ->
 pub fn update_matcher(
     name: String,
     updater: MatcherConfigUpdater,
-    delete: Option<Vec<DeleteableMatcherProperty>>,
-    digest: Option<String>,
+    delete: Option<Vec<DeletableMatcherProperty>>,
+    digest: Option<ConfigDigest>,
     _rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<(), Error> {
     let _lock = pbs_config::notifications::lock_config()?;
-    let mut config = pbs_config::notifications::config()?;
-    let digest = digest.map(hex::decode).transpose()?;
+    let mut config = pbs_config::notifications::config(server::notifications::context())?;
 
     proxmox_notify::api::matcher::update_matcher(
         &mut config,
         &name,
         updater,
         delete.as_deref(),
-        digest.as_deref(),
+        digest,
     )?;
 
     pbs_config::notifications::save_config(config)?;
@@ -166,7 +169,7 @@ pub fn update_matcher(
 /// Delete notification matcher.
 pub fn delete_matcher(name: String, _rpcenv: &mut dyn RpcEnvironment) -> Result<(), Error> {
     let _lock = pbs_config::notifications::lock_config()?;
-    let mut config = pbs_config::notifications::config()?;
+    let mut config = pbs_config::notifications::config(server::notifications::context())?;
     proxmox_notify::api::matcher::delete_matcher(&mut config, &name)?;
 
     pbs_config::notifications::save_config(config)?;
diff --git a/src/api2/config/notifications/sendmail.rs b/src/api2/config/notifications/sendmail.rs
index b8ce6b2b1..875784afc 100644
--- a/src/api2/config/notifications/sendmail.rs
+++ b/src/api2/config/notifications/sendmail.rs
@@ -1,15 +1,17 @@
 use anyhow::Error;
 use serde_json::Value;
 
-use proxmox_notify::endpoints::sendmail::{
-    DeleteableSendmailProperty, SendmailConfig, SendmailConfigUpdater,
+use proxmox_config_digest::ConfigDigest;
+use proxmox_notify::api_types::{
+    DeletableSendmailProperty, ENTITY_NAME_SCHEMA, SendmailConfig, SendmailConfigUpdater,
 };
-use proxmox_notify::schema::ENTITY_NAME_SCHEMA;
 use proxmox_router::{Permission, Router, RpcEnvironment};
 use proxmox_schema::api;
 
 use pbs_api_types::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY, PROXMOX_CONFIG_DIGEST_SCHEMA};
 
+use crate::server;
+
 #[api(
     protected: true,
     input: {
@@ -29,7 +31,7 @@ pub fn list_endpoints(
     _param: Value,
     _rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<Vec<SendmailConfig>, Error> {
-    let config = pbs_config::notifications::config()?;
+    let config = pbs_config::notifications::config(server::notifications::context())?;
 
     let endpoints = proxmox_notify::api::sendmail::get_endpoints(&config)?;
 
@@ -55,10 +57,10 @@ pub fn get_endpoint(
     name: String,
     rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<SendmailConfig, Error> {
-    let config = pbs_config::notifications::config()?;
+    let config = pbs_config::notifications::config(server::notifications::context())?;
     let endpoint = proxmox_notify::api::sendmail::get_endpoint(&config, &name)?;
 
-    rpcenv["digest"] = hex::encode(config.digest()).into();
+    rpcenv["digest"] = config.digest().to_hex().into();
 
     Ok(endpoint)
 }
@@ -83,7 +85,7 @@ pub fn add_endpoint(
     _rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<(), Error> {
     let _lock = pbs_config::notifications::lock_config()?;
-    let mut config = pbs_config::notifications::config()?;
+    let mut config = pbs_config::notifications::config(server::notifications::context())?;
 
     proxmox_notify::api::sendmail::add_endpoint(&mut config, endpoint)?;
 
@@ -107,7 +109,7 @@ pub fn add_endpoint(
                 type: Array,
                 optional: true,
                 items: {
-                    type: DeleteableSendmailProperty,
+                    type: DeletableSendmailProperty,
                 }
             },
             digest: {
@@ -124,20 +126,19 @@ pub fn add_endpoint(
 pub fn update_endpoint(
     name: String,
     updater: SendmailConfigUpdater,
-    delete: Option<Vec<DeleteableSendmailProperty>>,
-    digest: Option<String>,
+    delete: Option<Vec<DeletableSendmailProperty>>,
+    digest: Option<ConfigDigest>,
     _rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<(), Error> {
     let _lock = pbs_config::notifications::lock_config()?;
-    let mut config = pbs_config::notifications::config()?;
-    let digest = digest.map(hex::decode).transpose()?;
+    let mut config = pbs_config::notifications::config(server::notifications::context())?;
 
     proxmox_notify::api::sendmail::update_endpoint(
         &mut config,
         &name,
         updater,
         delete.as_deref(),
-        digest.as_deref(),
+        digest,
     )?;
 
     pbs_config::notifications::save_config(config)?;
@@ -160,7 +161,7 @@ pub fn update_endpoint(
 /// Delete sendmail endpoint.
 pub fn delete_endpoint(name: String, _rpcenv: &mut dyn RpcEnvironment) -> Result<(), Error> {
     let _lock = pbs_config::notifications::lock_config()?;
-    let mut config = pbs_config::notifications::config()?;
+    let mut config = pbs_config::notifications::config(server::notifications::context())?;
     proxmox_notify::api::sendmail::delete_endpoint(&mut config, &name)?;
 
     pbs_config::notifications::save_config(config)?;
diff --git a/src/api2/config/notifications/smtp.rs b/src/api2/config/notifications/smtp.rs
index 8df2ab18c..6d9313403 100644
--- a/src/api2/config/notifications/smtp.rs
+++ b/src/api2/config/notifications/smtp.rs
@@ -1,16 +1,18 @@
 use anyhow::Error;
 use serde_json::Value;
 
-use proxmox_notify::endpoints::smtp::{
-    DeleteableSmtpProperty, SmtpConfig, SmtpConfigUpdater, SmtpPrivateConfig,
+use proxmox_config_digest::ConfigDigest;
+use proxmox_notify::api_types::{
+    DeletableSmtpProperty, ENTITY_NAME_SCHEMA, SmtpConfig, SmtpConfigUpdater, SmtpPrivateConfig,
     SmtpPrivateConfigUpdater,
 };
-use proxmox_notify::schema::ENTITY_NAME_SCHEMA;
 use proxmox_router::{Permission, Router, RpcEnvironment};
 use proxmox_schema::api;
 
 use pbs_api_types::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY, PROXMOX_CONFIG_DIGEST_SCHEMA};
 
+use crate::server;
+
 #[api(
     protected: true,
     input: {
@@ -30,7 +32,7 @@ pub fn list_endpoints(
     _param: Value,
     _rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<Vec<SmtpConfig>, Error> {
-    let config = pbs_config::notifications::config()?;
+    let config = pbs_config::notifications::config(server::notifications::context())?;
 
     let endpoints = proxmox_notify::api::smtp::get_endpoints(&config)?;
 
@@ -53,10 +55,10 @@ pub fn list_endpoints(
 )]
 /// Get a smtp endpoint.
 pub fn get_endpoint(name: String, rpcenv: &mut dyn RpcEnvironment) -> Result<SmtpConfig, Error> {
-    let config = pbs_config::notifications::config()?;
+    let config = pbs_config::notifications::config(server::notifications::context())?;
     let endpoint = proxmox_notify::api::smtp::get_endpoint(&config, &name)?;
 
-    rpcenv["digest"] = hex::encode(config.digest()).into();
+    rpcenv["digest"] = config.digest().to_hex().into();
 
     Ok(endpoint)
 }
@@ -86,7 +88,7 @@ pub fn add_endpoint(
     _rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<(), Error> {
     let _lock = pbs_config::notifications::lock_config()?;
-    let mut config = pbs_config::notifications::config()?;
+    let mut config = pbs_config::notifications::config(server::notifications::context())?;
     let private_endpoint_config = SmtpPrivateConfig {
         name: endpoint.name.clone(),
         password,
@@ -118,7 +120,7 @@ pub fn add_endpoint(
                 type: Array,
                 optional: true,
                 items: {
-                    type: DeleteableSmtpProperty,
+                    type: DeletableSmtpProperty,
                 }
             },
             digest: {
@@ -136,13 +138,12 @@ pub fn update_endpoint(
     name: String,
     updater: SmtpConfigUpdater,
     password: Option<String>,
-    delete: Option<Vec<DeleteableSmtpProperty>>,
-    digest: Option<String>,
+    delete: Option<Vec<DeletableSmtpProperty>>,
+    digest: Option<ConfigDigest>,
     _rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<(), Error> {
     let _lock = pbs_config::notifications::lock_config()?;
-    let mut config = pbs_config::notifications::config()?;
-    let digest = digest.map(hex::decode).transpose()?;
+    let mut config = pbs_config::notifications::config(server::notifications::context())?;
 
     proxmox_notify::api::smtp::update_endpoint(
         &mut config,
@@ -150,7 +151,7 @@ pub fn update_endpoint(
         updater,
         SmtpPrivateConfigUpdater { password },
         delete.as_deref(),
-        digest.as_deref(),
+        digest,
     )?;
 
     pbs_config::notifications::save_config(config)?;
@@ -173,7 +174,7 @@ pub fn update_endpoint(
 /// Delete smtp endpoint.
 pub fn delete_endpoint(name: String, _rpcenv: &mut dyn RpcEnvironment) -> Result<(), Error> {
     let _lock = pbs_config::notifications::lock_config()?;
-    let mut config = pbs_config::notifications::config()?;
+    let mut config = pbs_config::notifications::config(server::notifications::context())?;
     proxmox_notify::api::smtp::delete_endpoint(&mut config, &name)?;
 
     pbs_config::notifications::save_config(config)?;
diff --git a/src/api2/config/notifications/targets.rs b/src/api2/config/notifications/targets.rs
index ee9f2b26d..bf0cfa3de 100644
--- a/src/api2/config/notifications/targets.rs
+++ b/src/api2/config/notifications/targets.rs
@@ -1,14 +1,15 @@
 use anyhow::Error;
 use serde_json::Value;
 
-use proxmox_notify::api::Target;
-use proxmox_notify::schema::ENTITY_NAME_SCHEMA;
+use proxmox_notify::api_types::{ENTITY_NAME_SCHEMA, Target};
 use proxmox_router::{Permission, Router, RpcEnvironment, SubdirMap, list_subdirs_api_method};
 use proxmox_schema::api;
 use proxmox_sortable_macro::sortable;
 
 use pbs_api_types::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY};
 
+use crate::server;
+
 #[api(
     protected: true,
     input: {
@@ -25,7 +26,7 @@ use pbs_api_types::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY};
 )]
 /// List all notification targets.
 pub fn list_targets(_param: Value, _rpcenv: &mut dyn RpcEnvironment) -> Result<Vec<Target>, Error> {
-    let config = pbs_config::notifications::config()?;
+    let config = pbs_config::notifications::config(server::notifications::context())?;
     let targets = proxmox_notify::api::get_targets(&config)?;
 
     Ok(targets)
@@ -46,8 +47,10 @@ pub fn list_targets(_param: Value, _rpcenv: &mut dyn RpcEnvironment) -> Result<V
 )]
 /// Test a given notification target.
 pub fn test_target(name: String, _rpcenv: &mut dyn RpcEnvironment) -> Result<(), Error> {
-    let config = pbs_config::notifications::config()?;
-    proxmox_notify::api::common::test_target(&config, &name)?;
+    let context = server::notifications::context();
+
+    let config = pbs_config::notifications::config(context)?;
+    proxmox_notify::test_target(context, &config, &name)?;
     Ok(())
 }
 
diff --git a/src/api2/config/notifications/webhook.rs b/src/api2/config/notifications/webhook.rs
index 4a0400245..76c5a4eea 100644
--- a/src/api2/config/notifications/webhook.rs
+++ b/src/api2/config/notifications/webhook.rs
@@ -1,15 +1,17 @@
 use anyhow::Error;
 use serde_json::Value;
 
-use proxmox_notify::endpoints::webhook::{
-    DeleteableWebhookProperty, WebhookConfig, WebhookConfigUpdater,
+use proxmox_config_digest::ConfigDigest;
+use proxmox_notify::api_types::{
+    DeletableWebhookProperty, ENTITY_NAME_SCHEMA, WebhookConfig, WebhookConfigUpdater,
 };
-use proxmox_notify::schema::ENTITY_NAME_SCHEMA;
 use proxmox_router::{Permission, Router, RpcEnvironment};
 use proxmox_schema::api;
 
 use pbs_api_types::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY, PROXMOX_CONFIG_DIGEST_SCHEMA};
 
+use crate::server;
+
 #[api(
     protected: true,
     input: {
@@ -29,7 +31,7 @@ pub fn list_endpoints(
     _param: Value,
     _rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<Vec<WebhookConfig>, Error> {
-    let config = pbs_config::notifications::config()?;
+    let config = pbs_config::notifications::config(server::notifications::context())?;
 
     let endpoints = proxmox_notify::api::webhook::get_endpoints(&config)?;
 
@@ -52,10 +54,10 @@ pub fn list_endpoints(
 )]
 /// Get a webhook endpoint.
 pub fn get_endpoint(name: String, rpcenv: &mut dyn RpcEnvironment) -> Result<WebhookConfig, Error> {
-    let config = pbs_config::notifications::config()?;
+    let config = pbs_config::notifications::config(server::notifications::context())?;
     let endpoint = proxmox_notify::api::webhook::get_endpoint(&config, &name)?;
 
-    rpcenv["digest"] = hex::encode(config.digest()).into();
+    rpcenv["digest"] = config.digest().to_hex().into();
 
     Ok(endpoint)
 }
@@ -80,7 +82,7 @@ pub fn add_endpoint(
     _rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<(), Error> {
     let _lock = pbs_config::notifications::lock_config()?;
-    let mut config = pbs_config::notifications::config()?;
+    let mut config = pbs_config::notifications::config(server::notifications::context())?;
 
     proxmox_notify::api::webhook::add_endpoint(&mut config, endpoint)?;
 
@@ -104,7 +106,7 @@ pub fn add_endpoint(
                 type: Array,
                 optional: true,
                 items: {
-                    type: DeleteableWebhookProperty,
+                    type: DeletableWebhookProperty,
                 }
             },
             digest: {
@@ -121,20 +123,19 @@ pub fn add_endpoint(
 pub fn update_endpoint(
     name: String,
     updater: WebhookConfigUpdater,
-    delete: Option<Vec<DeleteableWebhookProperty>>,
-    digest: Option<String>,
+    delete: Option<Vec<DeletableWebhookProperty>>,
+    digest: Option<ConfigDigest>,
     _rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<(), Error> {
     let _lock = pbs_config::notifications::lock_config()?;
-    let mut config = pbs_config::notifications::config()?;
-    let digest = digest.map(hex::decode).transpose()?;
+    let mut config = pbs_config::notifications::config(server::notifications::context())?;
 
     proxmox_notify::api::webhook::update_endpoint(
         &mut config,
         &name,
         updater,
         delete.as_deref(),
-        digest.as_deref(),
+        digest,
     )?;
 
     pbs_config::notifications::save_config(config)?;
@@ -157,7 +158,7 @@ pub fn update_endpoint(
 /// Delete webhook endpoint.
 pub fn delete_endpoint(name: String, _rpcenv: &mut dyn RpcEnvironment) -> Result<(), Error> {
     let _lock = pbs_config::notifications::lock_config()?;
-    let mut config = pbs_config::notifications::config()?;
+    let mut config = pbs_config::notifications::config(server::notifications::context())?;
     proxmox_notify::api::webhook::delete_endpoint(&mut config, &name)?;
 
     pbs_config::notifications::save_config(config)?;
diff --git a/src/bin/docgen.rs b/src/bin/docgen.rs
index ad85b9e55..3bea65854 100644
--- a/src/bin/docgen.rs
+++ b/src/bin/docgen.rs
@@ -3,6 +3,7 @@ use anyhow::{Error, bail};
 use proxmox_schema::ApiType;
 use proxmox_schema::format::dump_enum_properties;
 use proxmox_section_config::dump_section_config;
+use proxmox_section_config::typed::ApiSectionDataEntry;
 
 use pbs_api_types::PRIVILEGES;
 
@@ -29,9 +30,11 @@ fn main() -> Result<(), Error> {
             "apidata.js" => generate_api_tree(),
             "datastore.cfg" => dump_section_config(&pbs_config::datastore::CONFIG),
             "domains.cfg" => dump_section_config(&pbs_config::domains::CONFIG),
-            "notifications.cfg" => dump_section_config(proxmox_notify::config::config_parser()),
+            "notifications.cfg" => {
+                dump_section_config(proxmox_notify::ConfigEntity::section_config())
+            }
             "notifications-priv.cfg" => {
-                dump_section_config(proxmox_notify::config::private_config_parser())
+                dump_section_config(proxmox_notify::PrivateConfigEntity::section_config())
             }
             "tape.cfg" => dump_section_config(&pbs_config::drive::CONFIG),
             "tape-job.cfg" => dump_section_config(&pbs_config::tape_job::CONFIG),
diff --git a/src/bin/proxmox-backup-api.rs b/src/bin/proxmox-backup-api.rs
index 710a70042..aad3fabc3 100644
--- a/src/bin/proxmox-backup-api.rs
+++ b/src/bin/proxmox-backup-api.rs
@@ -77,7 +77,6 @@ async fn run() -> Result<(), Error> {
     let _ = csrf_secret(); // load with lazy_static
 
     proxmox_backup::auth_helpers::setup_auth_context(true);
-    proxmox_backup::server::notifications::init()?;
     let mut command_sock = proxmox_daemon::command_socket::CommandSocket::new(backup_user.gid);
 
     proxmox_acme_api::init(configdir!("/acme"), true)?;
diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs
index 46bbc514c..ae58339fb 100644
--- a/src/bin/proxmox-backup-manager.rs
+++ b/src/bin/proxmox-backup-manager.rs
@@ -669,7 +669,6 @@ async fn run() -> Result<(), Error> {
         .stderr_on_no_workertask()
         .tasklog_pbs()
         .init()?;
-    proxmox_backup::server::notifications::init()?;
     proxmox_product_config::init(pbs_config::backup_user()?, pbs_config::priv_user()?);
     proxmox_acme_api::init(configdir!("/acme"), false)?;
 
diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
index 22abfdbdb..a550f285b 100644
--- a/src/bin/proxmox-backup-proxy.rs
+++ b/src/bin/proxmox-backup-proxy.rs
@@ -186,7 +186,6 @@ async fn run() -> Result<(), Error> {
         .init()?;
 
     proxmox_backup::auth_helpers::setup_auth_context(false);
-    proxmox_backup::server::notifications::init()?;
     metric_collection::init()?;
     proxmox_acme_api::init(configdir!("/acme"), false)?;
 
diff --git a/src/bin/proxmox-daily-update.rs b/src/bin/proxmox-daily-update.rs
index 597722497..4f5e39c8f 100644
--- a/src/bin/proxmox-daily-update.rs
+++ b/src/bin/proxmox-daily-update.rs
@@ -1,7 +1,6 @@
 use anyhow::Error;
 use serde_json::json;
 
-use proxmox_notify::context::pbs::PBS_CONTEXT;
 use proxmox_router::{ApiHandler, RpcEnvironment, cli::*};
 use proxmox_subscription::SubscriptionStatus;
 
@@ -102,8 +101,6 @@ async fn run(rpcenv: &mut dyn RpcEnvironment) -> Result<(), Error> {
     proxmox_rest_server::register_task_control_commands(&mut command_sock)?;
     command_sock.spawn(proxmox_rest_server::last_worker_future())?;
 
-    proxmox_notify::context::set_context(&PBS_CONTEXT);
-
     proxmox_acme_api::init(configdir!("/acme"), false)?;
 
     do_update(rpcenv).await
diff --git a/src/bin/proxmox_backup_manager/notifications/gotify.rs b/src/bin/proxmox_backup_manager/notifications/gotify.rs
index 0a6ebe053..43fe64dfd 100644
--- a/src/bin/proxmox_backup_manager/notifications/gotify.rs
+++ b/src/bin/proxmox_backup_manager/notifications/gotify.rs
@@ -1,7 +1,7 @@
 use anyhow::Error;
-use proxmox_notify::schema::ENTITY_NAME_SCHEMA;
 use serde_json::Value;
 
+use proxmox_notify::api_types::ENTITY_NAME_SCHEMA;
 use proxmox_router::{ApiHandler, RpcEnvironment, cli::*};
 use proxmox_schema::api;
 
diff --git a/src/bin/proxmox_backup_manager/notifications/matchers.rs b/src/bin/proxmox_backup_manager/notifications/matchers.rs
index 4d648bcbb..37823317d 100644
--- a/src/bin/proxmox_backup_manager/notifications/matchers.rs
+++ b/src/bin/proxmox_backup_manager/notifications/matchers.rs
@@ -1,7 +1,7 @@
 use anyhow::Error;
-use proxmox_notify::schema::ENTITY_NAME_SCHEMA;
 use serde_json::Value;
 
+use proxmox_notify::api_types::ENTITY_NAME_SCHEMA;
 use proxmox_router::{ApiHandler, RpcEnvironment, cli::*};
 use proxmox_schema::api;
 
diff --git a/src/bin/proxmox_backup_manager/notifications/sendmail.rs b/src/bin/proxmox_backup_manager/notifications/sendmail.rs
index a15b73a7e..07c9d16d6 100644
--- a/src/bin/proxmox_backup_manager/notifications/sendmail.rs
+++ b/src/bin/proxmox_backup_manager/notifications/sendmail.rs
@@ -1,7 +1,7 @@
 use anyhow::Error;
-use proxmox_notify::schema::ENTITY_NAME_SCHEMA;
 use serde_json::Value;
 
+use proxmox_notify::api_types::ENTITY_NAME_SCHEMA;
 use proxmox_router::{ApiHandler, RpcEnvironment, cli::*};
 use proxmox_schema::api;
 
diff --git a/src/bin/proxmox_backup_manager/notifications/smtp.rs b/src/bin/proxmox_backup_manager/notifications/smtp.rs
index 3c1d9f762..1bce6498b 100644
--- a/src/bin/proxmox_backup_manager/notifications/smtp.rs
+++ b/src/bin/proxmox_backup_manager/notifications/smtp.rs
@@ -1,7 +1,7 @@
 use anyhow::Error;
-use proxmox_notify::schema::ENTITY_NAME_SCHEMA;
 use serde_json::Value;
 
+use proxmox_notify::api_types::ENTITY_NAME_SCHEMA;
 use proxmox_router::{ApiHandler, RpcEnvironment, cli::*};
 use proxmox_schema::api;
 
diff --git a/src/bin/proxmox_backup_manager/notifications/webhook.rs b/src/bin/proxmox_backup_manager/notifications/webhook.rs
index 302940edf..8810f581c 100644
--- a/src/bin/proxmox_backup_manager/notifications/webhook.rs
+++ b/src/bin/proxmox_backup_manager/notifications/webhook.rs
@@ -1,7 +1,7 @@
 use anyhow::Error;
 use serde_json::Value;
 
-use proxmox_notify::schema::ENTITY_NAME_SCHEMA;
+use proxmox_notify::api_types::ENTITY_NAME_SCHEMA;
 use proxmox_router::{ApiHandler, RpcEnvironment, cli::*};
 use proxmox_schema::api;
 
diff --git a/src/server/notifications/mod.rs b/src/server/notifications/mod.rs
index 21bec254b..1e71cd39d 100644
--- a/src/server/notifications/mod.rs
+++ b/src/server/notifications/mod.rs
@@ -1,12 +1,13 @@
-use std::collections::HashMap;
 use std::path::Path;
+use std::sync::OnceLock;
 use std::time::{Duration, Instant};
 
 use anyhow::Error;
 use const_format::concatcp;
 use nix::unistd::Uid;
 
-use proxmox_notify::context::pbs::PBS_CONTEXT;
+use proxmox_notify::context::pbs::PBSContext;
+use proxmox_notify::{Context, EmailRecipient, Notification, Recipient, Severity};
 use proxmox_schema::ApiType;
 use proxmox_sys::fs::{CreateOptions, create_path};
 
@@ -15,8 +16,6 @@ use pbs_api_types::{
     APTUpdateInfo, DataStoreConfig, DatastoreNotify, GarbageCollectionStatus, NotificationMode,
     Notify, SyncJobConfig, TapeBackupJobSetup, User, Userid, VerificationJobConfig,
 };
-use proxmox_notify::endpoints::sendmail::{SendmailConfig, SendmailEndpoint};
-use proxmox_notify::{Endpoint, Notification, Severity};
 
 const SPOOL_DIR: &str = concatcp!(pbs_buildcfg::PROXMOX_BACKUP_STATE_DIR, "/notifications");
 
@@ -29,10 +28,11 @@ use template_data::{
     TapeLoadTemplateData, VerifyErrTemplateData, VerifyOkTemplateData,
 };
 
-/// Initialize the notification system by setting context in proxmox_notify
-pub fn init() -> Result<(), Error> {
-    proxmox_notify::context::set_context(&PBS_CONTEXT);
-    Ok(())
+static CONTEXT: OnceLock<Context> = OnceLock::new();
+
+/// Get a reference to the static notification context for PBS.
+pub fn context() -> &'static Context {
+    CONTEXT.get_or_init(|| Context::new(PBSContext))
 }
 
 /// Create the directory which will be used to temporarily store notifications
@@ -78,10 +78,12 @@ async fn send_queued_notifications() -> Result<(), Error> {
     // Make sure that we send the oldest notification first
     notifications.sort_unstable_by_key(|n| n.timestamp());
 
+    let context = context();
+
     let res = tokio::task::spawn_blocking(move || {
-        let config = pbs_config::notifications::config()?;
+        let config = pbs_config::notifications::config(context)?;
         for notification in notifications {
-            if let Err(err) = proxmox_notify::api::common::send(&config, &notification) {
+            if let Err(err) = proxmox_notify::send(context, &config, &notification) {
                 log::error!("failed to send notification: {err}");
             }
         }
@@ -111,9 +113,11 @@ pub async fn notification_worker() {
 }
 
 fn send_notification(notification: Notification) -> Result<(), Error> {
+    let context = context();
+
     if nix::unistd::ROOT == Uid::current() {
-        let config = pbs_config::notifications::config()?;
-        proxmox_notify::api::common::send(&config, &notification)?;
+        let config = pbs_config::notifications::config(context)?;
+        proxmox_notify::send(context, &config, &notification)?;
     } else {
         let ser = serde_json::to_vec(&notification)?;
         let path = Path::new(SPOOL_DIR).join(format!("{id}.json", id = notification.id()));
@@ -129,19 +133,6 @@ fn send_notification(notification: Notification) -> Result<(), Error> {
     Ok(())
 }
 
-fn send_sendmail_legacy_notification(notification: Notification, email: &str) -> Result<(), Error> {
-    let endpoint = SendmailEndpoint {
-        config: SendmailConfig {
-            mailto: vec![email.into()],
-            ..Default::default()
-        },
-    };
-
-    endpoint.send(&notification)?;
-
-    Ok(())
-}
-
 /// Summary of a successful Tape Job
 #[derive(Default)]
 pub struct TapeBackupJobSummary {
@@ -158,50 +149,33 @@ pub fn send_gc_status(
     status: &GarbageCollectionStatus,
     result: &Result<(), Error>,
 ) -> Result<(), Error> {
-    let metadata = HashMap::from([
-        ("datastore".into(), datastore.into()),
-        ("hostname".into(), proxmox_sys::nodename().into()),
-        ("type".into(), "gc".into()),
-    ]);
+    let Some(recipient) =
+        datastore_notification_recipient(datastore, |n| n.gc, Notify::Always, result.is_ok())
+    else {
+        return Ok(());
+    };
 
-    let notification = match result {
+    let builder = match result {
         Ok(()) => {
             let template_data = GcOkTemplateData::new(datastore.to_string(), status);
-            Notification::from_template(
-                Severity::Info,
-                "gc-ok",
-                serde_json::to_value(template_data)?,
-                metadata,
-            )
+            Notification::template_builder("gc-ok", serde_json::to_value(template_data)?)
+                .severity(Severity::Info)
         }
         Err(err) => {
             let template_data = GcErrTemplateData::new(datastore.to_string(), format!("{err:#}"));
-            Notification::from_template(
-                Severity::Error,
-                "gc-err",
-                serde_json::to_value(template_data)?,
-                metadata,
-            )
+            Notification::template_builder("gc-err", serde_json::to_value(template_data)?)
+                .severity(Severity::Error)
         }
     };
 
-    let (email, notify, mode) = lookup_datastore_notify_settings(datastore);
-    match mode {
-        NotificationMode::LegacySendmail => {
-            let notify = notify.gc.unwrap_or(Notify::Always);
+    let notification = builder
+        .field("type", "gc")
+        .field("datastore", datastore)
+        .field("hostname", proxmox_sys::nodename())
+        .recipient(recipient)
+        .build()?;
 
-            if notify == Notify::Never || (result.is_ok() && notify == Notify::Error) {
-                return Ok(());
-            }
-
-            if let Some(email) = email {
-                send_sendmail_legacy_notification(notification, &email)?;
-            }
-        }
-        NotificationMode::NotificationSystem => {
-            send_notification(notification)?;
-        }
-    }
+    send_notification(notification)?;
 
     Ok(())
 }
@@ -210,14 +184,16 @@ pub fn send_verify_status(
     job: VerificationJobConfig,
     result: &Result<Vec<String>, Error>,
 ) -> Result<(), Error> {
-    let metadata = HashMap::from([
-        ("job-id".into(), job.id.clone()),
-        ("datastore".into(), job.store.clone()),
-        ("hostname".into(), proxmox_sys::nodename().into()),
-        ("type".into(), "verify".into()),
-    ]);
+    // Failed snapshots are reported via `Ok`, but still count as an error for the notify setting.
+    let is_ok = matches!(result, Ok(errors) if errors.is_empty());
 
-    let notification = match result {
+    let Some(recipient) =
+        datastore_notification_recipient(&job.store, |n| n.verify, Notify::Always, is_ok)
+    else {
+        return Ok(());
+    };
+
+    let builder = match result {
         Err(_) => {
             // aborted job - do not send any notification
             return Ok(());
@@ -228,12 +204,8 @@ pub fn send_verify_status(
                 datastore: job.store.clone(),
                 job_id: job.id.clone(),
             };
-            Notification::from_template(
-                Severity::Info,
-                "verify-ok",
-                serde_json::to_value(template_data)?,
-                metadata,
-            )
+            Notification::template_builder("verify-ok", serde_json::to_value(template_data)?)
+                .severity(Severity::Info)
         }
         Ok(errors) => {
             let template_data = VerifyErrTemplateData {
@@ -242,34 +214,20 @@ pub fn send_verify_status(
                 job_id: job.id.clone(),
                 failed_snapshot_list: errors.clone(),
             };
-            Notification::from_template(
-                Severity::Error,
-                "verify-err",
-                serde_json::to_value(template_data)?,
-                metadata,
-            )
+            Notification::template_builder("verify-err", serde_json::to_value(template_data)?)
+                .severity(Severity::Error)
         }
     };
 
-    let (email, notify, mode) = lookup_datastore_notify_settings(&job.store);
-    match mode {
-        NotificationMode::LegacySendmail => {
-            let notify = notify.verify.unwrap_or(Notify::Always);
+    let notification = builder
+        .field("type", "verify")
+        .field("job-id", job.id)
+        .field("datastore", job.store)
+        .field("hostname", proxmox_sys::nodename())
+        .recipient(recipient)
+        .build()?;
 
-            if notify == Notify::Never
-                || (matches!(result, Ok(errors) if errors.is_empty()) && notify == Notify::Error)
-            {
-                return Ok(());
-            }
-
-            if let Some(email) = email {
-                send_sendmail_legacy_notification(notification, &email)?;
-            }
-        }
-        NotificationMode::NotificationSystem => {
-            send_notification(notification)?;
-        }
-    }
+    send_notification(notification)?;
 
     Ok(())
 }
@@ -279,14 +237,13 @@ pub fn send_prune_status(
     jobname: &str,
     result: &Result<(), Error>,
 ) -> Result<(), Error> {
-    let metadata = HashMap::from([
-        ("job-id".into(), jobname.to_string()),
-        ("datastore".into(), store.into()),
-        ("hostname".into(), proxmox_sys::nodename().into()),
-        ("type".into(), "prune".into()),
-    ]);
+    let Some(recipient) =
+        datastore_notification_recipient(store, |n| n.prune, Notify::Error, result.is_ok())
+    else {
+        return Ok(());
+    };
 
-    let notification = match result {
+    let builder = match result {
         Ok(()) => {
             let template_data = PruneOkTemplateData {
                 common: CommonData::new(),
@@ -294,12 +251,8 @@ pub fn send_prune_status(
                 job_id: jobname.to_string(),
             };
 
-            Notification::from_template(
-                Severity::Info,
-                "prune-ok",
-                serde_json::to_value(template_data)?,
-                metadata,
-            )
+            Notification::template_builder("prune-ok", serde_json::to_value(template_data)?)
+                .severity(Severity::Info)
         }
         Err(err) => {
             let template_data = PruneErrTemplateData {
@@ -309,45 +262,32 @@ pub fn send_prune_status(
                 error: format!("{err:#}"),
             };
 
-            Notification::from_template(
-                Severity::Error,
-                "prune-err",
-                serde_json::to_value(template_data)?,
-                metadata,
-            )
+            Notification::template_builder("prune-err", serde_json::to_value(template_data)?)
+                .severity(Severity::Error)
         }
     };
 
-    let (email, notify, mode) = lookup_datastore_notify_settings(store);
-    match mode {
-        NotificationMode::LegacySendmail => {
-            let notify = notify.prune.unwrap_or(Notify::Error);
+    let notification = builder
+        .field("type", "prune")
+        .field("job-id", jobname)
+        .field("datastore", store)
+        .field("hostname", proxmox_sys::nodename())
+        .recipient(recipient)
+        .build()?;
 
-            if notify == Notify::Never || (result.is_ok() && notify == Notify::Error) {
-                return Ok(());
-            }
-
-            if let Some(email) = email {
-                send_sendmail_legacy_notification(notification, &email)?;
-            }
-        }
-        NotificationMode::NotificationSystem => {
-            send_notification(notification)?;
-        }
-    }
+    send_notification(notification)?;
 
     Ok(())
 }
 
 pub fn send_sync_status(job: &SyncJobConfig, result: &Result<(), Error>) -> Result<(), Error> {
-    let metadata = HashMap::from([
-        ("job-id".into(), job.id.clone()),
-        ("datastore".into(), job.store.clone()),
-        ("hostname".into(), proxmox_sys::nodename().into()),
-        ("type".into(), "sync".into()),
-    ]);
+    let Some(recipient) =
+        datastore_notification_recipient(&job.store, |n| n.sync, Notify::Always, result.is_ok())
+    else {
+        return Ok(());
+    };
 
-    let notification = match result {
+    let builder = match result {
         Ok(()) => {
             let template_data = SyncOkTemplateData {
                 common: CommonData::new(),
@@ -356,12 +296,8 @@ pub fn send_sync_status(job: &SyncJobConfig, result: &Result<(), Error>) -> Resu
                 remote: job.remote.clone(),
                 remote_datastore: job.remote_store.clone(),
             };
-            Notification::from_template(
-                Severity::Info,
-                "sync-ok",
-                serde_json::to_value(template_data)?,
-                metadata,
-            )
+            Notification::template_builder("sync-ok", serde_json::to_value(template_data)?)
+                .severity(Severity::Info)
         }
         Err(err) => {
             let template_data = SyncErrTemplateData {
@@ -372,32 +308,20 @@ pub fn send_sync_status(job: &SyncJobConfig, result: &Result<(), Error>) -> Resu
                 remote_datastore: job.remote_store.clone(),
                 error: format!("{err:#}"),
             };
-            Notification::from_template(
-                Severity::Error,
-                "sync-err",
-                serde_json::to_value(template_data)?,
-                metadata,
-            )
+            Notification::template_builder("sync-err", serde_json::to_value(template_data)?)
+                .severity(Severity::Error)
         }
     };
 
-    let (email, notify, mode) = lookup_datastore_notify_settings(&job.store);
-    match mode {
-        NotificationMode::LegacySendmail => {
-            let notify = notify.sync.unwrap_or(Notify::Always);
+    let notification = builder
+        .field("type", "sync")
+        .field("job-id", &job.id)
+        .field("datastore", &job.store)
+        .field("hostname", proxmox_sys::nodename())
+        .recipient(recipient)
+        .build()?;
 
-            if notify == Notify::Never || (result.is_ok() && notify == Notify::Error) {
-                return Ok(());
-            }
-
-            if let Some(email) = email {
-                send_sendmail_legacy_notification(notification, &email)?;
-            }
-        }
-        NotificationMode::NotificationSystem => {
-            send_notification(notification)?;
-        }
-    }
+    send_notification(notification)?;
 
     Ok(())
 }
@@ -408,20 +332,13 @@ pub fn send_tape_backup_status(
     result: &Result<(), Error>,
     summary: TapeBackupJobSummary,
 ) -> Result<(), Error> {
-    let mut metadata = HashMap::from([
-        ("datastore".into(), job.store.clone()),
-        ("media-pool".into(), job.pool.clone()),
-        ("hostname".into(), proxmox_sys::nodename().into()),
-        ("type".into(), "tape-backup".into()),
-    ]);
-
-    if let Some(id) = id {
-        metadata.insert("job-id".into(), id.into());
-    }
+    let Some(recipient) = tape_notification_recipient(&TapeNotificationMode::from(job)) else {
+        return Ok(());
+    };
 
     let duration = summary.duration.as_secs();
 
-    let notification = match result {
+    let mut builder = match result {
         Ok(()) => {
             let template_data = TapeBackupOkTemplateData {
                 common: CommonData::new(),
@@ -434,12 +351,8 @@ pub fn send_tape_backup_status(
                 snapshot_list: summary.snapshot_list,
             };
 
-            Notification::from_template(
-                Severity::Info,
-                "tape-backup-ok",
-                serde_json::to_value(template_data)?,
-                metadata,
-            )
+            Notification::template_builder("tape-backup-ok", serde_json::to_value(template_data)?)
+                .severity(Severity::Info)
         }
         Err(err) => {
             let template_data = TapeBackupErrTemplateData {
@@ -454,30 +367,25 @@ pub fn send_tape_backup_status(
                 error: format!("{err:#}"),
             };
 
-            Notification::from_template(
-                Severity::Error,
-                "tape-backup-err",
-                serde_json::to_value(template_data)?,
-                metadata,
-            )
+            Notification::template_builder("tape-backup-err", serde_json::to_value(template_data)?)
+                .severity(Severity::Error)
         }
     };
 
-    let mode = TapeNotificationMode::from(job);
-
-    match &mode {
-        TapeNotificationMode::LegacySendmail { notify_user } => {
-            let email = lookup_user_email(notify_user);
-
-            if let Some(email) = email {
-                send_sendmail_legacy_notification(notification, &email)?;
-            }
-        }
-        TapeNotificationMode::NotificationSystem => {
-            send_notification(notification)?;
-        }
+    if let Some(id) = id {
+        builder = builder.field("job-id", id);
     }
 
+    let notification = builder
+        .field("type", "tape-backup")
+        .field("datastore", &job.store)
+        .field("media-pool", &job.pool)
+        .field("hostname", proxmox_sys::nodename())
+        .recipient(recipient)
+        .build()?;
+
+    send_notification(notification)?;
+
     Ok(())
 }
 
@@ -489,10 +397,9 @@ pub fn send_load_media_notification(
     label_text: &str,
     reason: Option<String>,
 ) -> Result<(), Error> {
-    let metadata = HashMap::from([
-        ("hostname".into(), proxmox_sys::nodename().into()),
-        ("type".into(), "tape-load".into()),
-    ]);
+    let Some(recipient) = tape_notification_recipient(mode) else {
+        return Ok(());
+    };
 
     let device_type = if changer { "changer" } else { "drive" };
 
@@ -505,45 +412,28 @@ pub fn send_load_media_notification(
         tape_label: label_text.into(),
     };
 
-    let notification = Notification::from_template(
-        Severity::Notice,
-        "tape-load",
-        serde_json::to_value(template_data)?,
-        metadata,
-    );
+    let notification =
+        Notification::template_builder("tape-load", serde_json::to_value(template_data)?)
+            .severity(Severity::Notice)
+            .field("type", "tape-load")
+            .field("hostname", proxmox_sys::nodename())
+            .recipient(recipient)
+            .build()?;
 
-    match mode {
-        TapeNotificationMode::LegacySendmail { notify_user } => {
-            let email = lookup_user_email(notify_user);
-
-            if let Some(email) = email {
-                send_sendmail_legacy_notification(notification, &email)?;
-            }
-        }
-        TapeNotificationMode::NotificationSystem => {
-            send_notification(notification)?;
-        }
-    }
+    send_notification(notification)?;
 
     Ok(())
 }
 
 pub fn send_updates_available(updates: &[&APTUpdateInfo]) -> Result<(), Error> {
-    let hostname = proxmox_sys::nodename().to_string();
-
-    let metadata = HashMap::from([
-        ("hostname".into(), hostname),
-        ("type".into(), "package-updates".into()),
-    ]);
-
     let template_data = PackageUpdatesTemplateData::new(updates);
 
-    let notification = Notification::from_template(
-        Severity::Info,
-        "package-updates",
-        serde_json::to_value(template_data)?,
-        metadata,
-    );
+    let notification =
+        Notification::template_builder("package-updates", serde_json::to_value(template_data)?)
+            .severity(Severity::Info)
+            .field("type", "package-updates")
+            .field("hostname", proxmox_sys::nodename())
+            .build()?;
 
     send_notification(notification)?;
     Ok(())
@@ -556,22 +446,17 @@ pub fn send_certificate_renewal_mail(result: &Result<(), Error>) -> Result<(), E
         _ => return Ok(()),
     };
 
-    let metadata = HashMap::from([
-        ("hostname".into(), proxmox_sys::nodename().into()),
-        ("type".into(), "acme".into()),
-    ]);
-
     let template_data = AcmeErrTemplateData {
         common: CommonData::new(),
         error,
     };
 
-    let notification = Notification::from_template(
-        Severity::Error,
-        "acme-err",
-        serde_json::to_value(template_data)?,
-        metadata,
-    );
+    let notification =
+        Notification::template_builder("acme-err", serde_json::to_value(template_data)?)
+            .severity(Severity::Error)
+            .field("type", "acme")
+            .field("hostname", proxmox_sys::nodename())
+            .build()?;
 
     send_notification(notification)?;
     Ok(())
@@ -584,12 +469,6 @@ pub fn send_datastore_threshold_exceeded(
     limit: u64,
     value: u64,
 ) -> Result<(), Error> {
-    let metadata = HashMap::from([
-        ("datastore".into(), datastore.into()),
-        ("hostname".into(), proxmox_sys::nodename().into()),
-        ("type".into(), "thresholds".into()),
-    ]);
-
     let is_traffic = threshold == "uploaded" || threshold == "downloaded";
     let template_data = DatastoreThresholdExceededTemplateData::new(
         datastore.to_string(),
@@ -599,12 +478,13 @@ pub fn send_datastore_threshold_exceeded(
         is_traffic,
     );
 
-    let notification = Notification::from_template(
-        Severity::Warning,
-        "thresholds-exceeded",
-        serde_json::to_value(template_data)?,
-        metadata,
-    );
+    let notification =
+        Notification::template_builder("thresholds-exceeded", serde_json::to_value(template_data)?)
+            .severity(Severity::Warning)
+            .field("type", "thresholds")
+            .field("datastore", datastore)
+            .field("hostname", proxmox_sys::nodename())
+            .build()?;
 
     send_notification(notification)?;
     Ok(())
@@ -621,6 +501,55 @@ pub fn lookup_user_email(userid: &Userid) -> Option<String> {
     None
 }
 
+/// Determine the recipient for a datastore-related notification.
+///
+/// Returns `None` if no notification should be sent, either because the legacy notify
+/// settings of the datastore suppress it or because the notify user has no email address.
+fn datastore_notification_recipient(
+    store: &str,
+    notify_setting: fn(&DatastoreNotify) -> Option<Notify>,
+    default: Notify,
+    is_ok: bool,
+) -> Option<Recipient> {
+    let (email, notify, mode) = lookup_datastore_notify_settings(store);
+
+    match mode {
+        NotificationMode::LegacySendmail => {
+            let notify = notify_setting(&notify).unwrap_or(default);
+
+            if notify == Notify::Never || (is_ok && notify == Notify::Error) {
+                return None;
+            }
+
+            email.map(|email| {
+                Recipient::Email(EmailRecipient {
+                    mailto: vec![email],
+                    ..Default::default()
+                })
+            })
+        }
+        NotificationMode::NotificationSystem => Some(Recipient::Matcher),
+    }
+}
+
+/// Determine the recipient for a tape-related notification.
+///
+/// Returns `None` if no notification should be sent because the notify user has no email
+/// address.
+fn tape_notification_recipient(mode: &TapeNotificationMode) -> Option<Recipient> {
+    match mode {
+        TapeNotificationMode::LegacySendmail { notify_user } => {
+            lookup_user_email(notify_user).map(|email| {
+                Recipient::Email(EmailRecipient {
+                    mailto: vec![email],
+                    ..Default::default()
+                })
+            })
+        }
+        TapeNotificationMode::NotificationSystem => Some(Recipient::Matcher),
+    }
+}
+
 /// Lookup Datastore notify settings
 pub fn lookup_datastore_notify_settings(
     store: &str,
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox-backup v2 47/63] api: notification: send test notification via proxmox_notify::send
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (45 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox-backup v2 46/63] notifications: adapt to proxmox-notify API changes Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox-backup v2 48/63] notifications: send all notifications via proxmox-notify's queue Lukas Wagner
                   ` (16 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

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 <l.wagner@proxmox.com>
---
 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<V
 /// Test a given notification target.
 pub fn test_target(name: String, _rpcenv: &mut dyn RpcEnvironment) -> 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, &notification)?;
+
+    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





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox-backup v2 48/63] notifications: send all notifications via proxmox-notify's queue
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (46 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox-backup v2 47/63] api: notification: send test notification via proxmox_notify::send Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox-perl-rs v2 49/63] pve: notify: adapt to changes in the public API of proxmox-notify Lukas Wagner
                   ` (15 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

Previously, notifications were only queued when sent from an
unprivileged process, which wrote them as JSON files to the spool
directory for the worker in proxmox-backup-api to pick up. Each file
was removed before sending, so a notification was lost if the daemon
stopped while it was being sent. Privileged processes sent
notifications synchronously.

Now every notification is submitted to the queue provided by
proxmox-notify, located in /var/lib/proxmox-backup/notifications/queue.
The queue directory is owned by the privileged user and writable by the
'backup' group, so that both privileged and unprivileged processes can
submit notifications. The worker in proxmox-backup-api is replaced by
proxmox-notify's QueueWorker, which polls the queue every five seconds.
If the worker is interrupted while sending a notification, it retries
sending it up to two times after restart before dropping it.

Notifications left in the old spool directory are moved into the new
queue by renaming them, so that they cannot be lost in between. This is
repeated once a minute rather than only at startup: After an upgrade,
the proxy process running the old binary could keep running until all
worker tasks have finished. At move only on startup would delay these
notifications by potentially a long time. Scanning the old queue
directory once a minute is cheap enough to keep around until the next
major update, where it can be dropped.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---

Notes:
    Changes since v1:
    
    Keep scanning the old notification queue once a minute, as to ensure
    notifications sent by workers running in the proxy process *while* the
    package is updated are not delayed until the next daemon restart.

 Cargo.toml                              |  13 +-
 src/bin/proxmox-backup-api.rs           |   2 +-
 src/server/notifications/mod.rs         | 172 +++++++++++++-----------
 tests/data/serialized_notification.json |   1 +
 tests/notifications.rs                  |  11 ++
 5 files changed, 118 insertions(+), 81 deletions(-)
 create mode 100644 tests/data/serialized_notification.json
 create mode 100644 tests/notifications.rs

diff --git a/Cargo.toml b/Cargo.toml
index b83924a85..173437781 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -230,7 +230,18 @@ proxmox-ldap.workspace = true
 proxmox-metrics.workspace = true
 proxmox-network-api = { workspace = true, features = [ "impl" ] }
 proxmox-network-types.workspace = true
-proxmox-notify = { workspace = true, features = [ "pbs-context", "legacy-matchers", "api-impl", "send-impl", "api-types" ]}
+proxmox-notify = {
+    workspace = true,
+    features = [
+        "pbs-context",
+        "legacy-matchers",
+        "api-impl",
+        "send-impl",
+        "api-types",
+        "queue-submitter",
+        "queue-worker",
+    ]
+}
 proxmox-openid.workspace = true
 proxmox-product-config.workspace = true
 proxmox-parallel-handler.workspace = true
diff --git a/src/bin/proxmox-backup-api.rs b/src/bin/proxmox-backup-api.rs
index aad3fabc3..7e38b0225 100644
--- a/src/bin/proxmox-backup-api.rs
+++ b/src/bin/proxmox-backup-api.rs
@@ -60,7 +60,7 @@ async fn run() -> Result<(), Error> {
     proxmox_backup::server::create_state_dir()?;
     proxmox_backup::server::create_active_operations_dir()?;
     proxmox_backup::server::jobstate::create_jobstate_dir()?;
-    proxmox_backup::server::notifications::create_spool_dir()?;
+    proxmox_backup::server::notifications::create_notification_dirs()?;
     proxmox_backup::tape::create_tape_status_dir()?;
     proxmox_backup::tape::create_drive_state_dir()?;
     proxmox_backup::tape::create_changer_state_dir()?;
diff --git a/src/server/notifications/mod.rs b/src/server/notifications/mod.rs
index 1e71cd39d..2bbe45bce 100644
--- a/src/server/notifications/mod.rs
+++ b/src/server/notifications/mod.rs
@@ -1,15 +1,17 @@
 use std::path::Path;
 use std::sync::OnceLock;
-use std::time::{Duration, Instant};
+use std::time::Duration;
 
 use anyhow::Error;
 use const_format::concatcp;
-use nix::unistd::Uid;
+use nix::sys::stat::Mode;
 
 use proxmox_notify::context::pbs::PBSContext;
+use proxmox_notify::queue::{QueueConsumer, QueueSubmitter, QueueWorker};
 use proxmox_notify::{Context, EmailRecipient, Notification, Recipient, Severity};
 use proxmox_schema::ApiType;
 use proxmox_sys::fs::{CreateOptions, create_path};
+use proxmox_uuid::Uuid;
 
 use crate::tape::TapeNotificationMode;
 use pbs_api_types::{
@@ -17,7 +19,9 @@ use pbs_api_types::{
     Notify, SyncJobConfig, TapeBackupJobSetup, User, Userid, VerificationJobConfig,
 };
 
-const SPOOL_DIR: &str = concatcp!(pbs_buildcfg::PROXMOX_BACKUP_STATE_DIR, "/notifications");
+const NOTIFICATION_BASE_DIR: &str =
+    concatcp!(pbs_buildcfg::PROXMOX_BACKUP_STATE_DIR, "/notifications");
+const QUEUE_DIR: &str = concatcp!(NOTIFICATION_BASE_DIR, "/queue");
 
 mod template_data;
 
@@ -35,104 +39,114 @@ pub fn context() -> &'static Context {
     CONTEXT.get_or_init(|| Context::new(PBSContext))
 }
 
-/// Create the directory which will be used to temporarily store notifications
-/// which were sent from an unprivileged process.
-pub fn create_spool_dir() -> Result<(), Error> {
+/// Creates directories used for queuing notifications.
+pub fn create_notification_dirs() -> Result<(), Error> {
     let backup_user = proxmox_product_config::get_api_user();
     let opts = CreateOptions::new()
         .owner(backup_user.uid)
         .group(backup_user.gid);
 
-    create_path(SPOOL_DIR, None, Some(opts))?;
+    create_path(NOTIFICATION_BASE_DIR, None, Some(opts))?;
+
+    // The queue is writable by anybody in the 'backup' group.
+    let opts = CreateOptions::new()
+        .owner(proxmox_product_config::get_priv_user().uid)
+        .group(backup_user.gid)
+        .perm(Mode::from_bits_truncate(0o0770));
+
+    proxmox_sys::fs::ensure_dir_exists(QUEUE_DIR, &opts, true)?;
+
     Ok(())
 }
 
-async fn send_queued_notifications() -> Result<(), Error> {
-    let mut read_dir = tokio::fs::read_dir(SPOOL_DIR).await?;
-
-    let mut notifications = Vec::new();
-
-    while let Some(entry) = read_dir.next_entry().await? {
-        let path = entry.path();
-
-        if let Some(ext) = path.extension() {
-            if ext == "json" {
-                let p = path.clone();
-
-                let bytes = tokio::fs::read(p).await?;
-                let notification: Notification = serde_json::from_slice(&bytes)?;
-                notifications.push(notification);
-
-                // Currently, there is no retry-mechanism in case of failure...
-                // For retries, we'd have to keep track of which targets succeeded/failed
-                // to send, so we do not retry notifying a target which succeeded before.
-                tokio::fs::remove_file(path).await?;
-            }
-        }
-    }
-
-    if notifications.is_empty() {
-        return Ok(());
-    }
-
-    // Make sure that we send the oldest notification first
-    notifications.sort_unstable_by_key(|n| n.timestamp());
-
-    let context = context();
-
-    let res = tokio::task::spawn_blocking(move || {
-        let config = pbs_config::notifications::config(context)?;
-        for notification in notifications {
-            if let Err(err) = proxmox_notify::send(context, &config, &notification) {
-                log::error!("failed to send notification: {err}");
-            }
-        }
-
-        Ok::<(), Error>(())
-    })
-    .await?;
-
-    if let Err(e) = res {
-        log::error!("could not read notification config: {e}");
-    }
-
-    Ok::<(), Error>(())
-}
-
 /// Worker task to periodically send any queued notifications.
 pub async fn notification_worker() {
-    loop {
-        let delay_target = Instant::now() + Duration::from_secs(5);
+    let consumer = QueueConsumer::new(QUEUE_DIR);
 
-        if let Err(err) = send_queued_notifications().await {
-            log::error!("notification worker task error: {err}");
-        }
+    let worker = QueueWorker::builder(context().clone(), consumer)
+        .interval(Duration::from_secs(5))
+        .retry_attempts(2)
+        .build();
 
-        tokio::time::sleep_until(tokio::time::Instant::from_std(delay_target)).await;
+    tokio::select! {
+        _ = worker.run() => {}
+        _ = migrate_leftover_notifications_loop() => {}
     }
 }
 
-fn send_notification(notification: Notification) -> Result<(), Error> {
-    let context = context();
+/// Periodically move notifications from the old spool directory to the new queue.
+///
+/// After an upgrade, proxy processes running the old binary keep spooling notifications there
+/// until all of their worker tasks have finished, so checking only at startup is not enough.
+///
+/// FIXME: MAJOR VERSION: Remove
+async fn migrate_leftover_notifications_loop() {
+    loop {
+        match tokio::task::spawn_blocking(migrate_leftover_notifications).await {
+            Ok(Ok(())) => {}
+            Ok(Err(err)) => log::error!("failed to migrate notifications: {err:#}"),
+            Err(err) => log::error!("notification migration task failed: {err}"),
+        }
 
-    if nix::unistd::ROOT == Uid::current() {
-        let config = pbs_config::notifications::config(context)?;
-        proxmox_notify::send(context, &config, &notification)?;
-    } else {
-        let ser = serde_json::to_vec(&notification)?;
-        let path = Path::new(SPOOL_DIR).join(format!("{id}.json", id = notification.id()));
+        tokio::time::sleep(Duration::from_secs(60)).await;
+    }
+}
 
-        let backup_user = proxmox_product_config::get_api_user();
-        let opts = CreateOptions::new()
-            .owner(backup_user.uid)
-            .group(backup_user.gid);
-        proxmox_sys::fs::replace_file(path, &ser, opts, true)?;
-        log::info!("queued notification (id={id})", id = notification.id())
+/// Move any left-over notifications from the old spool directory at
+/// /var/lib/proxmox-backup/notifications to the new queue
+/// at /var/lib/proxmox-backup/notifications/queue
+fn migrate_leftover_notifications() -> Result<(), Error> {
+    let read_dir = std::fs::read_dir(NOTIFICATION_BASE_DIR)?;
+
+    for entry in read_dir.flatten() {
+        if let Some((name, ext)) = entry.file_name().to_string_lossy().split_once(".") {
+            if ext == "json" && Uuid::parse_str(name).is_ok() {
+                let path = entry.path();
+
+                if let Err(err) = migrate_single_notification(&path) {
+                    log::error!(
+                        "failed to migrate notification at '{p}' to new queue: {err:#}",
+                        p = path.display()
+                    );
+                }
+            }
+        }
     }
 
     Ok(())
 }
 
+fn migrate_single_notification(path: &Path) -> Result<(), Error> {
+    let bytes = std::fs::read(path)?;
+
+    // Technically, we don't need to parse, but this is just to ensure that
+    // we don't migrate over something that is not understood by the
+    // notification worker.
+    let notification: Notification = serde_json::from_slice(&bytes)?;
+
+    let uuid = notification.id().clone();
+
+    // Manually move the notification into the new queue directory.
+    //
+    // Use a manual rename instead of resubmitting to ensure atomicity.
+    std::fs::rename(
+        path,
+        Path::new(QUEUE_DIR).join(format!("notification-{uuid}")),
+    )?;
+
+    log::info!("moved notification {uuid} to new notification queue");
+
+    Ok(())
+}
+
+fn send_notification(notification: Notification) -> Result<(), Error> {
+    let options = proxmox_product_config::default_create_options();
+    let writer = QueueSubmitter::new(QUEUE_DIR, options);
+
+    writer.submit(&notification)?;
+    Ok(())
+}
+
 /// Summary of a successful Tape Job
 #[derive(Default)]
 pub struct TapeBackupJobSummary {
diff --git a/tests/data/serialized_notification.json b/tests/data/serialized_notification.json
new file mode 100644
index 000000000..aedefd455
--- /dev/null
+++ b/tests/data/serialized_notification.json
@@ -0,0 +1 @@
+{"content":{"template":{"template-name":"gc-ok","data":{"base-url":"https://pbs.proxmox.com:8007","datastore":"store","deduplication-factor":"0.00","disk-bytes":159,"disk-chunks":1,"fqdn":"pbs.proxmox.com","hostname":"pbs","index-data-bytes":0,"index-file-count":0,"pending-bytes":0,"pending-chunks":0,"removed-bad":0,"removed-bytes":0,"removed-chunks":0,"still-bad":0,"upid":"UPID:pbs:00000C78:00189303:00000000:6ADB5D2E:garbage_collection:store:root@pam:"}}},"metadata":{"severity":"info","timestamp":1792761135,"additional-fields":{"type":"gc","hostname":"pbs","datastore":"store"}},"id":"46516f7e-7eb7-43e7-b776-6048f144a6fe"}
diff --git a/tests/notifications.rs b/tests/notifications.rs
new file mode 100644
index 000000000..a02d13405
--- /dev/null
+++ b/tests/notifications.rs
@@ -0,0 +1,11 @@
+use proxmox_notify::Notification;
+
+/// Ensures that a notification serialized before switching to the shared notification worker
+/// continues to parse as the `Notification` type from proxmox-notify.
+#[test]
+fn test_parse_serialized_notification() {
+    let data = std::fs::read("tests/data/serialized_notification.json").unwrap();
+    let notification: Notification = serde_json::from_slice(&data).unwrap();
+
+    assert_eq!(notification.timestamp(), 1792761135);
+}
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox-perl-rs v2 49/63] pve: notify: adapt to changes in the public API of proxmox-notify
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (47 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox-backup v2 48/63] notifications: send all notifications via proxmox-notify's queue Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox-perl-rs v2 50/63] pve: notify: add `PVE::RS::Notify::enqueue` method Lukas Wagner
                   ` (14 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

proxmox-notify no longer keeps a global context that has to be set when
the module is loaded. Instead, the bindings now own a lazily initialized
static PVE context and pass it explicitly when sending notifications.
The context also supplies the default config, which is now handed to the
config parser.

The config update methods now take a ConfigDigest directly, so the
digest parameter is parsed on deserialization and the local
decode_digest helper is no longer needed.

proxmox-notify no longer provides a test_target helper. Testing a target
is now done by sending a regular test notification addressed to that
target and checking the returned receipt, raising an error if delivery
failed. The target is enabled in the in-memory copy of the config
beforehand, so that disabled targets can still be tested.

Apart from that, adapt to the types now being exported from
proxmox_notify::api_types (with the Deleteable* -> Deletable* rename),
the new notification template builder, and enable the api-impl and
send-impl features, which are now required for the config API and for
sending.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 pve-rs/Cargo.toml             |   2 +-
 pve-rs/src/bindings/mod.rs    |   3 -
 pve-rs/src/bindings/notify.rs | 175 +++++++++++++++++++---------------
 pve-rs/src/lib.rs             |  29 ++++--
 4 files changed, 116 insertions(+), 93 deletions(-)

diff --git a/pve-rs/Cargo.toml b/pve-rs/Cargo.toml
index d676395..9dbf4c9 100644
--- a/pve-rs/Cargo.toml
+++ b/pve-rs/Cargo.toml
@@ -43,7 +43,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 = ["pve-context", "legacy-matchers"] }
+proxmox-notify = { version = "2", features = [ "api-impl", "legacy-matchers", "pve-context", "send-impl" ] }
 proxmox-oci = "0.2.2"
 proxmox-openid = "1.0.2"
 proxmox-resource-scheduling = "2"
diff --git a/pve-rs/src/bindings/mod.rs b/pve-rs/src/bindings/mod.rs
index 143a62b..d91a122 100644
--- a/pve-rs/src/bindings/mod.rs
+++ b/pve-rs/src/bindings/mod.rs
@@ -31,13 +31,10 @@ pub mod proxmox_lib_pve {
     //!
     //! This contains the `init` function executed by the module on startup.
 
-    use proxmox_notify::context::pve::PVE_CONTEXT;
-
     use crate::common;
 
     #[export]
     fn init() {
         common::logger::init("PVE_LOG", "info");
-        proxmox_notify::context::set_context(&PVE_CONTEXT);
     }
 }
diff --git a/pve-rs/src/bindings/notify.rs b/pve-rs/src/bindings/notify.rs
index 546a742..a5faa93 100644
--- a/pve-rs/src/bindings/notify.rs
+++ b/pve-rs/src/bindings/notify.rs
@@ -13,31 +13,24 @@ pub mod pve_rs_notify {
     use std::sync::Mutex;
 
     use anyhow::{Error, bail};
-    use serde_json::Value as JSONValue;
+    use serde_json::{Value as JSONValue, json};
 
     use perlmod::Value;
+    use proxmox_config_digest::ConfigDigest;
     use proxmox_http_error::HttpError;
-    use proxmox_notify::api::Target;
-    use proxmox_notify::endpoints::gotify::{
-        DeleteableGotifyProperty, GotifyConfig, GotifyConfigUpdater, GotifyPrivateConfig,
-        GotifyPrivateConfigUpdater,
+    use proxmox_notify::api_types::{
+        DeletableGotifyProperty, DeletableMatcherProperty, DeletableSendmailProperty,
+        DeletableSmtpProperty, DeletableWebhookProperty, GotifyConfig, GotifyConfigUpdater,
+        GotifyPrivateConfig, GotifyPrivateConfigUpdater, MatcherConfig, MatcherConfigUpdater,
+        SendmailConfig, SendmailConfigUpdater, SmtpConfig, SmtpConfigUpdater, SmtpPrivateConfig,
+        SmtpPrivateConfigUpdater, Target, TargetReceiptStatus, WebhookConfig, WebhookConfigUpdater,
     };
-    use proxmox_notify::endpoints::sendmail::{
-        DeleteableSendmailProperty, SendmailConfig, SendmailConfigUpdater,
-    };
-    use proxmox_notify::endpoints::smtp::{
-        DeleteableSmtpProperty, SmtpConfig, SmtpConfigUpdater, SmtpPrivateConfig,
-        SmtpPrivateConfigUpdater,
-    };
-    use proxmox_notify::endpoints::webhook::{
-        DeleteableWebhookProperty, WebhookConfig, WebhookConfigUpdater,
-    };
-    use proxmox_notify::matcher::{DeleteableMatcherProperty, MatcherConfig, MatcherConfigUpdater};
-    use proxmox_notify::{Config, Notification, Severity, api};
+    use proxmox_notify::{Config, Notification, Recipient, Severity, api};
+    use proxmox_notify::{http_bail, http_err};
 
-    /// A notification catalog instance.
+    /// A notification configuration instance.
     ///
-    /// See [`Config`].
+    /// See [`proxmox_notify::Config`].
     pub struct NotificationConfig {
         config: Mutex<Config>,
     }
@@ -89,9 +82,11 @@ pub mod pve_rs_notify {
         let raw_config = std::str::from_utf8(raw_config)?;
         let raw_private_config = std::str::from_utf8(raw_private_config)?;
 
+        let default_config = crate::notify_context().default_config();
+
         Ok(perlmod::instantiate_magic!(&class, MAGIC => Box::new(
             NotificationConfig {
-                config: Mutex::new(Config::new(raw_config, raw_private_config)?)
+                config: Mutex::new(Config::parse_section_config(raw_config, raw_private_config, Some(default_config))?)
             }
         )))
     }
@@ -101,7 +96,7 @@ pub mod pve_rs_notify {
     pub fn write_config(
         #[try_from_ref] this: &NotificationConfig,
     ) -> Result<(String, String), Error> {
-        Ok(this.config.lock().unwrap().write()?)
+        Ok(this.config.lock().unwrap().to_section_config()?)
     }
 
     /// Method: Returns the SHA256 digest of the configuration.
@@ -110,15 +105,16 @@ pub mod pve_rs_notify {
     #[export]
     pub fn digest(#[try_from_ref] this: &NotificationConfig) -> String {
         let config = this.config.lock().unwrap();
-        hex::encode(config.digest())
+        config.digest().to_string()
     }
 
     /// Method: Send a notification from a template.
     ///
-    /// This instantiates a [`Notification`] via [`from_template`](Notification::from_template())
+    /// This instantiates a [`Notification`] via
+    /// [`template_builder`](Notification::template_builder())
     /// and sends it according to the configuration.
     ///
-    /// See [`api::common::send`].
+    /// See [`proxmox_notify::send`].
     #[export(serialize_error)]
     pub fn send(
         #[try_from_ref] this: &NotificationConfig,
@@ -128,14 +124,21 @@ pub mod pve_rs_notify {
         fields: Option<HashMap<String, String>>,
     ) -> Result<(), HttpError> {
         let config = this.config.lock().unwrap();
-        let notification = Notification::from_template(
-            severity,
-            template_name,
-            template_data.unwrap_or_default(),
-            fields.unwrap_or_default(),
-        );
 
-        api::common::send(&config, &notification)
+        let notification =
+            Notification::template_builder(template_name, template_data.unwrap_or_default())
+                .severity(severity)
+                .fields(fields.unwrap_or_default())
+                .build()
+                .map_err(|err| {
+                    http_err!(INTERNAL_SERVER_ERROR, "failed to build notification: {err}")
+                })?;
+
+        proxmox_notify::send(crate::notify_context(), &config, &notification).map_err(|err| {
+            http_err!(INTERNAL_SERVER_ERROR, "failed to send notification: {err}")
+        })?;
+
+        Ok(())
     }
 
     /// Method: Get a list of all notification targets.
@@ -149,14 +152,58 @@ pub mod pve_rs_notify {
         api::get_targets(&config)
     }
 
-    /// Method: Test a target, see [`api::common::test_target`].
+    /// Method: Test a target.
     #[export(serialize_error)]
     pub fn test_target(
         #[try_from_ref] this: &NotificationConfig,
         target: &str,
     ) -> Result<(), HttpError> {
-        let config = this.config.lock().unwrap();
-        api::common::test_target(&config, target)
+        // create a copy to make sure that we don't persist the modified configuration
+        let mut config = {
+            let config = this.config.lock().unwrap();
+            config.clone()
+        };
+
+        let context = crate::notify_context();
+
+        // Testing targets should also work if they are set to 'disabled'
+        // We don't persist the modified config, so this is ephemeral.
+        proxmox_notify::api::set_entity_disabled(&mut config, target, false)?;
+
+        let notification = Notification::template_builder("test", json!({ "target": &target }))
+            .severity(Severity::Info)
+            .recipient(Recipient::Target(target.to_string()))
+            .build()
+            .map_err(|err| http_err!(INTERNAL_SERVER_ERROR, "{err}"))?;
+
+        let receipt = proxmox_notify::send(context, &config, &notification)
+            .map_err(|err| http_err!(INTERNAL_SERVER_ERROR, "{err}"))?;
+
+        match receipt
+            .target_receipts()
+            .first()
+            .ok_or_else(|| {
+                http_err!(
+                    INTERNAL_SERVER_ERROR,
+                    "target receipt array did not contain expected entry"
+                )
+            })?
+            .status()
+        {
+            TargetReceiptStatus::Delivered => Ok(()),
+            TargetReceiptStatus::Error { error_message } => {
+                http_bail!(
+                    INTERNAL_SERVER_ERROR,
+                    "could not test target: {error_message}"
+                )
+            }
+            TargetReceiptStatus::Disabled => {
+                http_bail!(
+                    INTERNAL_SERVER_ERROR,
+                    "target {target} disabled while sending test notification -- this should not happen"
+                )
+            }
+        }
     }
 
     /// Method: Get sendmail endpoints.
@@ -203,19 +250,12 @@ pub mod pve_rs_notify {
         #[try_from_ref] this: &NotificationConfig,
         name: &str,
         updater: SendmailConfigUpdater,
-        delete: Option<Vec<DeleteableSendmailProperty>>,
-        digest: Option<&str>,
+        delete: Option<Vec<DeletableSendmailProperty>>,
+        digest: Option<ConfigDigest>,
     ) -> Result<(), HttpError> {
         let mut config = this.config.lock().unwrap();
-        let digest = decode_digest(digest)?;
 
-        api::sendmail::update_endpoint(
-            &mut config,
-            name,
-            updater,
-            delete.as_deref(),
-            digest.as_deref(),
-        )
+        api::sendmail::update_endpoint(&mut config, name, updater, delete.as_deref(), digest)
     }
 
     /// Method: Delete a sendmail endpoint.
@@ -275,11 +315,10 @@ pub mod pve_rs_notify {
         name: &str,
         updater: GotifyConfigUpdater,
         private_updater: GotifyPrivateConfigUpdater,
-        delete: Option<Vec<DeleteableGotifyProperty>>,
-        digest: Option<&str>,
+        delete: Option<Vec<DeletableGotifyProperty>>,
+        digest: Option<ConfigDigest>,
     ) -> Result<(), HttpError> {
         let mut config = this.config.lock().unwrap();
-        let digest = decode_digest(digest)?;
 
         api::gotify::update_endpoint(
             &mut config,
@@ -287,7 +326,7 @@ pub mod pve_rs_notify {
             updater,
             private_updater,
             delete.as_deref(),
-            digest.as_deref(),
+            digest,
         )
     }
 
@@ -348,11 +387,10 @@ pub mod pve_rs_notify {
         name: &str,
         updater: SmtpConfigUpdater,
         private_updater: SmtpPrivateConfigUpdater,
-        delete: Option<Vec<DeleteableSmtpProperty>>,
-        digest: Option<&str>,
+        delete: Option<Vec<DeletableSmtpProperty>>,
+        digest: Option<ConfigDigest>,
     ) -> Result<(), HttpError> {
         let mut config = this.config.lock().unwrap();
-        let digest = decode_digest(digest)?;
 
         api::smtp::update_endpoint(
             &mut config,
@@ -360,7 +398,7 @@ pub mod pve_rs_notify {
             updater,
             private_updater,
             delete.as_deref(),
-            digest.as_deref(),
+            digest,
         )
     }
 
@@ -419,19 +457,12 @@ pub mod pve_rs_notify {
         #[try_from_ref] this: &NotificationConfig,
         name: &str,
         config_updater: WebhookConfigUpdater,
-        delete: Option<Vec<DeleteableWebhookProperty>>,
-        digest: Option<&str>,
+        delete: Option<Vec<DeletableWebhookProperty>>,
+        digest: Option<ConfigDigest>,
     ) -> Result<(), HttpError> {
         let mut config = this.config.lock().unwrap();
-        let digest = decode_digest(digest)?;
 
-        api::webhook::update_endpoint(
-            &mut config,
-            name,
-            config_updater,
-            delete.as_deref(),
-            digest.as_deref(),
-        )
+        api::webhook::update_endpoint(&mut config, name, config_updater, delete.as_deref(), digest)
     }
 
     /// Method: Delete a webhook endpoint.
@@ -495,19 +526,12 @@ pub mod pve_rs_notify {
         #[try_from_ref] this: &NotificationConfig,
         name: &str,
         updater: MatcherConfigUpdater,
-        delete: Option<Vec<DeleteableMatcherProperty>>,
-        digest: Option<&str>,
+        delete: Option<Vec<DeletableMatcherProperty>>,
+        digest: Option<ConfigDigest>,
     ) -> Result<(), HttpError> {
         let mut config = this.config.lock().unwrap();
-        let digest = decode_digest(digest)?;
 
-        api::matcher::update_matcher(
-            &mut config,
-            name,
-            updater,
-            delete.as_deref(),
-            digest.as_deref(),
-        )
+        api::matcher::update_matcher(&mut config, name, updater, delete.as_deref(), digest)
     }
 
     /// Method: Delete a matcher.
@@ -533,11 +557,4 @@ pub mod pve_rs_notify {
         let config = this.config.lock().unwrap();
         api::common::get_referenced_entities(&config, name)
     }
-
-    fn decode_digest(digest: Option<&str>) -> Result<Option<Vec<u8>>, HttpError> {
-        digest
-            .map(hex::decode)
-            .transpose()
-            .map_err(|e| api::http_err!(BAD_REQUEST, "invalid digest: {e}"))
-    }
 }
diff --git a/pve-rs/src/lib.rs b/pve-rs/src/lib.rs
index b32b061..a888877 100644
--- a/pve-rs/src/lib.rs
+++ b/pve-rs/src/lib.rs
@@ -2,7 +2,7 @@
 
 #![deny(missing_docs)]
 
-use std::collections::HashMap;
+use std::sync::OnceLock;
 
 use anyhow::Error;
 use serde_json::json;
@@ -24,9 +24,12 @@ fn send_notification(notification: &Notification) -> Result<(), Error> {
         proxmox_sys::fs::file_read_optional_string("/etc/pve/priv/notifications.cfg")?
             .unwrap_or_default();
 
-    let config = Config::new(&config, &private_config)?;
+    let context = crate::notify_context();
 
-    proxmox_notify::api::common::send(&config, notification)?;
+    let config =
+        Config::parse_section_config(&config, &private_config, Some(context.default_config()))?;
+
+    proxmox_notify::send(context, &config, notification)?;
 
     Ok(())
 }
@@ -36,11 +39,6 @@ fn send_notification(notification: &Notification) -> Result<(), Error> {
 pub fn send_updates_available(updates: &[&APTUpdateInfo]) -> Result<(), Error> {
     let hostname = proxmox_sys::nodename().to_string();
 
-    let metadata = HashMap::from([
-        ("hostname".into(), hostname.clone()),
-        ("type".into(), "package-updates".into()),
-    ]);
-
     // The template uses the `table` handlebars helper, so
     // we need to form the approriate data structure first.
     let update_table = json!({
@@ -68,9 +66,20 @@ pub fn send_updates_available(updates: &[&APTUpdateInfo]) -> Result<(), Error> {
         "updates": update_table,
     });
 
-    let notification =
-        Notification::from_template(Severity::Info, "package-updates", template_data, metadata);
+    let notification = Notification::template_builder("package-updates", template_data)
+        .severity(Severity::Info)
+        .field("hostname", hostname)
+        .field("type", "package-updates")
+        .build()?;
 
     send_notification(&notification)?;
     Ok(())
 }
+
+static NOTIFY_CONTEXT: OnceLock<proxmox_notify::Context> = OnceLock::new();
+
+/// Get a reference to the static notification context for PVE.
+pub fn notify_context() -> &'static proxmox_notify::Context {
+    NOTIFY_CONTEXT
+        .get_or_init(|| proxmox_notify::Context::new(proxmox_notify::context::pve::PVEContext))
+}
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox-perl-rs v2 50/63] pve: notify: add `PVE::RS::Notify::enqueue` method
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (48 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox-perl-rs v2 49/63] pve: notify: adapt to changes in the public API of proxmox-notify Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH pve-cluster v2 51/63] notify: send notifications via notification queue Lukas Wagner
                   ` (13 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

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 <l.wagner@proxmox.com>
---
 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 9dbf4c9..3937365 100644
--- a/pve-rs/Cargo.toml
+++ b/pve-rs/Cargo.toml
@@ -43,7 +43,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<JSONValue>,
+        fields: Option<HashMap<String, String>>,
+        recipient: Option<EmailRecipient>,
+    ) -> 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(&notification)?;
+
+        Ok(())
+    }
+
+    fn queue_file_options() -> Result<CreateOptions, anyhow::Error> {
+        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





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH pve-cluster v2 51/63] notify: send notifications via notification queue
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (49 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox-perl-rs v2 50/63] pve: notify: add `PVE::RS::Notify::enqueue` method Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH manager v2 52/63] vzdump: send legacy-sendmail notifications via simplified API Lukas Wagner
                   ` (12 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

Instead of reading the configuration and sending the notification
directly, based on the targets and matchers defined in the config,
use the new PVE::RS::Notify::enqueue function to write the notification
to the notification queue.

For cases where the notification configuration was explicitly provided
by the caller (used only by 'legacy-sendmail' mode when sending backup
job notifications), we add a simply check to switch over to the new
semantics where only the specific sendmail endpoint config is provided,
instead of a full notification config.
If package version requirements are bumped correctly this should not
strictly be needed, but this tiny fallback-mechanism does not really
hurt, as the old `send` path will continue to exist anyway.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 src/PVE/Notify.pm | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/PVE/Notify.pm b/src/PVE/Notify.pm
index 89be6bc..5cfecf3 100644
--- a/src/PVE/Notify.pm
+++ b/src/PVE/Notify.pm
@@ -64,8 +64,22 @@ sub write_config {
 
 my $send_notification = sub {
     my ($severity, $template_name, $template_data, $fields, $config) = @_;
-    $config = read_config() if !defined($config);
-    $config->send($severity, $template_name, $template_data, $fields);
+
+    my $recipient = undef;
+
+    if (defined($config)) {
+        if (ref($config) eq 'PVE::RS::Notify') {
+            # Old style with explicitly provided config, call send directly.
+            $config->send($severity, $template_name, $template_data, $fields);
+            return;
+        } else {
+            # New style email-based recipient, set the recipient to the provided config
+            # and try to send via queue.
+            $recipient = $config;
+        }
+    }
+
+    PVE::RS::Notify::enqueue($severity, $template_name, $template_data, $fields, $recipient);
 };
 
 sub notify {
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH manager v2 52/63] vzdump: send legacy-sendmail notifications via simplified API
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (50 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH pve-cluster v2 51/63] notify: send notifications via notification queue Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH manager v2 53/63] debian: create notification queue directory via tmpfiles Lukas Wagner
                   ` (11 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

Instead of passing the full configuration, one can now pass a simplified
subset of the sendmail configuration as an optional parameter. In the
glue code in libpve-notify-perl, this is translated into a fitting
'recipient' parameter for the notification.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 PVE/VZDump.pm | 28 ++--------------------------
 1 file changed, 2 insertions(+), 26 deletions(-)

diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index d2861f9e..b27e6e03 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -545,34 +545,10 @@ sub send_notification {
 
     if (($mode eq 'auto' && $email_configured) || $mode eq 'legacy-sendmail') {
         if ($email_configured && ($policy eq "always" || ($policy eq "failure" && $failed))) {
-            # Start out with an empty config. Might still contain
-            # built-ins, so we need to disable/remove them.
-            my $notification_config = PVE::RS::Notify->parse_config('', '');
-
-            # Remove built-in matchers, since we only want to send an
-            # email to the specified recipients and nobody else.
-            for my $matcher (@{ $notification_config->get_matchers() }) {
-                $notification_config->delete_matcher($matcher->{name});
-            }
-
-            # <, >, @ are not allowed in endpoint names, but that is only
-            # verified once the config is serialized. That means that
-            # we can rely on that fact that no other endpoint with this name exists.
-            my $endpoint_name = "<" . join(",", @$mailto) . ">";
-            $notification_config->add_sendmail_endpoint({
-                name => $endpoint_name,
+            my $notification_config = {
                 mailto => $mailto,
                 author => "vzdump backup tool",
-            });
-
-            my $endpoints = [$endpoint_name];
-
-            # Add a matcher that matches all notifications, set our
-            # newly created target as a target.
-            $notification_config->add_matcher({
-                name => "<matcher-$endpoint_name>",
-                target => $endpoints,
-            });
+            };
 
             PVE::Notify::notify(
                 $severity, "vzdump", $template_data, $fields, $notification_config,
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH manager v2 53/63] debian: create notification queue directory via tmpfiles
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (51 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH manager v2 52/63] vzdump: send legacy-sendmail notifications via simplified API Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH manager v2 54/63] debian: add 'pve-notify-worker' as dependecy Lukas Wagner
                   ` (10 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 debian/tmpfiles | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/debian/tmpfiles b/debian/tmpfiles
index 1263300f..5d2edb48 100644
--- a/debian/tmpfiles
+++ b/debian/tmpfiles
@@ -1,2 +1,3 @@
-#Type Path     Mode User Group     Age Argument
-d     /run/pve 0750 root www-data  -   -
+#Type Path                                       Mode User Group     Age Argument
+d     /run/pve                                   0750 root www-data    -   -
+d     /var/lib/pve-manager/notifications/queue   0770 root www-data    -   -
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH manager v2 54/63] debian: add 'pve-notify-worker' as dependecy
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (52 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH manager v2 53/63] debian: create notification queue directory via tmpfiles Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH manager v2 55/63] api: services: add 'pve-notify-worker' as known service Lukas Wagner
                   ` (9 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

>From now on, when sending notification, it is written to a notification
queue as a serialized JSON file. pve-notify-worker is a daemon that
regularly processes any queued notification, hence it is a required
service from now on.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 debian/control | 1 +
 1 file changed, 1 insertion(+)

diff --git a/debian/control b/debian/control
index 1d5cc294..a9cb2fce 100644
--- a/debian/control
+++ b/debian/control
@@ -92,6 +92,7 @@ Depends: apt (>= 1.5~),
          pve-firewall,
          pve-ha-manager (>= 5.2.5),
          pve-i18n (>= 3.2.0~),
+         pve-notify-worker,
          pve-xtermjs (>= 4.7.0-1),
          pve-yew-mobile-gui (>= 0.5.1),
          qemu-server (>= 9.2.17),
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH manager v2 55/63] api: services: add 'pve-notify-worker' as known service
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (53 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH manager v2 54/63] debian: add 'pve-notify-worker' as dependecy Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH manager v2 56/63] services: request pve-notify-worker.service via Wants Lukas Wagner
                   ` (8 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

This allows users to start, stop, restart this new service, as well as
retrieve its logs from the journal.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---

Notes:
    New in v2.

 PVE/API2/Services.pm | 1 +
 1 file changed, 1 insertion(+)

diff --git a/PVE/API2/Services.pm b/PVE/API2/Services.pm
index b7bae6b5..d127e472 100644
--- a/PVE/API2/Services.pm
+++ b/PVE/API2/Services.pm
@@ -29,6 +29,7 @@ my $service_name_list = [
     'pve-ha-crm',
     'pve-ha-lrm',
     'pve-lxc-syscalld',
+    'pve-notify-worker',
     'pvedaemon',
     'pvefw-logger',
     'pveproxy',
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH manager v2 56/63] services: request pve-notify-worker.service via Wants
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (54 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH manager v2 55/63] api: services: add 'pve-notify-worker' as known service Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox-mail-forward v2 57/63] forward mails via notification queue Lukas Wagner
                   ` (7 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 services/pvedaemon.service    | 2 +-
 services/pvescheduler.service | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/services/pvedaemon.service b/services/pvedaemon.service
index f922570f..d795ccba 100644
--- a/services/pvedaemon.service
+++ b/services/pvedaemon.service
@@ -1,7 +1,7 @@
 [Unit]
 Description=PVE API Daemon
 ConditionPathExists=/usr/bin/pvedaemon
-Wants=corosync.service pve-cluster.service
+Wants=corosync.service pve-cluster.service pve-notify-worker.service
 After=corosync.service pve-cluster.service
 
 [Service]
diff --git a/services/pvescheduler.service b/services/pvescheduler.service
index 8f410101..b49aa3b6 100644
--- a/services/pvescheduler.service
+++ b/services/pvescheduler.service
@@ -2,6 +2,7 @@
 Description=Proxmox VE scheduler
 ConditionPathExists=/usr/bin/pvescheduler
 Wants=pve-cluster.service
+Wants=pve-notify-worker.service
 After=pve-cluster.service
 After=pve-guests.service
 After=pve-storage.target
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox-mail-forward v2 57/63] forward mails via notification queue
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (55 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH manager v2 56/63] services: request pve-notify-worker.service via Wants Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox-mail-forward v2 58/63] use return code to signal permanent or temporary failure Lukas Wagner
                   ` (6 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

Instead of loading the notification configuration and sending the
notification directly, submit the forwarded mail to the notification
queue of the installed product. The product's notification worker then
picks it up and handles matching and delivery like for any other
notification.

This way, the setuid helper no longer parses the product's notification
configuration, including the private part with secrets, and contains
none of the sending logic. The product-specific workarounds go away as
well, such as the default sendmail target that was added for PBS
installations without a notifications.cfg.

The helper still has to start as root, since postfix runs it as 'nobody'
and the queue must not be world-writable. Root is only used to switch to
the user and group that own the queue (www-data for PVE, backup for
PBS), and all privileges are dropped permanently before the mail is
read. A bug in the code handling the mail can therefore not be used to
gain root, and queue files get the ownership the consumer expects.

If PVE and PBS are installed on the same host, the mail is now only
submitted to the PVE queue. Previously, it was passed to both
notification systems, unless PBS had no notifications.cfg of its own.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 Cargo.toml  |   5 +-
 src/main.rs | 227 ++++++++++++++++++++++++++++++----------------------
 2 files changed, 133 insertions(+), 99 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 6860f49..d6ba2ae 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,8 +18,5 @@ anyhow = "1.0"
 nix = "0.29"
 
 proxmox-log = "1"
-proxmox-notify = {version = "2", features = ["mail-forwarder", "pve-context", "pbs-context", "legacy-matchers"] }
+proxmox-notify = { version = "2", features = ["queue-submitter"] }
 proxmox-sys = "1"
-
-# Not directly used, this is just to force it to the new version:
-proxmox-http = "1.0.2"
diff --git a/src/main.rs b/src/main.rs
index a95d75c..d388134 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,54 +1,114 @@
 //! A helper binary that forwards any mail passed via stdin to
-//! proxmox_notify.
+//! the notification queue of the currently installed Proxmox product.
+//!
+//! If multiple products are installed side-by-side, only one notification is created.
+//! The order of precedence is:
+//!   - PVE
+//!   - PBS
 //!
 //! The binary's path is added to /root/.forward, which means that
 //! postfix will invoke it when the local root user receives an email message.
 //! The message is passed via stdin.
-//! The binary is installed with setuid permissions and will thus run as
-//! root (euid ~ root, ruid ~ nobody)
+//! The binary is installed with setuid permissions and will thus start as
+//! root (euid ~ root, ruid ~ nobody).
 //!
-//! The forwarding behavior is the following:
-//!   - PVE installed: Use PVE's notifications.cfg
-//!   - PBS installed: Use PBS's notifications.cfg if present. If not,
-//!     use an empty configuration and add a default sendmail target and
-//!     a matcher - this is needed because notifications are not yet
-//!     integrated in PBS.
-//!   - PVE/PBS co-installed: Use PVE's config *and* PBS's config, but if
-//!     PBS's config does not exist, a default sendmail target will *not* be
-//!     added. We assume that PVE's config contains the desired notification
-//!     behavior for system mails.
+//! The setuid permissions are needed since postfix will run the script as
+//! `nobody`. If we would not become `root` via a setuid binary, we would need to
+//! make the notification submission queue world-writable, which is
+//! not what we want.
 //!
+//! Root privileges are only needed to switch to the user that owns the
+//! notification queue of the installed product. Once the product has been
+//! determined, the binary permanently drops to that user and group before
+//! reading the mail from stdin.
+
 use std::io::Read;
 use std::path::Path;
 
+use anyhow::Context;
 use anyhow::Error;
+use anyhow::bail;
+use nix::sys::stat::Mode;
+use nix::unistd::Gid;
+use nix::unistd::Group;
+use nix::unistd::Uid;
+use nix::unistd::User;
 
 use proxmox_log::LevelFilter;
 use proxmox_log::Logger;
 use proxmox_log::error;
-use proxmox_notify::Config;
-use proxmox_notify::context::pbs::PBS_CONTEXT;
-use proxmox_notify::context::pve::PVE_CONTEXT;
-use proxmox_sys::fs;
+use proxmox_notify::Notification;
+use proxmox_notify::Severity;
+use proxmox_notify::queue::QueueSubmitter;
+use proxmox_sys::fs::CreateOptions;
 
-const PVE_CFG_PATH: &str = "/etc/pve";
-const PVE_PUB_NOTIFICATION_CFG_FILENAME: &str = "/etc/pve/notifications.cfg";
-const PVE_PRIV_NOTIFICATION_CFG_FILENAME: &str = "/etc/pve/priv/notifications.cfg";
+/// A Proxmox product whose notifications are processed via a notification queue.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+enum Product {
+    /// Proxmox VE
+    Pve,
+    /// Proxmox Backup Server
+    Pbs,
+}
 
-const PBS_CFG_PATH: &str = "/etc/proxmox-backup";
-const PBS_PUB_NOTIFICATION_CFG_FILENAME: &str = "/etc/proxmox-backup/notifications.cfg";
-const PBS_PRIV_NOTIFICATION_CFG_FILENAME: &str = "/etc/proxmox-backup/notifications-priv.cfg";
+impl Product {
+    /// All supported products, in order of precedence.
+    const ALL: &[Product] = &[Product::Pve, Product::Pbs];
 
-/// Wrapper around `proxmox_sys::fs::file_read_optional_string` which also returns `None` upon error
-/// after logging it.
-fn attempt_file_read<P: AsRef<Path>>(path: P) -> Option<String> {
-    match fs::file_read_optional_string(path.as_ref()) {
-        Ok(contents) => contents,
-        Err(err) => {
-            error!("unable to read {path:?}: {err:#}", path = path.as_ref());
-            None
+    /// Directory of the product's notification queue.
+    fn queue_dir(self) -> &'static str {
+        match self {
+            Self::Pve => "/var/lib/pve-manager/notifications/queue",
+            Self::Pbs => "/var/lib/proxmox-backup/notifications/queue",
         }
     }
+
+    /// Check whether the product is installed on this host.
+    ///
+    /// A product counts as installed if its notification queue directory exists.
+    fn is_installed(self) -> bool {
+        Path::new(self.queue_dir()).exists()
+    }
+
+    /// Name of the user that owns the notification queue.
+    fn user(self) -> &'static str {
+        match self {
+            Self::Pve => "www-data",
+            Self::Pbs => "backup",
+        }
+    }
+
+    /// Name of the group that owns the notification queue.
+    fn group(self) -> &'static str {
+        match self {
+            Self::Pve => "www-data",
+            Self::Pbs => "backup",
+        }
+    }
+
+    /// Look up the ID of the user that owns the notification queue.
+    fn uid(self) -> Result<Uid, Error> {
+        let user = self.user();
+
+        let uid = User::from_name(user)
+            .with_context(|| format!("could not look up username {user}"))?
+            .with_context(|| format!("user {user} does not exist"))?
+            .uid;
+
+        Ok(uid)
+    }
+
+    /// Look up the ID of the group that owns the notification queue.
+    fn gid(self) -> Result<Gid, Error> {
+        let group = self.group();
+
+        let gid = Group::from_name(group)
+            .with_context(|| format!("could not look up group {group}"))?
+            .with_context(|| format!("group {group} does not exist"))?
+            .gid;
+
+        Ok(gid)
+    }
 }
 
 /// Read data from stdin, until EOF is encountered.
@@ -61,55 +121,53 @@ fn read_stdin() -> Result<Vec<u8>, Error> {
     Ok(input)
 }
 
-fn forward_common(mail: &[u8], config: &Config) -> Result<(), Error> {
-    let real_uid = nix::unistd::getuid();
-    // The uid is passed so that `sendmail` can be called as the a correct user.
-    // (sendmail will show a warning if called from a setuid process)
-    let notification =
-        proxmox_notify::Notification::new_forwarded_mail(mail, Some(real_uid.as_raw()))?;
+fn installed_product() -> Result<Product, Error> {
+    Product::ALL
+        .iter()
+        .copied()
+        .find(|product| product.is_installed())
+        .context("no supported Proxmox product installed")
+}
 
-    proxmox_notify::api::common::send(config, &notification)?;
+/// Permanently switch to `uid` and `gid`, dropping all supplementary groups.
+///
+/// The real, effective and saved IDs are all set, so that the original privileges cannot be
+/// regained afterwards.
+fn drop_privileges(uid: Uid, gid: Gid) -> Result<(), Error> {
+    // Supplementary groups and the group IDs can only be changed while still privileged, so the
+    // user ID must be changed last.
+    nix::unistd::setgroups(&[]).context("could not drop supplementary groups")?;
+    nix::unistd::setresgid(gid, gid, gid).with_context(|| format!("could not set gid to {gid}"))?;
+    nix::unistd::setresuid(uid, uid, uid).with_context(|| format!("could not set uid to {uid}"))?;
+
+    if uid != Uid::from_raw(0) && nix::unistd::setuid(Uid::from_raw(0)).is_ok() {
+        bail!("root privileges could be regained after dropping them");
+    }
 
     Ok(())
 }
 
-/// Forward a mail to PVE's notification system
-fn forward_for_pve(mail: &[u8]) -> Result<(), Error> {
-    proxmox_notify::context::set_context(&PVE_CONTEXT);
-    let config = attempt_file_read(PVE_PUB_NOTIFICATION_CFG_FILENAME).unwrap_or_default();
-    let priv_config = attempt_file_read(PVE_PRIV_NOTIFICATION_CFG_FILENAME).unwrap_or_default();
+fn forward_mail_from_stdin() -> Result<(), Error> {
+    let product = installed_product()?;
+    drop_privileges(product.uid()?, product.gid()?)?;
 
-    let config = Config::new(&config, &priv_config)?;
+    let mail = read_stdin().context("could not read mail from STDIN")?;
 
-    forward_common(mail, &config)
-}
+    // Files are created by the queue's owner now, so only the mode needs to be set explicitly.
+    let queue = QueueSubmitter::new(
+        product.queue_dir(),
+        CreateOptions::new().perm(Mode::from_bits_truncate(0o0660)),
+    );
 
-/// Forward a mail to PBS's notification system
-fn forward_for_pbs(mail: &[u8], has_pve: bool) -> Result<(), Error> {
-    proxmox_notify::context::set_context(&PBS_CONTEXT);
+    let notification = Notification::forwarded_mail_builder(mail)
+        .severity(Severity::Unknown)
+        .field("hostname", proxmox_sys::nodename())
+        .field("type", "system-mail")
+        .build()?;
 
-    let config = if Path::new(PBS_PUB_NOTIFICATION_CFG_FILENAME).exists() {
-        let config = attempt_file_read(PBS_PUB_NOTIFICATION_CFG_FILENAME).unwrap_or_default();
-        let priv_config = attempt_file_read(PBS_PRIV_NOTIFICATION_CFG_FILENAME).unwrap_or_default();
-
-        Config::new(&config, &priv_config)?
-    } else {
-        // Instantiate empty config.
-        // Note: This will contain the default built-in targets/matchers.
-        let config = Config::new("", "")?;
-        if has_pve {
-            // Skip forwarding if we are co-installed with PVE AND
-            // we do not have our own notifications.cfg file yet
-            // --> We assume that PVE has a sane matcher configured that
-            // forwards the mail properly
-            // TODO: This can be removed once PBS has full notification integration
-
-            return Ok(());
-        }
-        config
-    };
-
-    forward_common(mail, &config)?;
+    queue
+        .submit(&notification)
+        .context("could not submit mail to notification queue")?;
 
     Ok(())
 }
@@ -119,31 +177,10 @@ fn main() {
         .journald()
         .init()
     {
-        eprintln!("unable to initialize syslog: {err}");
+        eprintln!("unable to initialize logging: {err}");
     }
 
-    // Read the mail that is to be forwarded from stdin
-    match read_stdin() {
-        Ok(mail) => {
-            let mut has_pve = false;
-
-            // Assume a PVE installation if /etc/pve exists
-            if Path::new(PVE_CFG_PATH).exists() {
-                has_pve = true;
-                if let Err(err) = forward_for_pve(&mail) {
-                    error!("could not forward mail for Proxmox VE: {err:#}");
-                }
-            }
-
-            // Assume a PBS installation if /etc/proxmox-backup exists
-            if Path::new(PBS_CFG_PATH).exists() {
-                if let Err(err) = forward_for_pbs(&mail, has_pve) {
-                    error!("could not forward mail for Proxmox Backup Server: {err:#}");
-                }
-            }
-        }
-        Err(err) => {
-            error!("could not read mail from STDIN: {err:#}")
-        }
+    if let Err(err) = forward_mail_from_stdin() {
+        error!("proxmox-mail-forward could not forward email: {err:#}");
     }
 }
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox-mail-forward v2 58/63] use return code to signal permanent or temporary failure
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (56 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox-mail-forward v2 57/63] forward mails via notification queue Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox-mail-forward v2 59/63] limit size of mail read from stdin Lukas Wagner
                   ` (5 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

Previously, we returned 0 if there was an error, giving Postfix no
indication that the delivery of the notification failed. By returning
EX_TEMPFAIL (75) we signal Postfix to retry later, by returning
EX_DATAERR (65), we let the mail bounce.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 src/main.rs | 64 ++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 56 insertions(+), 8 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index d388134..8a60df9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -24,6 +24,7 @@
 
 use std::io::Read;
 use std::path::Path;
+use std::process::ExitCode;
 
 use anyhow::Context;
 use anyhow::Error;
@@ -42,6 +43,37 @@ use proxmox_notify::Severity;
 use proxmox_notify::queue::QueueSubmitter;
 use proxmox_sys::fs::CreateOptions;
 
+enum ForwardError {
+    Temporary(Error),
+    Bounce(Error),
+}
+
+impl From<ForwardError> for ExitCode {
+    fn from(value: ForwardError) -> Self {
+        match value {
+            // EX_TEMPFAIL -> postfix retries later
+            ForwardError::Temporary(_) => ExitCode::from(75),
+            // EX_DATAERR -> mail bounces
+            ForwardError::Bounce(_) => ExitCode::from(65),
+        }
+    }
+}
+
+impl std::fmt::Display for ForwardError {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        match self {
+            ForwardError::Temporary(error) => write!(
+                f,
+                "proxmox-mail-forward could not forward email to notification queue, retrying later: {error:#}"
+            ),
+            ForwardError::Bounce(error) => write!(
+                f,
+                "proxmox-mail-forward could not forward email, dropping email: {error:#}"
+            ),
+        }
+    }
+}
+
 /// A Proxmox product whose notifications are processed via a notification queue.
 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
 enum Product {
@@ -147,11 +179,17 @@ fn drop_privileges(uid: Uid, gid: Gid) -> Result<(), Error> {
     Ok(())
 }
 
-fn forward_mail_from_stdin() -> Result<(), Error> {
-    let product = installed_product()?;
-    drop_privileges(product.uid()?, product.gid()?)?;
+fn forward_mail_from_stdin() -> Result<(), ForwardError> {
+    let product = installed_product().map_err(ForwardError::Temporary)?;
+    drop_privileges(
+        product.uid().map_err(ForwardError::Temporary)?,
+        product.gid().map_err(ForwardError::Temporary)?,
+    )
+    .map_err(ForwardError::Temporary)?;
 
-    let mail = read_stdin().context("could not read mail from STDIN")?;
+    let mail = read_stdin()
+        .context("could not read mail from STDIN")
+        .map_err(ForwardError::Bounce)?;
 
     // Files are created by the queue's owner now, so only the mode needs to be set explicitly.
     let queue = QueueSubmitter::new(
@@ -163,16 +201,18 @@ fn forward_mail_from_stdin() -> Result<(), Error> {
         .severity(Severity::Unknown)
         .field("hostname", proxmox_sys::nodename())
         .field("type", "system-mail")
-        .build()?;
+        .build()
+        .map_err(|err| ForwardError::Bounce(err.into()))?;
 
     queue
         .submit(&notification)
-        .context("could not submit mail to notification queue")?;
+        .context("could not submit mail to notification queue")
+        .map_err(ForwardError::Temporary)?;
 
     Ok(())
 }
 
-fn main() {
+fn main() -> ExitCode {
     if let Err(err) = Logger::from_env("PROXMOX_LOG", LevelFilter::INFO)
         .journald()
         .init()
@@ -181,6 +221,14 @@ fn main() {
     }
 
     if let Err(err) = forward_mail_from_stdin() {
-        error!("proxmox-mail-forward could not forward email: {err:#}");
+        error!("{err:#}");
+
+        // Print the error to stderr as well, since that will be shown
+        // in `mailq` output for deferred emails.
+        eprintln!("{err:#}");
+
+        return err.into();
     }
+
+    ExitCode::SUCCESS
 }
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox-mail-forward v2 59/63] limit size of mail read from stdin
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (57 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox-mail-forward v2 58/63] use return code to signal permanent or temporary failure Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox-mail-forward v2 60/63] cargo: move mail forwarder into a workspace member crate Lukas Wagner
                   ` (4 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

Previously, the whole mail passed via stdin was read into memory
without any bound. Since the binary is invoked by postfix for every
mail delivered to root, an unexpectedly large mail could cause
excessive memory usage and result in an equally large entry in the
notification queue.

For mails sent from local system daemons, we don't expect any email
attachments or the like, so a limit of 1MB should be more than enough.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 src/main.rs | 56 +++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 52 insertions(+), 4 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 8a60df9..60c8336 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -143,16 +143,33 @@ impl Product {
     }
 }
 
-/// Read data from stdin, until EOF is encountered.
-fn read_stdin() -> Result<Vec<u8>, Error> {
+/// Maximum number of bytes read from stdin, as a safeguard against excessively large mails.
+const MAX_MAIL_SIZE: u64 = 1024 * 1024;
+
+/// Read data from `reader` until EOF is encountered.
+///
+/// Returns an error if the input exceeds `limit` bytes.
+fn read_limited(reader: impl Read, limit: u64) -> Result<Vec<u8>, Error> {
     let mut input = Vec::new();
-    let stdin = std::io::stdin();
-    let mut handle = stdin.lock();
+    // Read one additional byte to detect whether the input exceeds the limit.
+    let mut handle = reader.take(limit + 1);
 
     handle.read_to_end(&mut input)?;
+
+    if input.len() as u64 > limit {
+        bail!("mail exceeds maximum size of {limit} bytes");
+    }
+
     Ok(input)
 }
 
+/// Read data from stdin until EOF is encountered.
+///
+/// Returns an error if the input exceeds [`MAX_MAIL_SIZE`] bytes.
+fn read_stdin() -> Result<Vec<u8>, Error> {
+    read_limited(std::io::stdin().lock(), MAX_MAIL_SIZE)
+}
+
 fn installed_product() -> Result<Product, Error> {
     Product::ALL
         .iter()
@@ -232,3 +249,34 @@ fn main() -> ExitCode {
 
     ExitCode::SUCCESS
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    #[test]
+    fn read_limited_below_limit() {
+        let data = b"Subject: test\n\nbody\n";
+        let input = read_limited(&data[..], 64).unwrap();
+        assert_eq!(input, data);
+    }
+
+    #[test]
+    fn read_limited_exactly_at_limit() {
+        let data = vec![b'a'; 64];
+        let input = read_limited(&data[..], 64).unwrap();
+        assert_eq!(input, data);
+    }
+
+    #[test]
+    fn read_limited_rejects_above_limit() {
+        let data = vec![b'a'; 65];
+        assert!(read_limited(&data[..], 64).is_err());
+    }
+
+    #[test]
+    fn read_limited_empty() {
+        let input = read_limited(&b""[..], 64).unwrap();
+        assert!(input.is_empty());
+    }
+}
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox-mail-forward v2 60/63] cargo: move mail forwarder into a workspace member crate
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (58 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox-mail-forward v2 59/63] limit size of mail read from stdin Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox-mail-forward v2 61/63] add crate for code shared between the mail-forwarder and the worker Lukas Wagner
                   ` (3 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

This allows adding the notification worker daemon as a separate crate
in the same workspace, so that each binary only pulls in the
dependencies it actually needs.

Since 'cargo install' does not support virtual workspace roots,
install the binary from the Makefile directly to /usr/libexec instead
of moving it there from /usr/bin in d/rules. As the debian cargo
wrapper always passes '--target', include it in release builds to
know where the compiled binaries end up.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 Cargo.toml                                | 16 +++++++++-------
 Makefile                                  | 13 +++++++------
 debian/rules                              |  4 ----
 proxmox-mail-forward/Cargo.toml           | 16 ++++++++++++++++
 {src => proxmox-mail-forward/src}/main.rs |  0
 5 files changed, 32 insertions(+), 17 deletions(-)
 create mode 100644 proxmox-mail-forward/Cargo.toml
 rename {src => proxmox-mail-forward/src}/main.rs (100%)

diff --git a/Cargo.toml b/Cargo.toml
index d6ba2ae..e6e70c6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,5 +1,10 @@
-[package]
-name = "proxmox-mail-forward"
+[workspace]
+members = [
+    "proxmox-mail-forward",
+]
+resolver = "3"
+
+[workspace.package]
 version = "1.1.0"
 authors = [
     "Fiona Ebner <f.ebner@proxmox.com>",
@@ -8,15 +13,12 @@ authors = [
 ]
 edition = "2024"
 license = "AGPL-3"
-description = "Proxmox mail forward helper"
 homepage = "https://www.proxmox.com"
 
-exclude = [ "debian" ]
-
-[dependencies]
+[workspace.dependencies]
 anyhow = "1.0"
 nix = "0.29"
 
 proxmox-log = "1"
-proxmox-notify = { version = "2", features = ["queue-submitter"] }
+proxmox-notify = "2"
 proxmox-sys = "1"
diff --git a/Makefile b/Makefile
index 8b0f728..72ae89a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,6 @@
 include /usr/share/dpkg/pkg-info.mk
 include /usr/share/dpkg/architecture.mk
+include /usr/share/rustc/architecture.mk
 
 PACKAGE=proxmox-mail-forward
 BUILDDIR ?= $(PACKAGE)-$(DEB_VERSION)
@@ -11,8 +12,8 @@ DBG_DEB=$(PACKAGE)-dbgsym_$(DEB_VERSION)_$(DEB_HOST_ARCH).deb
 DEBS=$(DEB) $(DBG_DEB)
 
 ifeq ($(BUILD_MODE), release)
-CARGO_BUILD_ARGS += --release
-COMPILEDIR := target/release
+CARGO_BUILD_ARGS += --release --target $(DEB_HOST_RUST_TYPE)
+COMPILEDIR := target/$(DEB_HOST_RUST_TYPE)/release
 else
 COMPILEDIR := target/debug
 endif
@@ -21,7 +22,7 @@ CARGO ?= cargo
 
 $(BUILDDIR):
 	rm -rf $@ $@.tmp && mkdir $@.tmp
-	cp -a debian Cargo.toml src Makefile .cargo $@.tmp
+	cp -a debian Cargo.toml proxmox-mail-forward Makefile .cargo $@.tmp
 	rm -f $@.tmp/Cargo.lock
 	find $@.tmp/debian -name "*.hint" -delete
 	mv $@.tmp $@
@@ -49,11 +50,11 @@ dinstall: $(DEBS)
 .PHONY: cargo-build
 cargo-build:
 	$(CARGO) build $(CARGO_BUILD_ARGS) \
-	    --package proxmox-mail-forward \
-	    --bin proxmox-mail-forward
+	    --package proxmox-mail-forward
 
 install: cargo-build
-	$(CARGO) install
+	install -d $(DESTDIR)/usr/libexec
+	install -m 0755 $(COMPILEDIR)/proxmox-mail-forward $(DESTDIR)/usr/libexec/
 
 .PHONY: upload
 upload: $(DEBS)
diff --git a/debian/rules b/debian/rules
index cc2ec17..ddde12f 100755
--- a/debian/rules
+++ b/debian/rules
@@ -26,11 +26,7 @@ override_dh_auto_configure:
 	dh_auto_configure
 
 execute_after_dh_auto_install:
-	# Install the binary to /usr/libexec, not /usr/bin. Inspired by virtiofsd's d/rules
-	mkdir -p debian/proxmox-mail-forward/usr/libexec
-	mv debian/proxmox-mail-forward/usr/bin/proxmox-mail-forward debian/proxmox-mail-forward/usr/libexec/
 	chmod u+s debian/proxmox-mail-forward/usr/libexec/proxmox-mail-forward
-	rmdir debian/proxmox-mail-forward/usr/bin
 
 override_dh_fixperms:
 	dh_fixperms --exclude proxmox-mail-forward
diff --git a/proxmox-mail-forward/Cargo.toml b/proxmox-mail-forward/Cargo.toml
new file mode 100644
index 0000000..c3f7f7d
--- /dev/null
+++ b/proxmox-mail-forward/Cargo.toml
@@ -0,0 +1,16 @@
+[package]
+name = "proxmox-mail-forward"
+description = "Proxmox mail forward helper"
+version.workspace = true
+authors.workspace = true
+edition.workspace = true
+license.workspace = true
+homepage.workspace = true
+
+[dependencies]
+anyhow.workspace = true
+nix.workspace = true
+
+proxmox-log.workspace = true
+proxmox-notify = { workspace = true, features = ["queue-submitter"] }
+proxmox-sys.workspace = true
diff --git a/src/main.rs b/proxmox-mail-forward/src/main.rs
similarity index 100%
rename from src/main.rs
rename to proxmox-mail-forward/src/main.rs
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox-mail-forward v2 61/63] add crate for code shared between the mail-forwarder and the worker
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (59 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox-mail-forward v2 60/63] cargo: move mail forwarder into a workspace member crate Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox-mail-forward v2 62/63] add pve-notify-worker crate and package Lukas Wagner
                   ` (2 subsequent siblings)
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 Cargo.toml                       |  3 ++
 Makefile                         |  2 +-
 common/Cargo.toml                | 13 ++++++
 common/src/lib.rs                | 78 ++++++++++++++++++++++++++++++++
 proxmox-mail-forward/Cargo.toml  |  2 +
 proxmox-mail-forward/src/main.rs | 74 +-----------------------------
 6 files changed, 99 insertions(+), 73 deletions(-)
 create mode 100644 common/Cargo.toml
 create mode 100644 common/src/lib.rs

diff --git a/Cargo.toml b/Cargo.toml
index e6e70c6..27e4d8e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,5 +1,6 @@
 [workspace]
 members = [
+    "common",
     "proxmox-mail-forward",
 ]
 resolver = "3"
@@ -22,3 +23,5 @@ nix = "0.29"
 proxmox-log = "1"
 proxmox-notify = "2"
 proxmox-sys = "1"
+
+common = { path = "common" }
diff --git a/Makefile b/Makefile
index 72ae89a..0c7dc72 100644
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,7 @@ CARGO ?= cargo
 
 $(BUILDDIR):
 	rm -rf $@ $@.tmp && mkdir $@.tmp
-	cp -a debian Cargo.toml proxmox-mail-forward Makefile .cargo $@.tmp
+	cp -a debian Cargo.toml common proxmox-mail-forward Makefile .cargo $@.tmp
 	rm -f $@.tmp/Cargo.lock
 	find $@.tmp/debian -name "*.hint" -delete
 	mv $@.tmp $@
diff --git a/common/Cargo.toml b/common/Cargo.toml
new file mode 100644
index 0000000..e66ec5e
--- /dev/null
+++ b/common/Cargo.toml
@@ -0,0 +1,13 @@
+[package]
+name = "common"
+description = "Shared definitions for the Proxmox mail forwarder and notification worker"
+version.workspace = true
+authors.workspace = true
+edition.workspace = true
+license.workspace = true
+homepage.workspace = true
+publish = false
+
+[dependencies]
+anyhow.workspace = true
+nix = { workspace = true, features = [ "user" ] }
diff --git a/common/src/lib.rs b/common/src/lib.rs
new file mode 100644
index 0000000..fe03064
--- /dev/null
+++ b/common/src/lib.rs
@@ -0,0 +1,78 @@
+//! Definitions shared between the Proxmox mail forwarder and the notification worker.
+
+#![deny(unsafe_code)]
+#![deny(missing_docs)]
+
+use std::path::Path;
+
+use anyhow::{Context, Error};
+use nix::unistd::{Gid, Group, Uid, User};
+
+/// A Proxmox product whose notifications are processed via a notification queue.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum Product {
+    /// Proxmox VE
+    Pve,
+    /// Proxmox Backup Server
+    Pbs,
+}
+
+impl Product {
+    /// All supported products, in order of precedence.
+    pub const ALL: &[Product] = &[Product::Pve, Product::Pbs];
+
+    /// Directory of the product's notification queue.
+    pub fn queue_dir(self) -> &'static str {
+        match self {
+            Self::Pve => "/var/lib/pve-manager/notifications/queue",
+            Self::Pbs => "/var/lib/proxmox-backup/notifications/queue",
+        }
+    }
+
+    /// Check whether the product is installed on this host.
+    ///
+    /// A product counts as installed if its notification queue directory exists.
+    pub fn is_installed(self) -> bool {
+        Path::new(self.queue_dir()).exists()
+    }
+
+    /// Name of the user that owns the notification queue.
+    pub fn user(self) -> &'static str {
+        match self {
+            Self::Pve => "www-data",
+            Self::Pbs => "backup",
+        }
+    }
+
+    /// Name of the group that owns the notification queue.
+    pub fn group(self) -> &'static str {
+        match self {
+            Self::Pve => "www-data",
+            Self::Pbs => "backup",
+        }
+    }
+
+    /// Look up the ID of the user that owns the notification queue.
+    pub fn uid(self) -> Result<Uid, Error> {
+        let user = self.user();
+
+        let uid = User::from_name(user)
+            .with_context(|| format!("could not look up username {user}"))?
+            .with_context(|| format!("user {user} does not exist"))?
+            .uid;
+
+        Ok(uid)
+    }
+
+    /// Look up the ID of the group that owns the notification queue.
+    pub fn gid(self) -> Result<Gid, Error> {
+        let group = self.group();
+
+        let gid = Group::from_name(group)
+            .with_context(|| format!("could not look up group {group}"))?
+            .with_context(|| format!("group {group} does not exist"))?
+            .gid;
+
+        Ok(gid)
+    }
+}
diff --git a/proxmox-mail-forward/Cargo.toml b/proxmox-mail-forward/Cargo.toml
index c3f7f7d..ef3e4a7 100644
--- a/proxmox-mail-forward/Cargo.toml
+++ b/proxmox-mail-forward/Cargo.toml
@@ -11,6 +11,8 @@ homepage.workspace = true
 anyhow.workspace = true
 nix.workspace = true
 
+common.workspace = true
+
 proxmox-log.workspace = true
 proxmox-notify = { workspace = true, features = ["queue-submitter"] }
 proxmox-sys.workspace = true
diff --git a/proxmox-mail-forward/src/main.rs b/proxmox-mail-forward/src/main.rs
index 60c8336..0673728 100644
--- a/proxmox-mail-forward/src/main.rs
+++ b/proxmox-mail-forward/src/main.rs
@@ -23,7 +23,6 @@
 //! reading the mail from stdin.
 
 use std::io::Read;
-use std::path::Path;
 use std::process::ExitCode;
 
 use anyhow::Context;
@@ -31,9 +30,9 @@ use anyhow::Error;
 use anyhow::bail;
 use nix::sys::stat::Mode;
 use nix::unistd::Gid;
-use nix::unistd::Group;
 use nix::unistd::Uid;
-use nix::unistd::User;
+
+use common::Product;
 
 use proxmox_log::LevelFilter;
 use proxmox_log::Logger;
@@ -74,75 +73,6 @@ impl std::fmt::Display for ForwardError {
     }
 }
 
-/// A Proxmox product whose notifications are processed via a notification queue.
-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
-enum Product {
-    /// Proxmox VE
-    Pve,
-    /// Proxmox Backup Server
-    Pbs,
-}
-
-impl Product {
-    /// All supported products, in order of precedence.
-    const ALL: &[Product] = &[Product::Pve, Product::Pbs];
-
-    /// Directory of the product's notification queue.
-    fn queue_dir(self) -> &'static str {
-        match self {
-            Self::Pve => "/var/lib/pve-manager/notifications/queue",
-            Self::Pbs => "/var/lib/proxmox-backup/notifications/queue",
-        }
-    }
-
-    /// Check whether the product is installed on this host.
-    ///
-    /// A product counts as installed if its notification queue directory exists.
-    fn is_installed(self) -> bool {
-        Path::new(self.queue_dir()).exists()
-    }
-
-    /// Name of the user that owns the notification queue.
-    fn user(self) -> &'static str {
-        match self {
-            Self::Pve => "www-data",
-            Self::Pbs => "backup",
-        }
-    }
-
-    /// Name of the group that owns the notification queue.
-    fn group(self) -> &'static str {
-        match self {
-            Self::Pve => "www-data",
-            Self::Pbs => "backup",
-        }
-    }
-
-    /// Look up the ID of the user that owns the notification queue.
-    fn uid(self) -> Result<Uid, Error> {
-        let user = self.user();
-
-        let uid = User::from_name(user)
-            .with_context(|| format!("could not look up username {user}"))?
-            .with_context(|| format!("user {user} does not exist"))?
-            .uid;
-
-        Ok(uid)
-    }
-
-    /// Look up the ID of the group that owns the notification queue.
-    fn gid(self) -> Result<Gid, Error> {
-        let group = self.group();
-
-        let gid = Group::from_name(group)
-            .with_context(|| format!("could not look up group {group}"))?
-            .with_context(|| format!("group {group} does not exist"))?
-            .gid;
-
-        Ok(gid)
-    }
-}
-
 /// Maximum number of bytes read from stdin, as a safeguard against excessively large mails.
 const MAX_MAIL_SIZE: u64 = 1024 * 1024;
 
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox-mail-forward v2 62/63] add pve-notify-worker crate and package
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (60 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox-mail-forward v2 61/63] add crate for code shared between the mail-forwarder and the worker Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18  9:43 ` [PATCH proxmox-mail-forward v2 63/63] debian: add versioned break for pve-manager and proxmox-backup-server Lukas Wagner
  2026-11-18 21:44 ` [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Thomas Lamprecht
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

This new daemon hosts the notification worker task from proxmox-notify
for Proxmox VE. It processes PVE's notification queue at
/var/lib/pve-manager/notifications/queue, including mails submitted by
the mail forwarder, and is meant to be pulled in as a service
dependency by pve-manager.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 Cargo.toml                          |  6 +++
 Makefile                            | 12 ++++--
 debian/control                      |  7 ++++
 debian/proxmox-mail-forward.install |  1 +
 debian/pve-notify-worker.install    |  1 +
 debian/pve-notify-worker.service    | 13 ++++++
 debian/rules                        |  2 +-
 pve-notify-worker/Cargo.toml        | 21 ++++++++++
 pve-notify-worker/src/main.rs       | 64 +++++++++++++++++++++++++++++
 9 files changed, 122 insertions(+), 5 deletions(-)
 create mode 100644 debian/proxmox-mail-forward.install
 create mode 100644 debian/pve-notify-worker.install
 create mode 100644 debian/pve-notify-worker.service
 create mode 100644 pve-notify-worker/Cargo.toml
 create mode 100644 pve-notify-worker/src/main.rs

diff --git a/Cargo.toml b/Cargo.toml
index 27e4d8e..59e94c0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -2,6 +2,7 @@
 members = [
     "common",
     "proxmox-mail-forward",
+    "pve-notify-worker",
 ]
 resolver = "3"
 
@@ -18,8 +19,13 @@ homepage = "https://www.proxmox.com"
 
 [workspace.dependencies]
 anyhow = "1.0"
+futures = "0.3"
 nix = "0.29"
+tokio = "1.6"
+tracing = "0.1"
 
+proxmox-async = "0.5"
+proxmox-daemon = "1"
 proxmox-log = "1"
 proxmox-notify = "2"
 proxmox-sys = "1"
diff --git a/Makefile b/Makefile
index 0c7dc72..384037a 100644
--- a/Makefile
+++ b/Makefile
@@ -8,8 +8,10 @@ BUILDDIR ?= $(PACKAGE)-$(DEB_VERSION)
 DSC=rust-$(PACKAGE)_$(DEB_VERSION_UPSTREAM).dsc
 DEB=$(PACKAGE)_$(DEB_VERSION)_$(DEB_HOST_ARCH).deb
 DBG_DEB=$(PACKAGE)-dbgsym_$(DEB_VERSION)_$(DEB_HOST_ARCH).deb
+WORKER_DEB=pve-notify-worker_$(DEB_VERSION)_$(DEB_HOST_ARCH).deb
+WORKER_DBG_DEB=pve-notify-worker-dbgsym_$(DEB_VERSION)_$(DEB_HOST_ARCH).deb
 
-DEBS=$(DEB) $(DBG_DEB)
+DEBS=$(DEB) $(DBG_DEB) $(WORKER_DEB) $(WORKER_DBG_DEB)
 
 ifeq ($(BUILD_MODE), release)
 CARGO_BUILD_ARGS += --release --target $(DEB_HOST_RUST_TYPE)
@@ -22,7 +24,7 @@ CARGO ?= cargo
 
 $(BUILDDIR):
 	rm -rf $@ $@.tmp && mkdir $@.tmp
-	cp -a debian Cargo.toml common proxmox-mail-forward Makefile .cargo $@.tmp
+	cp -a debian Cargo.toml common proxmox-mail-forward pve-notify-worker Makefile .cargo $@.tmp
 	rm -f $@.tmp/Cargo.lock
 	find $@.tmp/debian -name "*.hint" -delete
 	mv $@.tmp $@
@@ -50,11 +52,13 @@ dinstall: $(DEBS)
 .PHONY: cargo-build
 cargo-build:
 	$(CARGO) build $(CARGO_BUILD_ARGS) \
-	    --package proxmox-mail-forward
+	    --package proxmox-mail-forward \
+	    --package pve-notify-worker
 
 install: cargo-build
-	install -d $(DESTDIR)/usr/libexec
+	install -d $(DESTDIR)/usr/libexec/proxmox
 	install -m 0755 $(COMPILEDIR)/proxmox-mail-forward $(DESTDIR)/usr/libexec/
+	install -m 0755 $(COMPILEDIR)/pve-notify-worker $(DESTDIR)/usr/libexec/proxmox/
 
 .PHONY: upload
 upload: $(DEBS)
diff --git a/debian/control b/debian/control
index ebf96e1..3e574b7 100644
--- a/debian/control
+++ b/debian/control
@@ -30,3 +30,10 @@ Depends: ${misc:Depends}, ${shlibs:Depends},
 Description: Proxmox mail forward helper
  This package contains the Proxmox mail forward helper. It forwards mails to
  the address(es) of the root@pam user in Proxmox Backup Server and Proxmox VE.
+
+Package: pve-notify-worker
+Architecture: any
+Depends: ${misc:Depends}, ${shlibs:Depends},
+Description: Proxmox VE notification worker
+ This package contains the worker that processes the notification queue of
+ Proxmox VE.
diff --git a/debian/proxmox-mail-forward.install b/debian/proxmox-mail-forward.install
new file mode 100644
index 0000000..1b08c0b
--- /dev/null
+++ b/debian/proxmox-mail-forward.install
@@ -0,0 +1 @@
+usr/libexec/proxmox-mail-forward
diff --git a/debian/pve-notify-worker.install b/debian/pve-notify-worker.install
new file mode 100644
index 0000000..abdcdf7
--- /dev/null
+++ b/debian/pve-notify-worker.install
@@ -0,0 +1 @@
+usr/libexec/proxmox/pve-notify-worker
diff --git a/debian/pve-notify-worker.service b/debian/pve-notify-worker.service
new file mode 100644
index 0000000..dccbb61
--- /dev/null
+++ b/debian/pve-notify-worker.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=Proxmox VE notification worker
+Wants=network-online.target
+After=network-online.target
+
+[Service]
+Type=exec
+ExecStart=/usr/libexec/proxmox/pve-notify-worker
+KillSignal=SIGINT
+Restart=on-failure
+
+[Install]
+WantedBy=multi-user.target
diff --git a/debian/rules b/debian/rules
index ddde12f..2049ba3 100755
--- a/debian/rules
+++ b/debian/rules
@@ -25,7 +25,7 @@ override_dh_auto_configure:
 	$(CARGO) prepare-debian $(CURDIR)/debian/cargo_registry --link-from-system
 	dh_auto_configure
 
-execute_after_dh_auto_install:
+execute_after_dh_install:
 	chmod u+s debian/proxmox-mail-forward/usr/libexec/proxmox-mail-forward
 
 override_dh_fixperms:
diff --git a/pve-notify-worker/Cargo.toml b/pve-notify-worker/Cargo.toml
new file mode 100644
index 0000000..61738e9
--- /dev/null
+++ b/pve-notify-worker/Cargo.toml
@@ -0,0 +1,21 @@
+[package]
+name = "pve-notify-worker"
+description = "Proxmox VE notification worker"
+version.workspace = true
+authors.workspace = true
+edition.workspace = true
+license.workspace = true
+homepage.workspace = true
+
+[dependencies]
+anyhow.workspace = true
+futures.workspace = true
+tokio = { workspace = true, features = [ "full" ] }
+tracing.workspace = true
+
+common.workspace = true
+
+proxmox-async.workspace = true
+proxmox-daemon.workspace = true
+proxmox-log.workspace = true
+proxmox-notify = { workspace = true, features = [ "send-impl", "queue-worker", "pve-context", "legacy-matchers" ]}
diff --git a/pve-notify-worker/src/main.rs b/pve-notify-worker/src/main.rs
new file mode 100644
index 0000000..5f13b25
--- /dev/null
+++ b/pve-notify-worker/src/main.rs
@@ -0,0 +1,64 @@
+//! This binary hosts the notification worker for PVE.
+//!
+//! When sending a notification, it is written as a JSON file into the queue directory at
+//! `/var/lib/pve-manager/notifications/queue`.
+//!
+//! The notification worker will periodically read the contents of the queue directory and process
+//! any notification that was put there.
+//!
+//! The worker task was implemented in such a way that it tries to finish sending the currently
+//! handled notification in case of a requested daemon shutdown. If there are multiple
+//! notifications in the queue, they are handled one-by-one, giving ample opportunities for
+//! a clean shutdown.
+
+#![deny(unsafe_code)]
+#![deny(missing_docs)]
+
+use std::time::Duration;
+
+use anyhow::{Context, Error};
+use tracing::level_filters::LevelFilter;
+
+use proxmox_notify::context::pve::PVEContext;
+use proxmox_notify::queue::{QueueConsumer, QueueWorker};
+
+use common::Product;
+
+fn main() -> Result<(), Error> {
+    proxmox_log::Logger::from_env("PVE_LOG", LevelFilter::INFO)
+        .journald()
+        .init()?;
+
+    proxmox_async::runtime::main(run())
+}
+
+async fn run() -> Result<(), Error> {
+    let signal_task = proxmox_daemon::shutdown_signal_task().context("unable to start daemon")?;
+    tokio::task::spawn(signal_task);
+
+    tracing::info!("PVE notification worker starting up");
+
+    start_notification_worker().await?;
+
+    tracing::info!("PVE notification worker shutting down");
+
+    Ok(())
+}
+
+/// Start the notification worker task
+async fn start_notification_worker() -> Result<(), Error> {
+    let consumer = QueueConsumer::new(Product::Pve.queue_dir());
+
+    let notification_worker = std::pin::pin!(
+        QueueWorker::builder(proxmox_notify::Context::new(PVEContext), consumer)
+            .interval(Duration::from_secs(5))
+            .retry_attempts(2)
+            .build()
+            .run()
+    );
+
+    let abort_future = std::pin::pin!(proxmox_daemon::shutdown_future());
+    futures::future::select(notification_worker, abort_future).await;
+
+    Ok(())
+}
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH proxmox-mail-forward v2 63/63] debian: add versioned break for pve-manager and proxmox-backup-server
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (61 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox-mail-forward v2 62/63] add pve-notify-worker crate and package Lukas Wagner
@ 2026-11-18  9:43 ` Lukas Wagner
  2026-11-18 21:44 ` [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Thomas Lamprecht
  63 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-18  9:43 UTC (permalink / raw)
  To: pve-devel

In order for mail forwarding to work, either pve-manager or
proxmox-backup-server must be recent enough to process its notification
queue, which for pve-manager means pulling in pve-notify-worker as a
service dependency.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---

Notes:
    TODO: MAINTAINERS: Please fix up the version

 debian/control | 1 +
 1 file changed, 1 insertion(+)

diff --git a/debian/control b/debian/control
index 3e574b7..a6ac7a8 100644
--- a/debian/control
+++ b/debian/control
@@ -27,6 +27,7 @@ Rules-Requires-Root: binary-targets
 Package: proxmox-mail-forward
 Architecture: any
 Depends: ${misc:Depends}, ${shlibs:Depends},
+Breaks: pve-manager (<< 9.2.30), proxmox-backup-server (<< 4.2.12-1)
 Description: Proxmox mail forward helper
  This package contains the Proxmox mail forward helper. It forwards mails to
  the address(es) of the root@pam user in Proxmox Backup Server and Proxmox VE.
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 66+ messages in thread

* Re: [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker
  2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
                   ` (62 preceding siblings ...)
  2026-11-18  9:43 ` [PATCH proxmox-mail-forward v2 63/63] debian: add versioned break for pve-manager and proxmox-backup-server Lukas Wagner
@ 2026-11-18 21:44 ` Thomas Lamprecht
  2026-11-19 10:45   ` Lukas Wagner
  63 siblings, 1 reply; 66+ messages in thread
From: Thomas Lamprecht @ 2026-11-18 21:44 UTC (permalink / raw)
  To: pve-devel, Lukas Wagner

On Wed, 18 Nov 2026 10:42:44 +0100, Lukas Wagner wrote:
> The notification stack will soon be integrated into a new product (PDM), so it
> makes sense to use this opportunity for any pending breaking changes and
> general cleanup of the notification stack, partly driven by the worker
> implementation, pending feature work (notification history), and overdue
> maintenance work to reduce technical debt.
> 
> The introduction of a shared worker implementation lifts long-standing limitations in PVE,
> where only the privileged process could send notifications. The worker will also be used
> in PDM.
> 
> [...]

Applied with some changes on top, thanks!

Folded in, besides typos and docs:
- worker: notifications failing validation, symlinks and other entries
  that cannot be opened are marked broken instead of being requeued
  forever; other read errors after a claim requeue instead of using up
  an attempt.
- moved patch 29 "notify: forwarded mails: don't hardcode severity and
  metadata fields" before patch 28 "notify: fold mail-forwarder feature
  into send-impl", so the default feature build works at each commit.
- mail-forward: worker unit ordered after pve-cluster,
  build-dependencies, and the worker package now ships the queue dir
  tmpfiles entry. dpkg configures it before pve-manager, so the worker
  started without its queue; patch 53 "debian: create notification queue
  directory via tmpfiles" got dropped. The worker is uploaded to the PVE
  repo only.
- PBS: patch 47 "api: notification: send test notification via
  proxmox_notify::send" squashed into patch 46 "notifications: adapt to
  proxmox-notify API changes", so the latter builds on its own; the
  multi-line inline tables in Cargo.toml are single-line again, as they
  need TOML 1.1.

Separate commits:
- notify: no config read while pmxcfs is not mounted; queue files are
  0640 and owned by the submitter, and the queue dir is expected to be
  3770, so submitters cannot change or remove each other's notifications
  (the worker checks the setup at startup); warning if the queue stays
  locked for five minutes; IDs queued twice are left alone; receipts
  record 'mailto' for direct email recipients instead of a
  'legacy-sendmail' target name.
- PBS: the queue dir is fixed up through an O_NOFOLLOW handle instead of
  refusing to start; old spool files are only renamed, not read as root.
- pve-cluster: libpve-notify-perl depends on pve-notify-worker.

Left oper open points, input welcome:
- retrying deliveries that reached no target. I had a variant reusing the
  attempt counter, but it seems to fit better with per-target state
  in the notification history, as then one can ensure nothing gets
  submitted multiple times for each specific target.
- the PVE queue path is defined in pve-rs, mail-forward and the worker;
  moving PVEContext and the path into a PVE crate would give one source.
- the PBS queue sits below the backup-owned state dir, so the backup
  user can still replace it.
- patch 56 "services: request pve-notify-worker.service via Wants" has
  no rationale; what does the extra Wants= guard against?
- mail-forward treats stdin I/O errors like an oversized mail and
  bounces it.
- a pve-docs counterpart for the PBS docs change would be nice

[manager] applied to pve-manager.git (master)
[52/63] vzdump: send legacy-sendmail notifications via simplified API
        https://git.proxmox.com/?p=pve-manager.git;a=commitdiff;h=ba8dd37eb7012ad837dba1831da23e964ee71d63
[53/63] debian: create notification queue directory via tmpfiles
        (no commit info)
[54/63] debian: add 'pve-notify-worker' as dependecy
        https://git.proxmox.com/?p=pve-manager.git;a=commitdiff;h=fe4f131c084a0e077a55678ca1929b1d236db709
[55/63] api: services: add 'pve-notify-worker' as known service
        https://git.proxmox.com/?p=pve-manager.git;a=commitdiff;h=7f87d76b293ecd20ba983e43ac41cd941eb9d9fd
[56/63] services: request pve-notify-worker.service via Wants
        https://git.proxmox.com/?p=pve-manager.git;a=commitdiff;h=618c236fb407d6204980197f8eb0d9d31d2dab5e

[proxmox] applied to git/proxmox.git (master)
[01/63] notify: disallow `unsafe` code
        commit: 8c715db3a42b1ef996784dfbcfde326a5d9a0116
[02/63] notify: refactor error type
        commit: c00b7d2b001af30ed00ab78e6646cb4dab26f104
[03/63] notify: move `Endpoint` trait to endpoint module as pub(crate)
        commit: 089c815ba6d7ce2c4ac516d2f73c5b3905a71260
[04/63] notify: use ConfigDigest instead of raw byte arrays
        commit: f37cfe258c2e741f4936d437c233ff2b95e3ab7f
[05/63] notify: remove static context and pass context as parameter
        commit: 3066b4436db4198445785b733cd3e77c9944381b
[06/63] notify: matcher: drop unused field matcher verifiers
        commit: a9c8845e2b4eb307ec528087909df2098541ed68
[07/63] notify: introduce 'send-impl', 'api-impl' and 'api-types' features
        commit: c0d14243fe83f18c8dadf22638daf304ea5a2a16
[08/63] notify: matcher: make matcher validation methods public
        commit: ed684af62fa34af8e49a10086349e62550a0f258
[09/63] notify: matcher: stub CalendarMatcher::matches on wasm32
        commit: a7ea27438b0d1246db109663c45549a926f16051
[10/63] notify: make SendmailEndpoint and SmtpEndpoint private types
        commit: cafaa7ad378188ee03ef3e8c4fadd1c31867dbe5
[11/63] notify: move `send`, `test_target` and `Bus` to new `send` module
        commit: 172e40456be2b21534458c4ce262746bb915b45d
[12/63] notify: move Origin type to api_types module
        commit: 6664b447f484c6608d536874deceff9d4a4e903b
[13/63] notify: move Target type to api_types module
        commit: 2dcca96b0f2e19518f1baa8b84d680a28b638d22
[14/63] notify: move Config to config module
        commit: 39cda59d301b16b6d5cb2fac3cf1fcd3bb925256
[15/63] notify: move Notification and sub-types to `notification` module
        commit: 66edfc9b337737f7add3ea1c24de43319586d816
[16/63] notify: move schema module to api_types
        commit: b9837a3f02c1055dacd5e0b1d7e9922cc7a026be
[17/63] notify: move check_matches from api_types::matcher to send::Bus
        commit: d6973a53b8737978b88bf2f6fb5f6a6fd3aeb0e3
[18/63] notify: move TemplateSource to context module
        commit: bc95b07be0bde600bb14defa75a7142820da3537
[19/63] notify: config: cleanup helper names and visibility
        commit: ef6e079d1d45896ed05ec37b51dac5aadf1a7eb3
[20/63] notify: config: rename section config parser/writer methods
        commit: bd240427b97f3a00e4feda3e1c6f1fbe15c6e322
[21/63] notify: config: pass builtins explicitly when parsing section config
        commit: 13c6f06ca0ae481c900f8c11c4260386201e0182
[22/63] notify: implement PartialEq for all Config types
        commit: b59510fda0ce184d784d805004ebd8e84a49f15f
[23/63] notify: use typed SectionConfigData
        commit: 79b95f7c2b5236080571bf64e8a318b894de88c7
[24/63] notify: api: api types: rename Deleteable* -> Deletable*
        commit: 57ad72daa24afbfcc55e36b512f91011a1087891
[25/63] notify: context: parse builtin config only once
        commit: a9e5bbd91d2a589495fe7d2e9941de1f19b00954
[26/63] notify: context: parse proxy config in trait impl, not at the callsite
        commit: 7fd90635ff9faea47c83be0ec689ab6c7d2c90f4
[27/63] notify: gate sub-modules with the appropriate feature flags
        commit: f7acb38a5cd670b7b1082804698dcd85d9476c32
[28/63] notify: fold mail-forwarder feature into send-impl
        commit: 824ef061666dc4195767cc1940ce6b31dc6ab1b5
[29/63] notify: forwarded mails: don't hardcode severity and metadata fields
        commit: f2974ff716e747e6244108c8355086380ed81979
[30/63] notify: don't pass uid when instantiating forwarded mail notifications
        commit: c9d7c57fbe391830f0aa0cb38d15e5e964862c1f
[31/63] notify: derive PartialEq for Notification type
        commit: 0c274f85220420233f6e608a61ab9c4090c3e227
[32/63] notify: add getters for severity and fields on Notification type
        commit: b57e80c53db004d10ffdbdbf119b7fb2034f8e71
[33/63] notify: add test suite for Notification type
        commit: 38c1bd5e53ad83df709dd7bced3458cee43faf49
[34/63] notify: serialize raw, forwarded mail content as base64
        commit: 19a994bc1205396f083796648602f8439b6f4907
[35/63] notify: unify code paths for legacy-sendmail and regular notifications
        commit: 3e18e96b828aa8a902d2bde0fec9edd97a794649
[36/63] notify: add backwards-compat note to Notification type
        commit: 7022cbe018a0459e3957d2a11203272d9c6ad379
[37/63] notify: remove 'test_target' API
        commit: 516c605451b3b5e9f3230da90517aba5e5d7d494
[38/63] notify: replace notification instantiation with builder pattern
        commit: 6e286d32db7ee38ee4365176d9854a8c2f807407
[39/63] notify: add send receipts
        commit: 8025ce40838af5f56e4867952ba047250fe3e8a7
[40/63] notify: make sure that template name matches SAFE_ID_REGEX
        commit: 5faae51b5308233eed41bca8a18ad9e58116ac90
[41/63] notify: implement notification queue submitter
        commit: b6f89f791e5fdeb94b5befc4d56ac90342870602
[42/63] notify: context: add read_config
        commit: 464812a29f6b703a82379e4a2379d024effe7a10
[43/63] notify: queue: add queue consumer
        commit: 08eb1922dbe279d83852176eeed805034e8ec47d
[44/63] notify: queue: add worker task
        commit: fe26fe0c48363c5a04ef89ee35e849223d4b6ada

[proxmox-backup] applied to git/proxmox-backup.git (master)
[45/63] notifications: don't ignore verification errors in legacy-sendmail mode
        commit: 958e6202a0c343e63be1abe0f50539b86101fadd
[46/63] notifications: adapt to proxmox-notify API changes
        commit: 02abfc8befa4ea5a9e98d18fd8b69b47a6a66fd3
[47/63] api: notification: send test notification via proxmox_notify::send
        commit: 02abfc8befa4ea5a9e98d18fd8b69b47a6a66fd3
[48/63] notifications: send all notifications via proxmox-notify's queue
        commit: 91aa31f58030821c2e05ca941f9e88fec88d2285

[proxmox-mail-forward] applied to git/proxmox-mail-forward.git (master)
[57/63] forward mails via notification queue
        commit: 6e4876c2dd62554c93de66d597ebac4ea527b5b1
[58/63] use return code to signal permanent or temporary failure
        commit: 509984db02d6bed09a740393a9fd9c8ad112f726
[59/63] limit size of mail read from stdin
        commit: c3bf1e9bbbbe6331d26316b028a068a8bcd64d81
[60/63] cargo: move mail forwarder into a workspace member crate
        commit: b49a21da57d748e1405f554eaccf7162b47e5cd3
[61/63] add crate for code shared between the mail-forwarder and the worker
        commit: e1cf6b27c439de75b3d8a894c6fad5f6fed11d35
[62/63] add pve-notify-worker crate and package
        commit: 2b269c9e8c7b1e35fba6bb183587ceec0a2f3806
[63/63] debian: add versioned break for pve-manager and proxmox-backup-server
        commit: 095d3c6668af9a4f67e562f213c193f1186ee7c4

[proxmox-perl-rs] applied to git/proxmox-perl-rs.git (master)
[49/63] pve: notify: adapt to changes in the public API of proxmox-notify
        commit: 0c51204db2bb0b53e3739acf40f4e22069e5eba8
[50/63] pve: notify: add `PVE::RS::Notify::enqueue` method
        commit: 3e40d44a4cdd18b45293dfeffd5d3f7356376716

[pve-cluster] applied to pve-cluster.git (master)
[51/63] notify: send notifications via notification queue
        https://git.proxmox.com/?p=pve-cluster.git;a=commitdiff;h=1a192374cc1f7d63f22e1bace700ea575d367f7b




^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker
  2026-11-18 21:44 ` [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Thomas Lamprecht
@ 2026-11-19 10:45   ` Lukas Wagner
  0 siblings, 0 replies; 66+ messages in thread
From: Lukas Wagner @ 2026-11-19 10:45 UTC (permalink / raw)
  To: Thomas Lamprecht, pve-devel, Lukas Wagner

On Wed Nov 18, 2026 at 10:44 PM CET, Thomas Lamprecht wrote:
> Folded in, besides typos and docs:
> - worker: notifications failing validation, symlinks and other entries
>   that cannot be opened are marked broken instead of being requeued
>   forever; other read errors after a claim requeue instead of using up
>   an attempt.
> - moved patch 29 "notify: forwarded mails: don't hardcode severity and
>   metadata fields" before patch 28 "notify: fold mail-forwarder feature
>   into send-impl", so the default feature build works at each commit.
> - mail-forward: worker unit ordered after pve-cluster,
>   build-dependencies, and the worker package now ships the queue dir
>   tmpfiles entry. dpkg configures it before pve-manager, so the worker
>   started without its queue; patch 53 "debian: create notification queue
>   directory via tmpfiles" got dropped. The worker is uploaded to the PVE
>   repo only.
> - PBS: patch 47 "api: notification: send test notification via
>   proxmox_notify::send" squashed into patch 46 "notifications: adapt to
>   proxmox-notify API changes", so the latter builds on its own; the
>   multi-line inline tables in Cargo.toml are single-line again, as they
>   need TOML 1.1.
>
> Separate commits:
> - notify: no config read while pmxcfs is not mounted; queue files are
>   0640 and owned by the submitter, and the queue dir is expected to be
>   3770, so submitters cannot change or remove each other's notifications
>   (the worker checks the setup at startup); warning if the queue stays
>   locked for five minutes; IDs queued twice are left alone; receipts
>   record 'mailto' for direct email recipients instead of a
>   'legacy-sendmail' target name.
> - PBS: the queue dir is fixed up through an O_NOFOLLOW handle instead of
>   refusing to start; old spool files are only renamed, not read as root.
> - pve-cluster: libpve-notify-perl depends on pve-notify-worker.

Checked your changes with `git range-diff`, looks good as far as I can
tell.
>
> Left oper open points, input welcome:
> - retrying deliveries that reached no target. I had a variant reusing the
>   attempt counter, but it seems to fit better with per-target state
>   in the notification history, as then one can ensure nothing gets
>   submitted multiple times for each specific target.

Yup, considered this as well when implementing, but given that there is
a queued item per notification and not per target, we need the history
to implement a proper per-target retry logic.

> - the PVE queue path is defined in pve-rs, mail-forward and the worker;
>   moving PVEContext and the path into a PVE crate would give one source.

Yes, at some point {PVE,PBS}Context should be moved out from
`proxmox-notify`. For PBS it would already be possible, but I refrained
from doing so for now. Given that a Rust-API server is at least
something we are thinking about, this was one of the reasons why
pve-notify-worker initially lived in the pve-manager repo; then the
PVEContext trait could simply live there as well.

> - the PBS queue sits below the backup-owned state dir, so the backup
>   user can still replace it.

Yes, would probably make sense to change the ownership.

> - patch 56 "services: request pve-notify-worker.service via Wants" has
>   no rationale; what does the extra Wants= guard against?

Probably a left-over from then the notify worker still created the queue
on startup, instead of the queue being created via tmpfiles. 
As otherwise a queuing a notification right after daemon
startup could fail. We can probably drop the Wants= now.

> - mail-forward treats stdin I/O errors like an oversized mail and
>   bounces it.

Might send a followup for this; but I don't think this would ever be an
issue in practice.

> - a pve-docs counterpart for the PBS docs change would be nice

Sent a patch for pve-docs:

https://lore.proxmox.com/all/20261119100743.238781-1-l.wagner@proxmox.com/T/#u

Took your patch for PBS and extended it; will add the extended section
to PBS when I have the time.





^ permalink raw reply	[flat|nested] 66+ messages in thread

end of thread, other threads:[~2026-11-19 10:45 UTC | newest]

Thread overview: 66+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18  9:42 [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
2026-11-18  9:42 ` [PATCH proxmox v2 01/63] notify: disallow `unsafe` code Lukas Wagner
2026-11-18  9:42 ` [PATCH proxmox v2 02/63] notify: refactor error type Lukas Wagner
2026-11-18  9:42 ` [PATCH proxmox v2 03/63] notify: move `Endpoint` trait to endpoint module as pub(crate) Lukas Wagner
2026-11-18  9:42 ` [PATCH proxmox v2 04/63] notify: use ConfigDigest instead of raw byte arrays Lukas Wagner
2026-11-18  9:42 ` [PATCH proxmox v2 05/63] notify: remove static context and pass context as parameter Lukas Wagner
2026-11-18  9:42 ` [PATCH proxmox v2 06/63] notify: matcher: drop unused field matcher verifiers Lukas Wagner
2026-11-18  9:42 ` [PATCH proxmox v2 07/63] notify: introduce 'send-impl', 'api-impl' and 'api-types' features Lukas Wagner
2026-11-18  9:42 ` [PATCH proxmox v2 08/63] notify: matcher: make matcher validation methods public Lukas Wagner
2026-11-18  9:42 ` [PATCH proxmox v2 09/63] notify: matcher: stub CalendarMatcher::matches on wasm32 Lukas Wagner
2026-11-18  9:42 ` [PATCH proxmox v2 10/63] notify: make SendmailEndpoint and SmtpEndpoint private types Lukas Wagner
2026-11-18  9:42 ` [PATCH proxmox v2 11/63] notify: move `send`, `test_target` and `Bus` to new `send` module Lukas Wagner
2026-11-18  9:42 ` [PATCH proxmox v2 12/63] notify: move Origin type to api_types module Lukas Wagner
2026-11-18  9:42 ` [PATCH proxmox v2 13/63] notify: move Target " Lukas Wagner
2026-11-18  9:42 ` [PATCH proxmox v2 14/63] notify: move Config to config module Lukas Wagner
2026-11-18  9:42 ` [PATCH proxmox v2 15/63] notify: move Notification and sub-types to `notification` module Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 16/63] notify: move schema module to api_types Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 17/63] notify: move check_matches from api_types::matcher to send::Bus Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 18/63] notify: move TemplateSource to context module Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 19/63] notify: config: cleanup helper names and visibility Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 20/63] notify: config: rename section config parser/writer methods Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 21/63] notify: config: pass builtins explicitly when parsing section config Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 22/63] notify: implement PartialEq for all Config types Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 23/63] notify: use typed SectionConfigData Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 24/63] notify: api: api types: rename Deleteable* -> Deletable* Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 25/63] notify: context: parse builtin config only once Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 26/63] notify: context: parse proxy config in trait impl, not at the callsite Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 27/63] notify: gate sub-modules with the appropriate feature flags Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 28/63] notify: fold mail-forwarder feature into send-impl Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 29/63] notify: forwarded mails: don't hardcode severity and metadata fields Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 30/63] notify: don't pass uid when instantiating forwarded mail notifications Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 31/63] notify: derive PartialEq for Notification type Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 32/63] notify: add getters for severity and fields on " Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 33/63] notify: add test suite for " Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 34/63] notify: serialize raw, forwarded mail content as base64 Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 35/63] notify: unify code paths for legacy-sendmail and regular notifications Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 36/63] notify: add backwards-compat note to Notification type Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 37/63] notify: remove 'test_target' API Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 38/63] notify: replace notification instantiation with builder pattern Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 39/63] notify: add send receipts Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 40/63] notify: make sure that template name matches SAFE_ID_REGEX Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 41/63] notify: implement notification queue submitter Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 42/63] notify: context: add read_config Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 43/63] notify: queue: add queue consumer Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox v2 44/63] notify: queue: add worker task Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox-backup v2 45/63] notifications: don't ignore verification errors in legacy-sendmail mode Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox-backup v2 46/63] notifications: adapt to proxmox-notify API changes Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox-backup v2 47/63] api: notification: send test notification via proxmox_notify::send Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox-backup v2 48/63] notifications: send all notifications via proxmox-notify's queue Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox-perl-rs v2 49/63] pve: notify: adapt to changes in the public API of proxmox-notify Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox-perl-rs v2 50/63] pve: notify: add `PVE::RS::Notify::enqueue` method Lukas Wagner
2026-11-18  9:43 ` [PATCH pve-cluster v2 51/63] notify: send notifications via notification queue Lukas Wagner
2026-11-18  9:43 ` [PATCH manager v2 52/63] vzdump: send legacy-sendmail notifications via simplified API Lukas Wagner
2026-11-18  9:43 ` [PATCH manager v2 53/63] debian: create notification queue directory via tmpfiles Lukas Wagner
2026-11-18  9:43 ` [PATCH manager v2 54/63] debian: add 'pve-notify-worker' as dependecy Lukas Wagner
2026-11-18  9:43 ` [PATCH manager v2 55/63] api: services: add 'pve-notify-worker' as known service Lukas Wagner
2026-11-18  9:43 ` [PATCH manager v2 56/63] services: request pve-notify-worker.service via Wants Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox-mail-forward v2 57/63] forward mails via notification queue Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox-mail-forward v2 58/63] use return code to signal permanent or temporary failure Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox-mail-forward v2 59/63] limit size of mail read from stdin Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox-mail-forward v2 60/63] cargo: move mail forwarder into a workspace member crate Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox-mail-forward v2 61/63] add crate for code shared between the mail-forwarder and the worker Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox-mail-forward v2 62/63] add pve-notify-worker crate and package Lukas Wagner
2026-11-18  9:43 ` [PATCH proxmox-mail-forward v2 63/63] debian: add versioned break for pve-manager and proxmox-backup-server Lukas Wagner
2026-11-18 21:44 ` [PATCH many v2 00/63] notify: maintenance, PDM preparations, queue + worker Thomas Lamprecht
2026-11-19 10:45   ` Lukas Wagner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal