* [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker
@ 2026-11-13 15:07 Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 01/55] notify: disallow `unsafe` code Lukas Wagner
` (56 more replies)
0 siblings, 57 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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.
## 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 (part of pve-manager) 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 might need *some* dependency on pve-notify-worker,
otherwise notifications might be deferred or dropped if proxmox-mail-forward is
updated, but the worker for the queue is not installed or running yet. In PBS,
the regular proxmox-backup-server packages houses the worker, so there we'd
have a circular dependecy, which is of course also bad.
Not sure what the best approach here is, I'm happy for any suggestions.
proxmox:
Lukas Wagner (42):
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: 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 helpers 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: 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 | 72 +-
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 | 197 ++---
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 | 25 +-
.../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 | 427 ++++++----
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 | 165 ++++
proxmox-notify/src/lib.rs | 754 +-----------------
proxmox-notify/src/notification.rs | 423 ++++++++++
proxmox-notify/src/queue/consumer.rs | 418 ++++++++++
proxmox-notify/src/queue/mod.rs | 29 +
proxmox-notify/src/queue/submitter.rs | 59 ++
proxmox-notify/src/queue/worker.rs | 638 +++++++++++++++
proxmox-notify/src/renderer/mod.rs | 44 +-
proxmox-notify/src/send.rs | 487 +++++++++++
.../testdata/notifications-priv.cfg.ref | 8 +
proxmox-notify/testdata/notifications.cfg.ref | 29 +
44 files changed, 4245 insertions(+), 2228 deletions(-)
create mode 100644 proxmox-notify/src/api_types/gotify.rs
rename proxmox-notify/src/{ => api_types}/matcher/calendar.rs (82%)
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 | 582 ++++++++----------
20 files changed, 409 insertions(+), 424 deletions(-)
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 (3):
vzdump: send legacy-sendmail notifications via simplified API
pve-notify-worker: add new rust-based notification worker daemon
debian: add 'pve-notify-worker' as a dependency
PVE/VZDump.pm | 28 +-
debian/control | 1 +
rust/.cargo/config.toml | 5 +
rust/.gitignore | 11 +
rust/Cargo.toml | 47 ++
rust/LICENSE | 661 ++++++++++++++++++
rust/Makefile | 118 ++++
rust/debian/changelog | 6 +
rust/debian/control | 36 +
rust/debian/copyright | 19 +
rust/debian/docs | 1 +
rust/debian/pve-notify-worker.service | 17 +
rust/debian/pve-notify-worker.tmpfiles | 3 +
rust/debian/rules | 45 ++
.../scripts/elf-strip-unused-dependencies.sh | 20 +
rust/debian/source/format | 1 +
rust/debian/source/lintian-overrides | 0
rust/defines.mk | 14 +
rust/lib/pve-buildcfg/Cargo.toml | 9 +
rust/lib/pve-buildcfg/build.rs | 17 +
rust/lib/pve-buildcfg/src/lib.rs | 37 +
rust/pve-notify-worker/Cargo.toml | 24 +
rust/pve-notify-worker/src/main.rs | 69 ++
rust/rustfmt.toml | 2 +
24 files changed, 1165 insertions(+), 26 deletions(-)
create mode 100644 rust/.cargo/config.toml
create mode 100644 rust/.gitignore
create mode 100644 rust/Cargo.toml
create mode 100644 rust/LICENSE
create mode 100644 rust/Makefile
create mode 100644 rust/debian/changelog
create mode 100644 rust/debian/control
create mode 100644 rust/debian/copyright
create mode 100644 rust/debian/docs
create mode 100644 rust/debian/pve-notify-worker.service
create mode 100644 rust/debian/pve-notify-worker.tmpfiles
create mode 100755 rust/debian/rules
create mode 100755 rust/debian/scripts/elf-strip-unused-dependencies.sh
create mode 100644 rust/debian/source/format
create mode 100644 rust/debian/source/lintian-overrides
create mode 100644 rust/defines.mk
create mode 100644 rust/lib/pve-buildcfg/Cargo.toml
create mode 100644 rust/lib/pve-buildcfg/build.rs
create mode 100644 rust/lib/pve-buildcfg/src/lib.rs
create mode 100644 rust/pve-notify-worker/Cargo.toml
create mode 100644 rust/pve-notify-worker/src/main.rs
create mode 100644 rust/rustfmt.toml
proxmox-mail-forward:
Lukas Wagner (3):
forward mails via notification queue
use return code to signal permanent or temporary failure
limit size of mail read from stdin
Cargo.toml | 5 +-
src/main.rs | 315 +++++++++++++++++++++++++++++++++++-----------------
2 files changed, 217 insertions(+), 103 deletions(-)
Summary over all repositories:
95 files changed, 6231 insertions(+), 2875 deletions(-)
--
Generated by murpp 0.12.1
^ permalink raw reply [flat|nested] 58+ messages in thread
* [PATCH proxmox 01/55] notify: disallow `unsafe` code
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 02/55] notify: refactor error type Lukas Wagner
` (55 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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] 58+ messages in thread
* [PATCH proxmox 02/55] notify: refactor error type
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 01/55] notify: disallow `unsafe` code Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 03/55] notify: move `Endpoint` trait to endpoint module as pub(crate) Lukas Wagner
` (54 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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(¬ification)?;
+ let request = endpoint.build_request(¬ification).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(¬ification)?;
} 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] 58+ messages in thread
* [PATCH proxmox 03/55] notify: move `Endpoint` trait to endpoint module as pub(crate)
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 01/55] notify: disallow `unsafe` code Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 02/55] notify: refactor error type Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 04/55] notify: use ConfigDigest instead of raw byte arrays Lukas Wagner
` (53 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 UTC (permalink / raw)
To: pve-devel
This trait better lives 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] 58+ messages in thread
* [PATCH proxmox 04/55] notify: use ConfigDigest instead of raw byte arrays
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (2 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 03/55] notify: move `Endpoint` trait to endpoint module as pub(crate) Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 05/55] notify: remove static context and pass context as parameter Lukas Wagner
` (52 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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>
---
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, 63 insertions(+), 49 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..bd73eac65 100644
--- a/proxmox-notify/src/api/mod.rs
+++ b/proxmox-notify/src/api/mod.rs
@@ -1,5 +1,6 @@
use std::collections::HashSet;
+use proxmox_config_digest::ConfigDigest;
use serde::{Deserialize, Serialize};
use proxmox_http_error::HttpError;
@@ -132,14 +133,14 @@ 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."
- );
- }
+fn verify_digest(config: &Config, digest: Option<ConfigDigest>) -> Result<(), HttpError> {
+ if let Some(digest) = digest
+ && config.digest != digest
+ {
+ http_bail!(
+ BAD_REQUEST,
+ "detected modified configuration - file changed by other user? Try again."
+ );
}
Ok(())
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] 58+ messages in thread
* [PATCH proxmox 05/55] notify: remove static context and pass context as parameter
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (3 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 04/55] notify: use ConfigDigest instead of raw byte arrays Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 06/55] notify: matcher: drop unused field matcher verifiers Lukas Wagner
` (51 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 UTC (permalink / raw)
To: pve-devel
Having static state in library code is not really a great practice for
various reasons, such as a 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
is a preparation to 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 bd73eac65..0ae71acfe 100644
--- a/proxmox-notify/src/api/mod.rs
+++ b/proxmox-notify/src/api/mod.rs
@@ -291,11 +291,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 ¬ification.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 ¬ification.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 ¬ification.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(¬ification).unwrap();
+ let context = test::test_context();
+
+ let request = endpoint.build_request(&context, ¬ification).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(¬ification)?;
+ endpoint.send(context, ¬ification)?;
} 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(¬ification);
+ bus.send(&context, ¬ification);
};
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] 58+ messages in thread
* [PATCH proxmox 06/55] notify: matcher: drop unused field matcher verifiers
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (4 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 05/55] notify: remove static context and pass context as parameter Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 07/55] notify: introduce 'send-impl', 'api-impl' and 'api-types' features Lukas Wagner
` (50 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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] 58+ messages in thread
* [PATCH proxmox 07/55] notify: introduce 'send-impl', 'api-impl' and 'api-types' features
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (5 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 06/55] notify: matcher: drop unused field matcher verifiers Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 08/55] notify: matcher: make matcher validation methods public Lukas Wagner
` (49 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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 0ae71acfe..0dbb15b91 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,
@@ -146,26 +134,11 @@ fn verify_digest(config: &Config, digest: Option<ConfigDigest>) -> Result<(), Ht
Ok(())
}
-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")
@@ -264,7 +237,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,
@@ -283,7 +255,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(())
@@ -300,12 +271,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..48193ff3c
--- /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..d30f1dfee
--- /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 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>,
+}
diff --git a/proxmox-notify/src/api_types/webhook.rs b/proxmox-notify/src/api_types/webhook.rs
new file mode 100644
index 000000000..ad65f617e
--- /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 ¬ification.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] 58+ messages in thread
* [PATCH proxmox 08/55] notify: matcher: make matcher validation methods public
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (6 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 07/55] notify: introduce 'send-impl', 'api-impl' and 'api-types' features Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 09/55] notify: make SendmailEndpoint and SmtpEndpoint private types Lukas Wagner
` (48 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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] 58+ messages in thread
* [PATCH proxmox 09/55] notify: make SendmailEndpoint and SmtpEndpoint private types
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (7 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 08/55] notify: matcher: make matcher validation methods public Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 10/55] notify: move `send`, `test_target` and `Bus` to new `send` module Lukas Wagner
` (47 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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] 58+ messages in thread
* [PATCH proxmox 10/55] notify: move `send`, `test_target` and `Bus` to new `send` module
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (8 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 09/55] notify: make SendmailEndpoint and SmtpEndpoint private types Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 11/55] notify: move Origin type to api_types module Lukas Wagner
` (46 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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 | 392 +++++++++++++++++++++++++++++++
3 files changed, 397 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, ¬ification)?;
- } 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, ¬ification);
- };
-
- 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..5dbf600df
--- /dev/null
+++ b/proxmox-notify/src/send.rs
@@ -0,0 +1,392 @@
+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::gotify::GotifyEndpoint;
+use crate::endpoints::sendmail::SendmailEndpoint;
+use crate::endpoints::smtp::SmtpEndpoint;
+use crate::endpoints::webhook::WebhookEndpoint;
+use crate::{Config, Content, Context, Endpoint, 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, ¬ification)?;
+ } 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, ¬ification);
+ };
+
+ 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] 58+ messages in thread
* [PATCH proxmox 11/55] notify: move Origin type to api_types module
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (9 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 10/55] notify: move `send`, `test_target` and `Bus` to new `send` module Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 12/55] notify: move Target " Lukas Wagner
` (45 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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 0dbb15b91..8bd5633da 100644
--- a/proxmox-notify/src/api/mod.rs
+++ b/proxmox-notify/src/api/mod.rs
@@ -6,7 +6,8 @@ use serde::{Deserialize, Serialize};
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 48193ff3c..cefdefe02 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 d30f1dfee..cc19bd7a1 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 ad65f617e..7e49188b7 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] 58+ messages in thread
* [PATCH proxmox 12/55] notify: move Target type to api_types module
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (10 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 11/55] notify: move Origin type to api_types module Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 13/55] notify: move Config to config module Lukas Wagner
` (44 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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 8bd5633da..44d3bb163 100644
--- a/proxmox-notify/src/api/mod.rs
+++ b/proxmox-notify/src/api/mod.rs
@@ -4,10 +4,9 @@ use proxmox_config_digest::ConfigDigest;
use serde::{Deserialize, Serialize};
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] 58+ messages in thread
* [PATCH proxmox 13/55] notify: move Config to config module
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (11 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 12/55] notify: move Target " Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 14/55] notify: move Notification and sub-types to `notification` module Lukas Wagner
` (43 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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/mod.rs | 2 +-
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 +----------------------------
8 files changed, 114 insertions(+), 117 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/mod.rs b/proxmox-notify/src/api/mod.rs
index 44d3bb163..bdbecf741 100644
--- a/proxmox-notify/src/api/mod.rs
+++ b/proxmox-notify/src/api/mod.rs
@@ -88,7 +88,7 @@ pub fn get_targets(config: &Config) -> Result<Vec<Target>, HttpError> {
fn verify_digest(config: &Config, digest: Option<ConfigDigest>) -> Result<(), HttpError> {
if let Some(digest) = digest
- && config.digest != digest
+ && config.digest() != &digest
{
http_bail!(
BAD_REQUEST,
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] 58+ messages in thread
* [PATCH proxmox 14/55] notify: move Notification and sub-types to `notification` module
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (12 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 13/55] notify: move Config to config module Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 15/55] notify: move schema module to api_types Lukas Wagner
` (42 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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] 58+ messages in thread
* [PATCH proxmox 15/55] notify: move schema module to api_types
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (13 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 14/55] notify: move Notification and sub-types to `notification` module Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 16/55] notify: move check_matches from api_types::matcher to send::Bus Lukas Wagner
` (41 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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 cefdefe02..a75589a35 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 cc19bd7a1..26e82ca3d 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 7e49188b7..94bc1e854 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] 58+ messages in thread
* [PATCH proxmox 16/55] notify: move check_matches from api_types::matcher to send::Bus
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (14 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 15/55] notify: move schema module to api_types Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 17/55] notify: move TemplateSource to context module Lukas Wagner
` (40 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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 5dbf600df..a96b838df 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;
@@ -186,7 +186,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) {
@@ -240,6 +240,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] 58+ messages in thread
* [PATCH proxmox 17/55] notify: move TemplateSource to context module
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (15 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 16/55] notify: move check_matches from api_types::matcher to send::Bus Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 18/55] notify: config: cleanup helpers names and visibility Lukas Wagner
` (39 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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] 58+ messages in thread
* [PATCH proxmox 18/55] notify: config: cleanup helpers names and visibility
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (16 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 17/55] notify: move TemplateSource to context module Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 19/55] notify: config: rename section config parser/writer methods Lukas Wagner
` (38 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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] 58+ messages in thread
* [PATCH proxmox 19/55] notify: config: rename section config parser/writer methods
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (17 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 18/55] notify: config: cleanup helpers names and visibility Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 20/55] notify: config: pass builtins explicitly when parsing section config Lukas Wagner
` (37 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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 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 bdbecf741..398f2c824 100644
--- a/proxmox-notify/src/api/mod.rs
+++ b/proxmox-notify/src/api/mod.rs
@@ -232,7 +232,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] 58+ messages in thread
* [PATCH proxmox 20/55] notify: config: pass builtins explicitly when parsing section config
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (18 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 19/55] notify: config: rename section config parser/writer methods Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 21/55] notify: implement PartialEq for all Config types Lukas Wagner
` (36 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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 398f2c824..b5b05e86f 100644
--- a/proxmox-notify/src/api/mod.rs
+++ b/proxmox-notify/src/api/mod.rs
@@ -227,12 +227,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] 58+ messages in thread
* [PATCH proxmox 21/55] notify: implement PartialEq for all Config types
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (19 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 20/55] notify: config: pass builtins explicitly when parsing section config Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 22/55] notify: use typed SectionConfigData Lukas Wagner
` (35 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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 a75589a35..a9338f38d 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 0a8d31e7a..738b14cf8 100644
--- a/proxmox-notify/src/api_types/matcher/calendar.rs
+++ b/proxmox-notify/src/api_types/matcher/calendar.rs
@@ -44,11 +44,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,
@@ -81,7 +88,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 26e82ca3d..dd779434d 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 Sendmail notification endpoints
pub struct SmtpConfig {
diff --git a/proxmox-notify/src/api_types/webhook.rs b/proxmox-notify/src/api_types/webhook.rs
index 94bc1e854..3fefcfa69 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] 58+ messages in thread
* [PATCH proxmox 22/55] notify: use typed SectionConfigData
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (20 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 21/55] notify: implement PartialEq for all Config types Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 23/55] notify: api: api types: rename Deleteable* -> Deletable* Lukas Wagner
` (34 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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>
---
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 | 41 +-
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 | 393 +++++++++++-------
proxmox-notify/src/send.rs | 183 ++++----
.../testdata/notifications-priv.cfg.ref | 8 +
proxmox-notify/testdata/notifications.cfg.ref | 29 ++
11 files changed, 540 insertions(+), 563 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 b5b05e86f..5232098b4 100644
--- a/proxmox-notify/src/api/mod.rs
+++ b/proxmox-notify/src/api/mod.rs
@@ -1,12 +1,11 @@
use std::collections::HashSet;
use proxmox_config_digest::ConfigDigest;
-use serde::{Deserialize, Serialize};
-
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;
@@ -124,7 +123,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"
@@ -147,14 +146,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");
@@ -202,29 +198,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..406d3cb53 100644
--- a/proxmox-notify/src/config.rs
+++ b/proxmox-notify/src/config.rs
@@ -1,138 +1,43 @@
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::{ApiType, api};
+use proxmox_section_config::typed::{ApiSectionDataEntry, SectionConfigData};
+use proxmox_section_config::{SectionConfig, SectionConfigPlugin};
+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,
+ MatcherConfig, Origin, SENDMAIL_TYPENAME, SMTP_TYPENAME, SendmailConfig, SmtpConfig,
+ SmtpPrivateConfig, WEBHOOK_TYPENAME, 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 +46,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 +90,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 +140,168 @@ impl Config {
&self.digest
}
}
+
+#[api]
+/// 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 ApiSectionDataEntry for ConfigEntity {
+ const INTERNALLY_TAGGED: Option<&'static str> = Some("type");
+
+ /// Get the `SectionConfig` configuration for this enum.
+ fn section_config() -> &'static SectionConfig {
+ static CONFIG: OnceLock<SectionConfig> = OnceLock::new();
+
+ CONFIG.get_or_init(|| {
+ let mut this = SectionConfig::new(&BACKEND_NAME_SCHEMA).with_type_key("type");
+ this.register_plugin(SectionConfigPlugin::new(
+ SENDMAIL_TYPENAME.into(),
+ Some("name".to_string()),
+ SendmailConfig::API_SCHEMA.unwrap_object_schema(),
+ ));
+ this.register_plugin(SectionConfigPlugin::new(
+ MATCHER_TYPENAME.into(),
+ Some("name".to_string()),
+ MatcherConfig::API_SCHEMA.unwrap_object_schema(),
+ ));
+ this.register_plugin(SectionConfigPlugin::new(
+ SMTP_TYPENAME.into(),
+ Some("name".to_string()),
+ SmtpConfig::API_SCHEMA.unwrap_object_schema(),
+ ));
+ this.register_plugin(SectionConfigPlugin::new(
+ GOTIFY_TYPENAME.into(),
+ Some("name".to_string()),
+ GotifyConfig::API_SCHEMA.unwrap_object_schema(),
+ ));
+ this.register_plugin(SectionConfigPlugin::new(
+ WEBHOOK_TYPENAME.into(),
+ Some("name".to_string()),
+ WebhookConfig::API_SCHEMA.unwrap_object_schema(),
+ ));
+ this
+ })
+ }
+
+ /// Maps an enum value to its type name.
+ fn section_type(&self) -> &'static str {
+ match self {
+ ConfigEntity::Sendmail(_) => "sendmail",
+ ConfigEntity::Gotify(_) => "gotify",
+ ConfigEntity::Smtp(_) => "smtp",
+ ConfigEntity::Webhook(_) => "webhook",
+ ConfigEntity::Matcher(_) => "matcher",
+ }
+ }
+}
+
+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]
+/// 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),
+}
+
+impl ApiSectionDataEntry for PrivateConfigEntity {
+ const INTERNALLY_TAGGED: Option<&'static str> = Some("type");
+
+ /// Get the `SectionConfig` configuration for this enum.
+ fn section_config() -> &'static SectionConfig {
+ static CONFIG: OnceLock<SectionConfig> = OnceLock::new();
+
+ CONFIG.get_or_init(|| {
+ let mut this = SectionConfig::new(&BACKEND_NAME_SCHEMA).with_type_key("type");
+ this.register_plugin(SectionConfigPlugin::new(
+ SMTP_TYPENAME.into(),
+ Some("name".to_string()),
+ SmtpPrivateConfig::API_SCHEMA.unwrap_object_schema(),
+ ));
+ this.register_plugin(SectionConfigPlugin::new(
+ GOTIFY_TYPENAME.into(),
+ Some("name".to_string()),
+ GotifyPrivateConfig::API_SCHEMA.unwrap_object_schema(),
+ ));
+ this.register_plugin(SectionConfigPlugin::new(
+ WEBHOOK_TYPENAME.into(),
+ Some("name".to_string()),
+ WebhookPrivateConfig::API_SCHEMA.unwrap_object_schema(),
+ ));
+ this
+ })
+ }
+
+ /// Maps an enum value to its type name.
+ fn section_type(&self) -> &'static str {
+ match self {
+ PrivateConfigEntity::Gotify(_) => "gotify",
+ PrivateConfigEntity::Smtp(_) => "smtp",
+ PrivateConfigEntity::Webhook(_) => "webhook",
+ }
+ }
+}
+
+#[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 a96b838df..210a42599 100644
--- a/proxmox-notify/src/send.rs
+++ b/proxmox-notify/src/send.rs
@@ -1,20 +1,18 @@
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;
use crate::endpoints::smtp::SmtpEndpoint;
use crate::endpoints::webhook::WebhookEndpoint;
-use crate::{Config, Content, Context, Endpoint, Error, Metadata, Notification, Severity};
+use crate::{Config, Content, Context, Error, Metadata, Notification, Severity};
/// Send a notification to a given target.
///
@@ -47,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 {
@@ -112,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] 58+ messages in thread
* [PATCH proxmox 23/55] notify: api: api types: rename Deleteable* -> Deletable*
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (21 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 22/55] notify: use typed SectionConfigData Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 24/55] notify: context: parse builtin config only once Lukas Wagner
` (33 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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 a9338f38d..e55e98aec 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 dd779434d..4b1e0b261 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 3fefcfa69..afd08c38d 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] 58+ messages in thread
* [PATCH proxmox 24/55] notify: context: parse builtin config only once
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (22 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 23/55] notify: api: api types: rename Deleteable* -> Deletable* Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 25/55] notify: context: parse proxy config in trait impl, not at the callsite Lukas Wagner
` (32 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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] 58+ messages in thread
* [PATCH proxmox 25/55] notify: context: parse proxy config in trait impl, not at the callsite
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (23 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 24/55] notify: context: parse builtin config only once Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 26/55] notify: gate sub-modules with the appropriate feature flags Lukas Wagner
` (31 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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] 58+ messages in thread
* [PATCH proxmox 26/55] notify: gate sub-modules with the appropriate feature flags
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (24 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 25/55] notify: context: parse proxy config in trait impl, not at the callsite Lukas Wagner
@ 2026-11-13 15:07 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 27/55] notify: fold mail-forwarder feature into send-impl Lukas Wagner
` (30 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:07 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] 58+ messages in thread
* [PATCH proxmox 27/55] notify: fold mail-forwarder feature into send-impl
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (25 preceding siblings ...)
2026-11-13 15:07 ` [PATCH proxmox 26/55] notify: gate sub-modules with the appropriate feature flags Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 28/55] notify: forwarded mails: don't hardcode severity and metadata fields Lukas Wagner
` (29 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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] 58+ messages in thread
* [PATCH proxmox 28/55] notify: forwarded mails: don't hardcode severity and metadata fields
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (26 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox 27/55] notify: fold mail-forwarder feature into send-impl Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 29/55] notify: don't pass uid when instantiating forwarded mail notifications Lukas Wagner
` (28 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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] 58+ messages in thread
* [PATCH proxmox 29/55] notify: don't pass uid when instantiating forwarded mail notifications
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (27 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox 28/55] notify: forwarded mails: don't hardcode severity and metadata fields Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 30/55] notify: derive PartialEq for Notification type Lukas Wagner
` (27 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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), back then the fix was to
pass the real uid when spawning the sendmail process. This is now 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] 58+ messages in thread
* [PATCH proxmox 30/55] notify: derive PartialEq for Notification type
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (28 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox 29/55] notify: don't pass uid when instantiating forwarded mail notifications Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 31/55] notify: add getters for severity and fields on " Lukas Wagner
` (26 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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] 58+ messages in thread
* [PATCH proxmox 31/55] notify: add getters for severity and fields on Notification type
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (29 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox 30/55] notify: derive PartialEq for Notification type Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 32/55] notify: add test suite for " Lukas Wagner
` (25 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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] 58+ messages in thread
* [PATCH proxmox 32/55] notify: add test suite for Notification type
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (30 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox 31/55] notify: add getters for severity and fields on " Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 33/55] notify: serialize raw, forwarded mail content as base64 Lukas Wagner
` (24 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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(¬ification).unwrap();
+ let deserialized: Notification = serde_json::from_str(&serialized).unwrap();
+ assert_eq!(deserialized, notification);
+ }
+ }
+}
--
2.47.3
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH proxmox 33/55] notify: serialize raw, forwarded mail content as base64
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (31 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox 32/55] notify: add test suite for " Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 34/55] notify: unify code paths for legacy-sendmail and regular notifications Lukas Wagner
` (23 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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] 58+ messages in thread
* [PATCH proxmox 34/55] notify: unify code paths for legacy-sendmail and regular notifications
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (32 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox 33/55] notify: serialize raw, forwarded mail content as base64 Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 35/55] notify: add backwards-compat note to Notification type Lukas Wagner
` (22 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 UTC (permalink / raw)
To: pve-devel
In the future, we will introduce a per-product notification queue and
notification history. Given these changed semantics, its 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 used 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..e8af6f655 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 reciepient 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] 58+ messages in thread
* [PATCH proxmox 35/55] notify: add backwards-compat note to Notification type
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (33 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox 34/55] notify: unify code paths for legacy-sendmail and regular notifications Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 36/55] notify: remove 'test_target' API Lukas Wagner
` (21 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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 e8af6f655..88940bcf5 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] 58+ messages in thread
* [PATCH proxmox 36/55] notify: remove 'test_target' API
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (34 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox 35/55] notify: add backwards-compat note to Notification type Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 37/55] notify: replace notification instantiation with builder pattern Lukas Wagner
` (20 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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 | 57 +++++++++++++++++++++++++++++++++++
proxmox-notify/src/lib.rs | 2 +-
proxmox-notify/src/send.rs | 47 ++---------------------------
3 files changed, 60 insertions(+), 46 deletions(-)
diff --git a/proxmox-notify/src/api/mod.rs b/proxmox-notify/src/api/mod.rs
index 5232098b4..66659ee21 100644
--- a/proxmox-notify/src/api/mod.rs
+++ b/proxmox-notify/src/api/mod.rs
@@ -85,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> {
if let Some(digest) = digest
&& config.digest() != &digest
@@ -325,4 +353,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, ¬ification)?;
- } 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] 58+ messages in thread
* [PATCH proxmox 37/55] notify: replace notification instantiation with builder pattern
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (35 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox 36/55] notify: remove 'test_target' API Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 38/55] notify: add send receipts Lukas Wagner
` (19 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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/notification.rs | 169 +++++++++++++-----
proxmox-notify/src/send.rs | 20 +--
7 files changed, 167 insertions(+), 85 deletions(-)
diff --git a/proxmox-notify/src/api_types/matcher/calendar.rs b/proxmox-notify/src/api_types/matcher/calendar.rs
index 738b14cf8..25109cd83 100644
--- a/proxmox-notify/src/api_types/matcher/calendar.rs
+++ b/proxmox-notify/src/api_types/matcher/calendar.rs
@@ -140,8 +140,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(¬ification).unwrap());
@@ -249,17 +252,23 @@ pub mod inline {
assert!(matcher.matches(¬ification).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(¬ification).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(¬ification).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(¬ification).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/notification.rs b/proxmox-notify/src/notification.rs
index 88940bcf5..41667ef44 100644
--- a/proxmox-notify/src/notification.rs
+++ b/proxmox-notify/src/notification.rs
@@ -133,42 +133,36 @@ 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::other_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 +196,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 +302,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 +335,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 +400,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, ¬ification);
};
--
2.47.3
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH proxmox 38/55] notify: add send receipts
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (36 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox 37/55] notify: replace notification instantiation with builder pattern Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 39/55] notify: implement notification queue submitter Lukas Wagner
` (18 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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(¬ification).unwrap().is_some())
+ assert!(config.matches(¬ification).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] 58+ messages in thread
* [PATCH proxmox 39/55] notify: implement notification queue submitter
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (37 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox 38/55] notify: add send receipts Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 40/55] notify: context: add read_config Lukas Wagner
` (17 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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 practices.
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>
---
proxmox-notify/Cargo.toml | 1 +
proxmox-notify/src/lib.rs | 3 ++
proxmox-notify/src/queue/mod.rs | 12 ++++++
proxmox-notify/src/queue/submitter.rs | 59 +++++++++++++++++++++++++++
4 files changed, 75 insertions(+)
create mode 100644 proxmox-notify/src/queue/mod.rs
create mode 100644 proxmox-notify/src/queue/submitter.rs
diff --git a/proxmox-notify/Cargo.toml b/proxmox-notify/Cargo.toml
index e47912d11..a3de1a3fe 100644
--- a/proxmox-notify/Cargo.toml
+++ b/proxmox-notify/Cargo.toml
@@ -78,3 +78,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/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..59d5e12cd
--- /dev/null
+++ b/proxmox-notify/src/queue/mod.rs
@@ -0,0 +1,12 @@
+use std::path::Path;
+
+use crate::Error;
+
+mod submitter;
+pub use submitter::QueueSubmitter;
+
+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::other_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..01d81e959
--- /dev/null
+++ b/proxmox-notify/src/queue/submitter.rs
@@ -0,0 +1,59 @@
+//! Submission of notifications to the queue.
+
+use std::path::PathBuf;
+
+use proxmox_sys::fs::CreateOptions;
+
+use crate::{Error, Notification};
+
+/// 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,
+ )
+ })?;
+
+ proxmox_sys::fs::replace_file(&path, &bytes, self.create_options, true).map_err(|err| {
+ Error::other_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(())
+ }
+}
--
2.47.3
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH proxmox 40/55] notify: context: add read_config
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (38 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox 39/55] notify: implement notification queue submitter Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 41/55] notify: queue: add queue consumer Lukas Wagner
` (16 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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] 58+ messages in thread
* [PATCH proxmox 41/55] notify: queue: add queue consumer
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (39 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox 40/55] notify: context: add read_config Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 42/55] notify: queue: add worker task Lukas Wagner
` (15 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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
sending a notification, 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>
---
Cargo.toml | 1 +
proxmox-notify/Cargo.toml | 4 +
proxmox-notify/src/lib.rs | 2 +-
proxmox-notify/src/queue/consumer.rs | 418 +++++++++++++++++++++++++++
proxmox-notify/src/queue/mod.rs | 12 +
5 files changed, 436 insertions(+), 1 deletion(-)
create mode 100644 proxmox-notify/src/queue/consumer.rs
diff --git a/Cargo.toml b/Cargo.toml
index ba62378ec..04b535f6d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -142,6 +142,7 @@ serde_regex = "1.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 a3de1a3fe..e08c0f512 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 = []
@@ -79,3 +80,6 @@ pve-context = ["dep:proxmox-sys", "legacy-matchers"]
pbs-context = ["dep:proxmox-sys", "legacy-matchers"]
legacy-matchers = []
queue-submitter = ["dep:proxmox-sys"]
+queue-worker = [
+ "proxmox-sys/timer",
+]
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..2defc0c6d
--- /dev/null
+++ b/proxmox-notify/src/queue/consumer.rs
@@ -0,0 +1,418 @@
+//! Consumer side of the notification queue.
+
+use std::fs::File;
+use std::io;
+use std::path::PathBuf;
+use std::time::Duration;
+
+use crate::{Error, Notification};
+
+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::other_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::other_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::other_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::other_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::other_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::other_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::other_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 Ok(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.
+ pub fn read_notification(&self, queued: &QueuedNotification) -> Result<Notification, Error> {
+ let path = self.queue_dir.join(queued.filename());
+
+ let buf = std::fs::read(path)
+ .map_err(|err| Error::other_with_source("could not read queued notification", err))?;
+
+ let notification = serde_json::from_slice(&buf).map_err(|err| {
+ Error::other_with_source("could not deserialize queued notification", 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) -> Result<Self, Error> {
+ 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>()
+ .map_err(|err| Error::other_with_source("invalid UUID", err))?;
+ let attempt = attempt_str
+ .strip_prefix("attempt-")
+ .ok_or_else(|| Error::other("missing 'attempt-'"))?
+ .parse::<u32>()
+ .map_err(|err| Error::other_with_source("invalid attempt counter", err))?;
+
+ (uuid, Some(attempt))
+ } else {
+ let uuid = s
+ .parse::<Uuid>()
+ .map_err(|err| Error::other_with_source("invalid UUID", err))?;
+
+ (uuid, None)
+ };
+
+ Ok(Self {
+ id: uuid,
+ attempt,
+ filename: filename.to_string(),
+ })
+ } else {
+ Err(Error::other("not a queued notification"))
+ }
+ }
+
+ /// 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(¬ification).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(¬ification).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(¬ification).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(¬ification).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);
+ }
+}
diff --git a/proxmox-notify/src/queue/mod.rs b/proxmox-notify/src/queue/mod.rs
index 59d5e12cd..7d20bd85e 100644
--- a/proxmox-notify/src/queue/mod.rs
+++ b/proxmox-notify/src/queue/mod.rs
@@ -1,10 +1,22 @@
+//! 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;
+
+#[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] 58+ messages in thread
* [PATCH proxmox 42/55] notify: queue: add worker task
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (40 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox 41/55] notify: queue: add queue consumer Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox-backup 43/55] notifications: don't ignore verification errors in legacy-sendmail mode Lukas Wagner
` (14 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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 | 638 +++++++++++++++++++++++++++++
3 files changed, 646 insertions(+)
create mode 100644 proxmox-notify/src/queue/worker.rs
diff --git a/proxmox-notify/Cargo.toml b/proxmox-notify/Cargo.toml
index e08c0f512..d69b48b45 100644
--- a/proxmox-notify/Cargo.toml
+++ b/proxmox-notify/Cargo.toml
@@ -24,6 +24,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"]}
@@ -81,5 +82,7 @@ pbs-context = ["dep:proxmox-sys", "legacy-matchers"]
legacy-matchers = []
queue-submitter = ["dep:proxmox-sys"]
queue-worker = [
+ "dep:tokio",
"proxmox-sys/timer",
+ "send-impl",
]
diff --git a/proxmox-notify/src/queue/mod.rs b/proxmox-notify/src/queue/mod.rs
index 7d20bd85e..7c4c3c434 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};
+
#[cfg(any(feature = "queue-submitter", feature = "queue-worker"))]
fn fsync_queue_dir(queue_dir: &Path) -> Result<(), Error> {
std::fs::File::open(queue_dir)
diff --git a/proxmox-notify/src/queue/worker.rs b/proxmox-notify/src/queue/worker.rs
new file mode 100644
index 000000000..cfaef3c15
--- /dev/null
+++ b/proxmox-notify/src/queue/worker.rs
@@ -0,0 +1,638 @@
+//! 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) => {
+ tracing::error!(
+ "queued notification {id} could not be read, marking as broken: {err}"
+ );
+ queue.mark_broken(queued_notification)?;
+ return Err(err);
+ }
+ };
+
+ tracing::info!("handling notification {}", queued_notification.id());
+
+ match crate::send(&context, &config, ¬ification) {
+ 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(¬ification).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] 58+ messages in thread
* [PATCH proxmox-backup 43/55] notifications: don't ignore verification errors in legacy-sendmail mode
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (41 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox 42/55] notify: queue: add worker task Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox-backup 44/55] notifications: adapt to proxmox-notify API changes Lukas Wagner
` (13 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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] 58+ messages in thread
* [PATCH proxmox-backup 44/55] notifications: adapt to proxmox-notify API changes
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (42 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox-backup 43/55] notifications: don't ignore verification errors in legacy-sendmail mode Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox-backup 45/55] api: notification: send test notification via proxmox_notify::send Lukas Wagner
` (12 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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 119969829..d609e91fb 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, ¬ification) {
+ if let Err(err) = proxmox_notify::send(context, &config, ¬ification) {
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, ¬ification)?;
+ let config = pbs_config::notifications::config(context)?;
+ proxmox_notify::send(context, &config, ¬ification)?;
} else {
let ser = serde_json::to_vec(¬ification)?;
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(¬ification)?;
-
- 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(¬ify).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] 58+ messages in thread
* [PATCH proxmox-backup 45/55] api: notification: send test notification via proxmox_notify::send
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (43 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox-backup 44/55] notifications: adapt to proxmox-notify API changes Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox-backup 46/55] notifications: send all notifications via proxmox-notify's queue Lukas Wagner
` (11 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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, ¬ification)?;
+
+ match receipt
+ .target_receipts()
+ .first()
+ .context("target receipt array did not contain expected entry")?
+ .status()
+ {
+ TargetReceiptStatus::Delivered => Ok(()),
+ TargetReceiptStatus::Error { error_message } => {
+ bail!("could not test target: {error_message}")
+ }
+ TargetReceiptStatus::Disabled => {
+ bail!(
+ "target {name} disabled while sending test notification -- this should not happen"
+ )
+ }
+ }
}
#[sortable]
--
2.47.3
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH proxmox-backup 46/55] notifications: send all notifications via proxmox-notify's queue
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (44 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox-backup 45/55] api: notification: send test notification via proxmox_notify::send Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox-perl-rs 47/55] pve: notify: adapt to changes in the public API of proxmox-notify Lukas Wagner
` (10 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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 that are still in the old spool directory on upgrade
are moved to the new queue when the worker starts.
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
Cargo.toml | 13 ++-
src/bin/proxmox-backup-api.rs | 2 +-
src/server/notifications/mod.rs | 163 ++++++++++++++++----------------
3 files changed, 93 insertions(+), 85 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index d609e91fb..bdffd6ffd 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..525d8e02b 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,101 +39,94 @@ 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, ¬ification) {
- 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);
-
- if let Err(err) = send_queued_notifications().await {
- log::error!("notification worker task error: {err}");
- }
-
- tokio::time::sleep_until(tokio::time::Instant::from_std(delay_target)).await;
+ // At startup, migrate any left-over notifications that weren't delivered
+ // right before the switch to PBS with the newer notification queue/worker.
+ //
+ // FIXME: MAJOR VERSION: Remove
+ if let Err(err) = migrate_leftover_notifications() {
+ log::error!("failed to migrate notifications: {err:#}");
}
+
+ let consumer = QueueConsumer::new(QUEUE_DIR);
+
+ QueueWorker::builder(context().clone(), consumer)
+ .interval(Duration::from_secs(5))
+ .retry_attempts(2)
+ .build()
+ .run()
+ .await;
+}
+
+/// 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)?;
+ let notification: Notification = serde_json::from_slice(&bytes)?;
+
+ // Removing the file from the old spool directory before putting it in the new queue is a
+ // deliberate decision: If, for some reason, the old directory is not writable, we don't
+ // want to continue to migrate the same notification over and over again.
+ std::fs::remove_file(path)?;
+
+ let uuid = notification.id().clone();
+
+ // Put notification into new queue
+ send_notification(notification)?;
+
+ log::info!("moved notification with ID '{uuid}' to new notification queue");
+
+ Ok(())
}
fn send_notification(notification: Notification) -> Result<(), Error> {
- let context = context();
-
- if nix::unistd::ROOT == Uid::current() {
- let config = pbs_config::notifications::config(context)?;
- proxmox_notify::send(context, &config, ¬ification)?;
- } else {
- let ser = serde_json::to_vec(¬ification)?;
- let path = Path::new(SPOOL_DIR).join(format!("{id}.json", id = notification.id()));
-
- 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())
- }
+ let options = proxmox_product_config::default_create_options();
+ let writer = QueueSubmitter::new(QUEUE_DIR, options);
+ writer.submit(¬ification)?;
Ok(())
}
--
2.47.3
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH proxmox-perl-rs 47/55] pve: notify: adapt to changes in the public API of proxmox-notify
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (45 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox-backup 46/55] notifications: send all notifications via proxmox-notify's queue Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox-perl-rs 48/55] pve: notify: add `PVE::RS::Notify::enqueue` method Lukas Wagner
` (9 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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 f22e3ae..f8982e2 100644
--- a/pve-rs/Cargo.toml
+++ b/pve-rs/Cargo.toml
@@ -39,7 +39,7 @@ proxmox-http = { version = "1.0.2", features = ["client-sync", "client-trait"] }
proxmox-http-error = "1"
proxmox-log = "1"
proxmox-network-types = "1.1.2"
-proxmox-notify = { version = "2", features = ["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, ¬ification)
+ 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, ¬ification).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, ¬ification)
+ .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(¬ification)?;
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] 58+ messages in thread
* [PATCH proxmox-perl-rs 48/55] pve: notify: add `PVE::RS::Notify::enqueue` method
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (46 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox-perl-rs 47/55] pve: notify: adapt to changes in the public API of proxmox-notify Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH pve-cluster 49/55] notify: send notifications via notification queue Lukas Wagner
` (8 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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 f8982e2..ed7d0e4 100644
--- a/pve-rs/Cargo.toml
+++ b/pve-rs/Cargo.toml
@@ -39,7 +39,7 @@ proxmox-http = { version = "1.0.2", features = ["client-sync", "client-trait"] }
proxmox-http-error = "1"
proxmox-log = "1"
proxmox-network-types = "1.1.2"
-proxmox-notify = { version = "2", features = [ "api-impl", "legacy-matchers", "pve-context", "send-impl" ] }
+proxmox-notify = { version = "2", features = [ "api-impl", "legacy-matchers", "pve-context", "queue-submitter", "send-impl" ] }
proxmox-oci = "0.2.2"
proxmox-openid = "1.0.2"
proxmox-resource-scheduling = "2"
diff --git a/pve-rs/src/bindings/notify.rs b/pve-rs/src/bindings/notify.rs
index a5faa93..6c494d9 100644
--- a/pve-rs/src/bindings/notify.rs
+++ b/pve-rs/src/bindings/notify.rs
@@ -12,7 +12,9 @@ pub mod pve_rs_notify {
use std::collections::HashMap;
use std::sync::Mutex;
- use anyhow::{Error, bail};
+ use anyhow::{Context, Error, bail};
+ use nix::sys::stat::Mode;
+ use nix::unistd::{Group, User};
use serde_json::{Value as JSONValue, json};
use perlmod::Value;
@@ -25,8 +27,10 @@ pub mod pve_rs_notify {
SendmailConfig, SendmailConfigUpdater, SmtpConfig, SmtpConfigUpdater, SmtpPrivateConfig,
SmtpPrivateConfigUpdater, Target, TargetReceiptStatus, WebhookConfig, WebhookConfigUpdater,
};
- use proxmox_notify::{Config, Notification, Recipient, Severity, api};
+ use proxmox_notify::queue::QueueSubmitter;
+ use proxmox_notify::{Config, EmailRecipient, Notification, Recipient, Severity, api};
use proxmox_notify::{http_bail, http_err};
+ use proxmox_sys::fs::CreateOptions;
/// A notification configuration instance.
///
@@ -557,4 +561,64 @@ pub mod pve_rs_notify {
let config = this.config.lock().unwrap();
api::common::get_referenced_entities(&config, name)
}
+
+ /// Send a notification by submitting it to the product's notification
+ /// queue.
+ ///
+ /// A dedicated worker task (pve-notify-worker) regularly processes any
+ /// queued notification and sends them to the appropriate destinations.
+ ///
+ /// If `recipient` is set, the `recipient` field will be set
+ /// to [`Recipient::Email`] with the provided [`EmailRecipient`]. This is
+ /// to support the old, legacy-sendmail mode also for notifications sent
+ /// through the notification worker.
+ ///
+ /// # Errors
+ ///
+ /// - The notification could not be serialized
+ /// - The serialized notification could not be written to the queue (e.g. permissions of the
+ /// queue directory are set wrong, the directory does not exist, etc.)
+ #[export]
+ pub fn enqueue(
+ severity: Severity,
+ template_name: String,
+ template_data: Option<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(¬ification)?;
+
+ 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] 58+ messages in thread
* [PATCH pve-cluster 49/55] notify: send notifications via notification queue
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (47 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox-perl-rs 48/55] pve: notify: add `PVE::RS::Notify::enqueue` method Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH manager 50/55] vzdump: send legacy-sendmail notifications via simplified API Lukas Wagner
` (7 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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] 58+ messages in thread
* [PATCH manager 50/55] vzdump: send legacy-sendmail notifications via simplified API
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (48 preceding siblings ...)
2026-11-13 15:08 ` [PATCH pve-cluster 49/55] notify: send notifications via notification queue Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH manager 51/55] pve-notify-worker: add new rust-based notification worker daemon Lukas Wagner
` (6 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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 56d2aea3..4137c296 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] 58+ messages in thread
* [PATCH manager 51/55] pve-notify-worker: add new rust-based notification worker daemon
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (49 preceding siblings ...)
2026-11-13 15:08 ` [PATCH manager 50/55] vzdump: send legacy-sendmail notifications via simplified API Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH manager 52/55] debian: add 'pve-notify-worker' as a dependency Lukas Wagner
` (5 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 UTC (permalink / raw)
To: pve-devel
This very lightweight daemon will periodically process queued
notifications from /var/lib/pve-manager/notifications/queue and
send them to their destinations based on the selected recipients.
The actual worker task is implemented in proxmox-notify, making the
product-specific daemon very simple. At some point, the tokio-based
worker could be part of a Rust-based API daemon, but until we have that,
a dedicated process is the best option.
The new daemon is packaged as its own package. Naturally, this could
also be part of the pve-manager package, but a separate package was
easier to set up, since the packaging of an existing project could be
reused and adapted.
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
rust/.cargo/config.toml | 5 +
rust/.gitignore | 11 +
rust/Cargo.toml | 47 ++
rust/LICENSE | 661 ++++++++++++++++++
rust/Makefile | 118 ++++
rust/debian/changelog | 6 +
rust/debian/control | 36 +
rust/debian/copyright | 19 +
rust/debian/docs | 1 +
rust/debian/pve-notify-worker.service | 17 +
rust/debian/pve-notify-worker.tmpfiles | 3 +
rust/debian/rules | 45 ++
.../scripts/elf-strip-unused-dependencies.sh | 20 +
rust/debian/source/format | 1 +
rust/debian/source/lintian-overrides | 0
rust/defines.mk | 14 +
rust/lib/pve-buildcfg/Cargo.toml | 9 +
rust/lib/pve-buildcfg/build.rs | 17 +
rust/lib/pve-buildcfg/src/lib.rs | 37 +
rust/pve-notify-worker/Cargo.toml | 24 +
rust/pve-notify-worker/src/main.rs | 69 ++
rust/rustfmt.toml | 2 +
22 files changed, 1162 insertions(+)
create mode 100644 rust/.cargo/config.toml
create mode 100644 rust/.gitignore
create mode 100644 rust/Cargo.toml
create mode 100644 rust/LICENSE
create mode 100644 rust/Makefile
create mode 100644 rust/debian/changelog
create mode 100644 rust/debian/control
create mode 100644 rust/debian/copyright
create mode 100644 rust/debian/docs
create mode 100644 rust/debian/pve-notify-worker.service
create mode 100644 rust/debian/pve-notify-worker.tmpfiles
create mode 100755 rust/debian/rules
create mode 100755 rust/debian/scripts/elf-strip-unused-dependencies.sh
create mode 100644 rust/debian/source/format
create mode 100644 rust/debian/source/lintian-overrides
create mode 100644 rust/defines.mk
create mode 100644 rust/lib/pve-buildcfg/Cargo.toml
create mode 100644 rust/lib/pve-buildcfg/build.rs
create mode 100644 rust/lib/pve-buildcfg/src/lib.rs
create mode 100644 rust/pve-notify-worker/Cargo.toml
create mode 100644 rust/pve-notify-worker/src/main.rs
create mode 100644 rust/rustfmt.toml
diff --git a/rust/.cargo/config.toml b/rust/.cargo/config.toml
new file mode 100644
index 00000000..3b5b6e48
--- /dev/null
+++ b/rust/.cargo/config.toml
@@ -0,0 +1,5 @@
+[source]
+[source.debian-packages]
+directory = "/usr/share/cargo/registry"
+[source.crates-io]
+replace-with = "debian-packages"
diff --git a/rust/.gitignore b/rust/.gitignore
new file mode 100644
index 00000000..a4e88c52
--- /dev/null
+++ b/rust/.gitignore
@@ -0,0 +1,11 @@
+**/*.rs.bk
+*.build
+*.buildinfo
+*.changes
+*.deb
+*.dsc
+*.tar.?z
+*~
+/target
+Cargo.lock
+pve-notify-worker-[0-9].*/
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
new file mode 100644
index 00000000..f161bbbe
--- /dev/null
+++ b/rust/Cargo.toml
@@ -0,0 +1,47 @@
+[workspace.package]
+version = "1.0.0"
+authors = [
+ "Lukas Wagner <l.wagner@proxmox.com>",
+ "Proxmox Support Team <support@proxmox.com>",
+]
+edition = "2024"
+license = "AGPL-3"
+repository = "https://git.proxmox.com/?p=pve-manager.git"
+
+exclude = [ "build" ]
+
+[workspace]
+resolver = "2"
+members = [
+ "lib/pve-buildcfg",
+ "pve-notify-worker",
+]
+
+[workspace.dependencies]
+# proxmox workspace
+proxmox-async = "0.5"
+proxmox-daemon = "1"
+proxmox-log = "1"
+proxmox-notify = "2"
+proxmox-rest-server = "1"
+proxmox-systemd = "1"
+
+# workspace
+pve-notify-worker = { path = "pve-notify-worker" }
+pve-buildcfg = { path = "lib/pve-buildcfg" }
+
+# regular crates
+anyhow = "1.0"
+futures = "0.3"
+tokio = "1.6"
+tracing = "0.1"
+
+# Local path overrides
+# NOTE: You must run `cargo update` after changing this for it to take effect!
+[patch.crates-io]
+# proxmox-async = { path = "../../proxmox/proxmox-async" }
+# proxmox-daemon = { path = "../../proxmox/proxmox-daemon" }
+# proxmox-lang = { path = "../../proxmox/proxmox-lang" }
+# proxmox-notify = { path = "../../proxmox/proxmox-notify" }
+# proxmox-rest-server = { path = "../../proxmox/proxmox-rest-server" }
+# proxmox-systemd = { path = "../../proxmox/proxmox-systemd" }
diff --git a/rust/LICENSE b/rust/LICENSE
new file mode 100644
index 00000000..be3f7b28
--- /dev/null
+++ b/rust/LICENSE
@@ -0,0 +1,661 @@
+ GNU AFFERO GENERAL PUBLIC LICENSE
+ Version 3, 19 November 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU Affero General Public License is a free, copyleft license for
+software and other kinds of works, specifically designed to ensure
+cooperation with the community in the case of network server software.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+our General Public Licenses are intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ Developers that use our General Public Licenses protect your rights
+with two steps: (1) assert copyright on the software, and (2) offer
+you this License which gives you legal permission to copy, distribute
+and/or modify the software.
+
+ A secondary benefit of defending all users' freedom is that
+improvements made in alternate versions of the program, if they
+receive widespread use, become available for other developers to
+incorporate. Many developers of free software are heartened and
+encouraged by the resulting cooperation. However, in the case of
+software used on network servers, this result may fail to come about.
+The GNU General Public License permits making a modified version and
+letting the public access it on a server without ever releasing its
+source code to the public.
+
+ The GNU Affero General Public License is designed specifically to
+ensure that, in such cases, the modified source code becomes available
+to the community. It requires the operator of a network server to
+provide the source code of the modified version running there to the
+users of that server. Therefore, public use of a modified version, on
+a publicly accessible server, gives the public access to the source
+code of the modified version.
+
+ An older license, called the Affero General Public License and
+published by Affero, was designed to accomplish similar goals. This is
+a different license, not a version of the Affero GPL, but Affero has
+released a new version of the Affero GPL which permits relicensing under
+this license.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU Affero General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Remote Network Interaction; Use with the GNU General Public License.
+
+ Notwithstanding any other provision of this License, if you modify the
+Program, your modified version must prominently offer all users
+interacting with it remotely through a computer network (if your version
+supports such interaction) an opportunity to receive the Corresponding
+Source of your version by providing access to the Corresponding Source
+from a network server at no charge, through some standard or customary
+means of facilitating copying of software. This Corresponding Source
+shall include the Corresponding Source for any work covered by version 3
+of the GNU General Public License that is incorporated pursuant to the
+following paragraph.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the work with which it is combined will remain governed by version
+3 of the GNU General Public License.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU Affero General Public License from time to time. Such new versions
+will be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU Affero General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU Affero General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU Affero General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If your software can interact with users remotely through a computer
+network, you should also make sure that it provides a way for users to
+get its source. For example, if your program is a web application, its
+interface could display a "Source" link that leads users to an archive
+of the code. There are many ways you could offer source, and different
+solutions will be better for different programs; see section 13 for the
+specific requirements.
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU AGPL, see
+<https://www.gnu.org/licenses/>.
diff --git a/rust/Makefile b/rust/Makefile
new file mode 100644
index 00000000..c2508c19
--- /dev/null
+++ b/rust/Makefile
@@ -0,0 +1,118 @@
+include /usr/share/dpkg/default.mk
+include defines.mk
+
+PACKAGE=pve-notify-worker
+CRATENAME=pve-notify-worker
+
+REPO=pve-manager
+
+BUILDDIR ?= $(PACKAGE)-$(DEB_VERSION_UPSTREAM)
+ORIG_SRC_TAR=$(PACKAGE)_$(DEB_VERSION_UPSTREAM).orig.tar.gz
+
+DEB=$(PACKAGE)_$(DEB_VERSION)_$(DEB_HOST_ARCH).deb
+DBG_DEB=$(PACKAGE)-dbgsym_$(DEB_VERSION)_$(DEB_HOST_ARCH).deb
+DSC=$(PACKAGE)_$(DEB_VERSION).dsc
+
+CARGO ?= cargo
+ifeq ($(BUILD_MODE), release)
+CARGO_BUILD_ARGS += --release
+COMPILEDIR := target/release
+else
+COMPILEDIR := target/debug
+endif
+
+DESTDIR =
+
+USR_BIN :=
+
+USR_SBIN :=
+
+SERVICE_BIN := \
+ pve-notify-worker \
+
+# for those binaries that are for internal use and e.g. have no command-line completion
+INTERNAL_SERVICE_BIN :=
+
+COMPILED_BINS := \
+ $(addprefix $(COMPILEDIR)/,$(USR_BIN) $(USR_SBIN) $(SERVICE_BIN) $(INTERNAL_SERVICE_BIN))
+
+tests ?= --workspace
+
+all:
+
+install: $(COMPILED_BINS)
+ install -dm755 $(DESTDIR)$(BINDIR)
+ $(foreach i,$(USR_BIN), \
+ install -m755 $(COMPILEDIR)/$(i) $(DESTDIR)$(BINDIR)/ ;)
+ install -dm755 $(DESTDIR)$(SBINDIR)
+ $(foreach i,$(USR_SBIN), \
+ install -m755 $(COMPILEDIR)/$(i) $(DESTDIR)$(SBINDIR)/ ;)
+ install -dm755 $(DESTDIR)$(LIBEXECDIR)/proxmox
+ $(foreach i,$(SERVICE_BIN) $(INTERNAL_SERVICE_BIN), \
+ install -m755 $(COMPILEDIR)/$(i) $(DESTDIR)$(LIBEXECDIR)/proxmox/ ;)
+ # make -C systemd install
+
+$(COMPILED_BINS) &:
+ $(CARGO) build $(CARGO_BUILD_ARGS)
+
+.PHONY: cargo-build
+cargo-build:
+ $(MAKE) $(COMPILED_BINS)
+
+$(BUILDDIR):
+ rm -rf $@ $@.tmp
+ mkdir $@.tmp
+ cp -a debian/ pve-notify-worker/ lib/ defines.mk Makefile Cargo.toml $@.tmp
+ echo "git clone git://git.proxmox.com/git/$(REPO).git\\ngit checkout $$(git rev-parse HEAD)" \
+ > $@.tmp/debian/SOURCE
+ mv $@.tmp $@
+
+$(ORIG_SRC_TAR): $(BUILDDIR)
+ tar czf $(ORIG_SRC_TAR) --exclude="$(BUILDDIR)/debian" $(BUILDDIR)
+
+.PHONY: deb
+deb: $(DEB)
+
+$(DEB) $(DBG_DEB) &: $(BUILDDIR)
+ cd $(BUILDDIR); dpkg-buildpackage -b -uc -us
+ lintian $(DEB)
+
+.PHONY: dsc
+dsc:
+ rm -rf $(DSC) $(BUILDDIR)
+ $(MAKE) $(DSC)
+ lintian $(DSC)
+
+$(DSC): $(BUILDDIR) $(ORIG_SRC_TAR)
+ cd $(BUILDDIR); dpkg-buildpackage -S -us -uc -d
+
+sbuild: $(DSC)
+ sbuild $(DSC)
+
+.PHONY: upload
+upload: UPLOAD_DIST ?= $(DEB_DISTRIBUTION)
+
+upload: $(DEB) $(DBG_DEB)
+ tar cf - $(DEB) $(DBG_DEB) |ssh -X repoman@repo.proxmox.com -- upload --product pve --dist $(UPLOAD_DIST) --arch $(DEB_HOST_ARCH)
+
+.PHONY: clean clean-deb distclean
+distclean: clean
+clean: clean-deb
+ $(CARGO) clean
+
+clean-deb:
+ rm -rf $(PACKAGE)-[0-9]*/ build/
+ rm -f *.deb *.changes *.dsc *.tar.* *.buildinfo *.build .do-cargo-build
+
+.PHONY: dinstall
+dinstall: deb
+ dpkg -i $(DEB)
+
+.PHONY: test
+test:
+ $(CARGO) test $(tests) $(CARGO_BUILD_ARGS)
+
+.PHONY: tidy
+tidy:
+ $(CARGO) fmt
+
diff --git a/rust/debian/changelog b/rust/debian/changelog
new file mode 100644
index 00000000..883e1596
--- /dev/null
+++ b/rust/debian/changelog
@@ -0,0 +1,6 @@
+pve-notify-worker (1.0.0) trixie; urgency=medium
+
+ * Initial release of the Rust-based notification worker daemon.
+
+ -- Proxmox Support Team <support@proxmox.com> Thu, 02 Jul 2026 11:33:42 +0200
+
diff --git a/rust/debian/control b/rust/debian/control
new file mode 100644
index 00000000..89884d03
--- /dev/null
+++ b/rust/debian/control
@@ -0,0 +1,36 @@
+Source: pve-notify-worker
+Section: admin
+Priority: optional
+Build-Depends: debhelper-compat (= 13),
+ dh-cargo (>= 25),
+ cargo:native,
+ git,
+ librust-anyhow-1+default-dev,
+ librust-futures-0.3+default-dev,
+ librust-proxmox-async-0.5+default-dev,
+ librust-proxmox-daemon-1+default-dev,
+ librust-proxmox-log-1+default-dev,
+ librust-proxmox-rest-server-1+default-dev,
+ librust-proxmox-rest-server-1+templates-dev,
+ librust-proxmox-systemd-1+default-dev,
+ librust-tokio-1+default-dev (>= 1.6-~~),
+ librust-tokio-1+full-dev (>= 1.6-~~),
+ librust-tracing-0.1+default-dev,
+ libstd-rust-dev,
+ libsystemd-dev,
+ rustc:native,
+Maintainer: Proxmox Support Team <support@proxmox.com>
+Standards-Version: 4.6.1
+Vcs-Git: git://git.proxmox.com/git/pve-manager.git
+Vcs-Browser: https://git.proxmox.com/?p=pve-manager.git;a=summary
+Homepage: https://www.proxmox.com
+Rules-Requires-Root: no
+
+Package: pve-notify-worker
+Architecture: any
+Multi-Arch: allowed
+Depends: ${misc:Depends},
+ ${shlibs:Depends},
+Description: Daemon that runs the notification worker task. It will periodically
+ check for any queued notifications and send them to their destinations.
+
diff --git a/rust/debian/copyright b/rust/debian/copyright
new file mode 100644
index 00000000..ab775910
--- /dev/null
+++ b/rust/debian/copyright
@@ -0,0 +1,19 @@
+Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+Source: https://git.proxmox.com/?p=pve-manager.git;a=summary
+
+Files:
+ *
+Copyright: 2026 Proxmox Server Solutions GmbH <support@proxmox.com>
+License: AGPL-3.0-or-later
+ This program is free software: you can redistribute it and/or modify it under
+ the terms of the GNU Affero General Public License as published by the Free
+ Software Foundation, either version 3 of the License, or (at your option) any
+ later version.
+ .
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
+ details.
+ .
+ You should have received a copy of the GNU Affero General Public License along
+ with this program. If not, see <https://www.gnu.org/licenses/>.
diff --git a/rust/debian/docs b/rust/debian/docs
new file mode 100644
index 00000000..86966720
--- /dev/null
+++ b/rust/debian/docs
@@ -0,0 +1 @@
+debian/SOURCE
diff --git a/rust/debian/pve-notify-worker.service b/rust/debian/pve-notify-worker.service
new file mode 100644
index 00000000..cd77e944
--- /dev/null
+++ b/rust/debian/pve-notify-worker.service
@@ -0,0 +1,17 @@
+[Unit]
+Description=Proxmox VE notification daemon
+Wants=pve-cluster.service
+Wants=network-online.target
+After=pve-cluster.service
+After=network-online.target
+
+[Service]
+Type=notify
+ExecStart=/usr/libexec/proxmox/pve-notify-worker
+KillSignal=SIGINT
+PIDFile=/run/pve-notify-worker.pid
+Restart=on-failure
+
+
+[Install]
+WantedBy=multi-user.target
diff --git a/rust/debian/pve-notify-worker.tmpfiles b/rust/debian/pve-notify-worker.tmpfiles
new file mode 100644
index 00000000..0e67a183
--- /dev/null
+++ b/rust/debian/pve-notify-worker.tmpfiles
@@ -0,0 +1,3 @@
+#Type Path Mode User Group Age Argument
+d /var/lib/pve-manager/notifications 0750 root www-data - -
+d /var/lib/pve-manager/notifications/queue 0770 root www-data - -
diff --git a/rust/debian/rules b/rust/debian/rules
new file mode 100755
index 00000000..44537b4a
--- /dev/null
+++ b/rust/debian/rules
@@ -0,0 +1,45 @@
+#!/usr/bin/make -f
+# See debhelper(7) (uncomment to enable)
+# output every command that modifies files on the build system.
+DH_VERBOSE = 1
+
+include /usr/share/dpkg/pkg-info.mk
+include /usr/share/rustc/architecture.mk
+
+export BUILD_MODE=release
+
+CARGO=/usr/share/cargo/bin/cargo
+
+export CFLAGS CXXFLAGS CPPFLAGS LDFLAGS
+export DEB_HOST_RUST_TYPE DEB_HOST_GNU_TYPE
+export CARGO_HOME = $(CURDIR)/debian/cargo_home
+
+export DEB_CARGO_CRATE=pve-notify-worker_$(DEB_VERSION_UPSTREAM)
+export DEB_CARGO_PACKAGE=pve-notify-worker
+
+export DEB_VERSION DEB_VERSION_UPSTREAM
+
+%:
+ dh $@
+
+override_dh_auto_configure:
+ifneq ($(DEB_DISTRIBUTION),UNRELEASED)
+ # Only warn about version mismatches once the new package version is actually released
+ @perl -ne 'if (/^version\s*=\s*"(\d+(?:\.\d+)+)"/) { my $$v_cargo = $$1; my $$v_deb = "$(DEB_VERSION_UPSTREAM)"; \
+ die "ERROR: d/changelog <-> Cargo.toml version mismatch: $$v_cargo != $$v_deb\n" if $$v_cargo ne $$v_deb; exit(0); }' Cargo.toml
+endif
+
+ $(CARGO) prepare-debian $(CURDIR)/debian/cargo_registry --link-from-system
+ dh_auto_configure
+
+override_dh_strip:
+ dh_strip
+ for exe in $$(find \
+ debian/pve-notify-worker/usr \
+ -executable -type f); do \
+ debian/scripts/elf-strip-unused-dependencies.sh "$$exe" || true; \
+ done
+
+override_dh_missing:
+ dh_missing --fail-missing
+
diff --git a/rust/debian/scripts/elf-strip-unused-dependencies.sh b/rust/debian/scripts/elf-strip-unused-dependencies.sh
new file mode 100755
index 00000000..9f89c09c
--- /dev/null
+++ b/rust/debian/scripts/elf-strip-unused-dependencies.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+binary=$1
+
+exec 3< <(ldd -u "$binary" | grep -oP '[^/:]+$')
+
+patchargs=""
+dropped=""
+while read -r dep; do
+ dropped="$dep $dropped"
+ patchargs="--remove-needed $dep $patchargs"
+done <&3
+exec 3<&-
+
+if [[ $dropped == "" ]]; then
+ exit 0
+fi
+
+echo -e "patchelf '$binary' - removing unused dependencies:\n $dropped"
+patchelf $patchargs $binary
diff --git a/rust/debian/source/format b/rust/debian/source/format
new file mode 100644
index 00000000..89ae9db8
--- /dev/null
+++ b/rust/debian/source/format
@@ -0,0 +1 @@
+3.0 (native)
diff --git a/rust/debian/source/lintian-overrides b/rust/debian/source/lintian-overrides
new file mode 100644
index 00000000..e69de29b
diff --git a/rust/defines.mk b/rust/defines.mk
new file mode 100644
index 00000000..529502ca
--- /dev/null
+++ b/rust/defines.mk
@@ -0,0 +1,14 @@
+PREFIX = /usr
+BINDIR = $(PREFIX)/bin
+SBINDIR = $(PREFIX)/sbin
+LIBDIR = $(PREFIX)/lib
+LIBEXECDIR = $(PREFIX)/libexec
+BASHCOMPDIR = $(PREFIX)/share/bash-completion/completions
+ZSHCOMPDIR = $(PREFIX)/share/zsh/vendor-completions
+MAN1DIR = $(PREFIX)/share/man/man1
+MAN5DIR = $(PREFIX)/share/man/man5
+SYSCONFDIR = /etc
+ZSH_COMPL_DEST = $(PREFIX)/share/zsh/vendor-completions
+
+# For local overrides
+-include local.mak
diff --git a/rust/lib/pve-buildcfg/Cargo.toml b/rust/lib/pve-buildcfg/Cargo.toml
new file mode 100644
index 00000000..d13baa0d
--- /dev/null
+++ b/rust/lib/pve-buildcfg/Cargo.toml
@@ -0,0 +1,9 @@
+[package]
+name = "pve-buildcfg"
+version.workspace = true
+authors.workspace = true
+edition.workspace = true
+description = "macros used for PVE related paths such as configdir and rundir"
+build = "build.rs"
+
+[dependencies]
diff --git a/rust/lib/pve-buildcfg/build.rs b/rust/lib/pve-buildcfg/build.rs
new file mode 100644
index 00000000..0be086c0
--- /dev/null
+++ b/rust/lib/pve-buildcfg/build.rs
@@ -0,0 +1,17 @@
+// build.rs
+use std::env;
+use std::process::Command;
+
+fn main() {
+ let repoid = match env::var("REPOID") {
+ Ok(repoid) => repoid,
+ Err(_) => match Command::new("git").args(["rev-parse", "HEAD"]).output() {
+ Ok(output) => String::from_utf8(output.stdout).unwrap(),
+ Err(err) => {
+ panic!("git rev-parse failed: {}", err);
+ }
+ },
+ };
+
+ println!("cargo:rustc-env=REPOID={}", repoid);
+}
diff --git a/rust/lib/pve-buildcfg/src/lib.rs b/rust/lib/pve-buildcfg/src/lib.rs
new file mode 100644
index 00000000..1a5a6cf8
--- /dev/null
+++ b/rust/lib/pve-buildcfg/src/lib.rs
@@ -0,0 +1,37 @@
+//! Exports configuration data from the build system
+
+pub const PROXMOX_PKG_VERSION: &str = concat!(
+ env!("CARGO_PKG_VERSION_MAJOR"),
+ ".",
+ env!("CARGO_PKG_VERSION_MINOR"),
+);
+pub const PROXMOX_PKG_RELEASE: &str = env!("CARGO_PKG_VERSION_PATCH");
+pub const PROXMOX_PKG_REPOID: &str = env!("REPOID");
+
+/// Unix system user used by various unprivileged PVE daemons.
+pub const PVE_UNPRIV_USER: &str = "www-data";
+/// Unix system group used by various unprivileged PVE daemons.
+pub const PVE_UNPRIV_GROUP: &str = "www-data";
+
+/// the PID filename for the notification worker.
+pub const PVE_NOTIFY_WORKER_PID_FILE: &str = "/run/pve-notify-worker.pid";
+
+#[macro_export]
+macro_rules! PVE_MANAGER_STATE_DIR_M {
+ () => {
+ "/var/lib/pve-manager"
+ };
+}
+
+/// Directory for persistent state
+pub const PVE_MANAGER_STATE_DIR: &str = PVE_MANAGER_STATE_DIR_M!();
+
+/// Prepend the state directory to a file name.
+///
+/// This is a simply way to get the full path for files in `/var/lib/`.
+#[macro_export]
+macro_rules! statedir {
+ ($subdir:expr) => {
+ concat!($crate::PVE_MANAGER_STATE_DIR_M!(), $subdir)
+ };
+}
diff --git a/rust/pve-notify-worker/Cargo.toml b/rust/pve-notify-worker/Cargo.toml
new file mode 100644
index 00000000..d773448a
--- /dev/null
+++ b/rust/pve-notify-worker/Cargo.toml
@@ -0,0 +1,24 @@
+[package]
+name = "pve-notify-worker"
+description = "PVE notification worker"
+homepage = "https://www.proxmox.com"
+
+version.workspace = true
+edition.workspace = true
+license.workspace = true
+repository.workspace = true
+
+[dependencies]
+anyhow.workspace = true
+futures.workspace = true
+tokio = { workspace = true, features = [ "full" ] }
+tracing.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" ]}
+proxmox-rest-server.workspace = true
+proxmox-systemd.workspace = true
+
+pve-buildcfg.workspace = true
diff --git a/rust/pve-notify-worker/src/main.rs b/rust/pve-notify-worker/src/main.rs
new file mode 100644
index 00000000..be778d8f
--- /dev/null
+++ b/rust/pve-notify-worker/src/main.rs
@@ -0,0 +1,69 @@
+//! This binary hosts the notification worker for PVE.
+//!
+//! When sending a notification, it is written as a JSON file into a queue directory. For PVE, the
+//! path is 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 pve_buildcfg::statedir;
+
+const QUEUE_DIR: &str = statedir!("/notifications/queue");
+
+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);
+
+ proxmox_rest_server::write_pid(pve_buildcfg::PVE_NOTIFY_WORKER_PID_FILE)?;
+ proxmox_systemd::notify::SystemdNotify::Ready.notify()?;
+
+ 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(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(())
+}
diff --git a/rust/rustfmt.toml b/rust/rustfmt.toml
new file mode 100644
index 00000000..f3e454b6
--- /dev/null
+++ b/rust/rustfmt.toml
@@ -0,0 +1,2 @@
+edition = "2024"
+style_edition = "2024"
--
2.47.3
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH manager 52/55] debian: add 'pve-notify-worker' as a dependency
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (50 preceding siblings ...)
2026-11-13 15:08 ` [PATCH manager 51/55] pve-notify-worker: add new rust-based notification worker daemon Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox-mail-forward 53/55] forward mails via notification queue Lukas Wagner
` (4 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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>
---
Notes:
Technically, it could be more correct to add it as a dep to
libpve-notify-perl, but adding a daemon as a depency to a perl lib felt
quite wrong...
debian/control | 1 +
1 file changed, 1 insertion(+)
diff --git a/debian/control b/debian/control
index e438ce12..cb7e38eb 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.1.13),
--
2.47.3
^ permalink raw reply related [flat|nested] 58+ messages in thread
* [PATCH proxmox-mail-forward 53/55] forward mails via notification queue
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (51 preceding siblings ...)
2026-11-13 15:08 ` [PATCH manager 52/55] debian: add 'pve-notify-worker' as a dependency Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox-mail-forward 54/55] use return code to signal permanent or temporary failure Lukas Wagner
` (3 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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 | 213 +++++++++++++++++++++++++++++-----------------------
2 files changed, 118 insertions(+), 100 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..7599553 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,56 +1,101 @@
//! 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";
+/// Settings needed to submit a notification to a product's queue.
+struct Product {
+ /// Path whose existence indicates that the product is installed.
+ cfg_path: &'static str,
+ /// Base directory of the product's notification queue.
+ notification_state_dir: &'static str,
+ /// User that owns the notification queue.
+ user: &'static str,
+ /// Group that owns the notification queue.
+ group: &'static str,
+}
-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 {
+ /// Look up the ID of the user that owns the notification queue.
+ fn uid(&self) -> Result<Uid, Error> {
+ let user = self.user;
-/// 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
- }
+ 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)
}
}
+/// Supported products, in order of precedence.
+const PRODUCTS: &[Product] = &[
+ Product {
+ cfg_path: "/etc/pve",
+ notification_state_dir: "/var/lib/pve-manager/notifications/queue",
+ user: "www-data",
+ group: "www-data",
+ },
+ Product {
+ cfg_path: "/etc/proxmox-backup",
+ notification_state_dir: "/var/lib/proxmox-backup/notifications/queue",
+ user: "backup",
+ group: "backup",
+ },
+];
+
/// Read data from stdin, until EOF is encountered.
fn read_stdin() -> Result<Vec<u8>, Error> {
let mut input = Vec::new();
@@ -61,55 +106,52 @@ 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<&'static Product, Error> {
+ PRODUCTS
+ .iter()
+ .find(|product| Path::new(product.cfg_path).exists())
+ .context("no supported Proxmox product installed")
+}
- proxmox_notify::api::common::send(config, ¬ification)?;
+/// 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.notification_state_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(¬ification)
+ .context("could not submit mail to notification queue")?;
Ok(())
}
@@ -119,31 +161,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] 58+ messages in thread
* [PATCH proxmox-mail-forward 54/55] use return code to signal permanent or temporary failure
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (52 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox-mail-forward 53/55] forward mails via notification queue Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox-mail-forward 55/55] limit size of mail read from stdin Lukas Wagner
` (2 subsequent siblings)
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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 7599553..1affeda 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:#}"
+ ),
+ }
+ }
+}
+
/// Settings needed to submit a notification to a product's queue.
struct Product {
/// Path whose existence indicates that the product is installed.
@@ -131,11 +163,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(
@@ -147,16 +185,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(¬ification)
- .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()
@@ -165,6 +205,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] 58+ messages in thread
* [PATCH proxmox-mail-forward 55/55] limit size of mail read from stdin
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (53 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox-mail-forward 54/55] use return code to signal permanent or temporary failure Lukas Wagner
@ 2026-11-13 15:08 ` Lukas Wagner
2026-11-17 9:35 ` [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
2026-11-18 9:55 ` superseded: " Lukas Wagner
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-13 15:08 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 1affeda..e4a2f08 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -128,16 +128,33 @@ const PRODUCTS: &[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<&'static Product, Error> {
PRODUCTS
.iter()
@@ -216,3 +233,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] 58+ messages in thread
* Re: [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (54 preceding siblings ...)
2026-11-13 15:08 ` [PATCH proxmox-mail-forward 55/55] limit size of mail read from stdin Lukas Wagner
@ 2026-11-17 9:35 ` Lukas Wagner
2026-11-18 9:55 ` superseded: " Lukas Wagner
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-17 9:35 UTC (permalink / raw)
To: Lukas Wagner, pve-devel
On Fri Nov 13, 2026 at 4:07 PM CET, 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.
>
Will send a v2 soon with a couple of fixes, was made aware of an issue
that must be fixed before applying this.
^ permalink raw reply [flat|nested] 58+ messages in thread
* superseded: [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
` (55 preceding siblings ...)
2026-11-17 9:35 ` [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
@ 2026-11-18 9:55 ` Lukas Wagner
56 siblings, 0 replies; 58+ messages in thread
From: Lukas Wagner @ 2026-11-18 9:55 UTC (permalink / raw)
To: Lukas Wagner, pve-devel
On Fri Nov 13, 2026 at 4:07 PM CET, 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.
superseded:
https://lore.proxmox.com/all/20261118094348.273646-1-l.wagner@proxmox.com/T/#u
^ permalink raw reply [flat|nested] 58+ messages in thread
end of thread, other threads:[~2026-11-18 9:55 UTC | newest]
Thread overview: 58+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13 15:07 [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 01/55] notify: disallow `unsafe` code Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 02/55] notify: refactor error type Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 03/55] notify: move `Endpoint` trait to endpoint module as pub(crate) Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 04/55] notify: use ConfigDigest instead of raw byte arrays Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 05/55] notify: remove static context and pass context as parameter Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 06/55] notify: matcher: drop unused field matcher verifiers Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 07/55] notify: introduce 'send-impl', 'api-impl' and 'api-types' features Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 08/55] notify: matcher: make matcher validation methods public Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 09/55] notify: make SendmailEndpoint and SmtpEndpoint private types Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 10/55] notify: move `send`, `test_target` and `Bus` to new `send` module Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 11/55] notify: move Origin type to api_types module Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 12/55] notify: move Target " Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 13/55] notify: move Config to config module Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 14/55] notify: move Notification and sub-types to `notification` module Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 15/55] notify: move schema module to api_types Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 16/55] notify: move check_matches from api_types::matcher to send::Bus Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 17/55] notify: move TemplateSource to context module Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 18/55] notify: config: cleanup helpers names and visibility Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 19/55] notify: config: rename section config parser/writer methods Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 20/55] notify: config: pass builtins explicitly when parsing section config Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 21/55] notify: implement PartialEq for all Config types Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 22/55] notify: use typed SectionConfigData Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 23/55] notify: api: api types: rename Deleteable* -> Deletable* Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 24/55] notify: context: parse builtin config only once Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 25/55] notify: context: parse proxy config in trait impl, not at the callsite Lukas Wagner
2026-11-13 15:07 ` [PATCH proxmox 26/55] notify: gate sub-modules with the appropriate feature flags Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 27/55] notify: fold mail-forwarder feature into send-impl Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 28/55] notify: forwarded mails: don't hardcode severity and metadata fields Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 29/55] notify: don't pass uid when instantiating forwarded mail notifications Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 30/55] notify: derive PartialEq for Notification type Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 31/55] notify: add getters for severity and fields on " Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 32/55] notify: add test suite for " Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 33/55] notify: serialize raw, forwarded mail content as base64 Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 34/55] notify: unify code paths for legacy-sendmail and regular notifications Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 35/55] notify: add backwards-compat note to Notification type Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 36/55] notify: remove 'test_target' API Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 37/55] notify: replace notification instantiation with builder pattern Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 38/55] notify: add send receipts Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 39/55] notify: implement notification queue submitter Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 40/55] notify: context: add read_config Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 41/55] notify: queue: add queue consumer Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox 42/55] notify: queue: add worker task Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox-backup 43/55] notifications: don't ignore verification errors in legacy-sendmail mode Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox-backup 44/55] notifications: adapt to proxmox-notify API changes Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox-backup 45/55] api: notification: send test notification via proxmox_notify::send Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox-backup 46/55] notifications: send all notifications via proxmox-notify's queue Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox-perl-rs 47/55] pve: notify: adapt to changes in the public API of proxmox-notify Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox-perl-rs 48/55] pve: notify: add `PVE::RS::Notify::enqueue` method Lukas Wagner
2026-11-13 15:08 ` [PATCH pve-cluster 49/55] notify: send notifications via notification queue Lukas Wagner
2026-11-13 15:08 ` [PATCH manager 50/55] vzdump: send legacy-sendmail notifications via simplified API Lukas Wagner
2026-11-13 15:08 ` [PATCH manager 51/55] pve-notify-worker: add new rust-based notification worker daemon Lukas Wagner
2026-11-13 15:08 ` [PATCH manager 52/55] debian: add 'pve-notify-worker' as a dependency Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox-mail-forward 53/55] forward mails via notification queue Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox-mail-forward 54/55] use return code to signal permanent or temporary failure Lukas Wagner
2026-11-13 15:08 ` [PATCH proxmox-mail-forward 55/55] limit size of mail read from stdin Lukas Wagner
2026-11-17 9:35 ` [PATCH many 00/55] notify: maintenance, PDM preparations, queue + worker Lukas Wagner
2026-11-18 9:55 ` superseded: " Lukas Wagner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox