[pve-devel] [PATCH many 00/11] notifications: feed system mails into proxmox_notify

Lukas Wagner l.wagner at proxmox.com
Thu Aug 31 13:06:10 CEST 2023


The aim of this patch series is to adapt `proxmox-mail-forward` 
so that it forwards emails that were sent to the local root user
through the `proxmox_notify` crate.

A short summary of the status quo:
Any mail that is sent to the local `root` user is forwarded by
postfix to the `proxmox-mail-forward` binary, which receives the
mail via STDIN. `proxmox-mail-forward` looks up the email address 
configured for the `root at pam` user in /etc/{proxmox-backup,pve}/user.cfg 
and then forwards the mail to this address by calling `sendmail`

This patch series modifies `proxmox-mail-forward` in the following way:
`proxmox-mail-forward` instantiates the configuration for `proxmox_notify`
by reading `/etc/{proxmox-backup,pve}/notifications.cfg. Also, it looks 
up the policy for system mail (target/if to forward at all) in 
`node.cfg/datacenter.cfg`. Following that, the mail is passed to 
`proxmox_notify`, which sends it to the specified target(s).
If no target is configured/configuration files do not exist, then
the mail is forwarded using the `mail-to-root` target, which always exists.
In this way the changes should be 100% backwards compatible.

One small change in behavior can occur if PBS is co-installed on a PVE host.
Here it could happen that a mail is forwarded twice: Once for for 
notification configuration for PVE, and once for the config for PBS.
Unfortunately there is no easy way to perform any useful 'deduplication'
there (by target name does not really work, since they could have different
configuration/recipients; by 'mail-address' would work for mail-based targets,
however this involves some pretty invasive changes and still does not work for 
targets that are not mail-based). 

Personally I feel that we should just add  a section about this behavior 
in the docs (once proxmox_notify is fully integrated in PBS), 
instructing the user to set `system-mail` to `never` in `node.cfg` 
(don't forward mails). Alternatively we could try to detect co-installations
and only forward for the target of one of both products. 
However, I prefer the first option.

`proxmox-notify` now depends on a new crate `mail-parser` to parse 
email headers (something I *really* don't want to implement myself
from scratch). The new dependency is not packaged yet, the necessary
debcargo-conf changes are included in the first patch.
@TESTERS: I can provide a pre-built deb for `mail-parser`.



debcargo-conf:

Lukas Wagner (1):
  package mail-parser 0.8.2

 src/mail-parser/debian/changelog              |  6 ++
 src/mail-parser/debian/copyright              | 49 ++++++++++++
 .../debian/copyright.debcargo.hint            | 77 +++++++++++++++++++
 src/mail-parser/debian/debcargo.toml          |  2 +
 4 files changed, 134 insertions(+)
 create mode 100644 src/mail-parser/debian/changelog
 create mode 100644 src/mail-parser/debian/copyright
 create mode 100644 src/mail-parser/debian/copyright.debcargo.hint
 create mode 100644 src/mail-parser/debian/debcargo.toml


proxmox:

Lukas Wagner (4):
  sys: email: add `forward`
  notify: introduce Error::Generic
  notify: add mechanisms for email message forwarding
  notify: add PVE/PBS context

 Cargo.toml                                    |   1 +
 proxmox-notify/Cargo.toml                     |   5 +-
 proxmox-notify/src/context/common.rs          |  27 ++++
 .../src/{context.rs => context/mod.rs}        |  14 +-
 proxmox-notify/src/context/pbs.rs             | 130 ++++++++++++++++++
 proxmox-notify/src/context/pve.rs             |  82 +++++++++++
 proxmox-notify/src/endpoints/gotify.rs        |  21 +--
 proxmox-notify/src/endpoints/sendmail.rs      |  62 +++++----
 proxmox-notify/src/filter.rs                  |   8 +-
 proxmox-notify/src/lib.rs                     | 109 +++++++++++++--
 proxmox-sys/src/email.rs                      |  52 ++++++-
 11 files changed, 451 insertions(+), 60 deletions(-)
 create mode 100644 proxmox-notify/src/context/common.rs
 rename proxmox-notify/src/{context.rs => context/mod.rs} (54%)
 create mode 100644 proxmox-notify/src/context/pbs.rs
 create mode 100644 proxmox-notify/src/context/pve.rs


proxmox-perl-rs:

Lukas Wagner (2):
  notify: construct Notification via constructor
  pve-rs: notify: remove notify_context for PVE

 common/src/notify.rs         |   8 +--
 pve-rs/Cargo.toml            |   2 +-
 pve-rs/src/lib.rs            |   7 ++-
 pve-rs/src/notify_context.rs | 117 -----------------------------------
 4 files changed, 6 insertions(+), 128 deletions(-)
 delete mode 100644 pve-rs/src/notify_context.rs


pve-cluster:

Lukas Wagner (1):
  datacenter config: add new parameters for system mail forwarding

 src/PVE/DataCenterConfig.pm | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)


pve-manager:

Lukas Wagner (1):
  ui: notify: add system-mail settings, configuring mail forwarding

 www/manager6/dc/NotificationEvents.js | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)


proxmox-mail-forward:

Lukas Wagner (1):
  feed forwarded mails into proxmox_notify

 Cargo.toml  |   8 +-
 src/main.rs | 348 +++++++++++++++++++++++++++++++++++-----------------
 2 files changed, 238 insertions(+), 118 deletions(-)


pve-docs:

Lukas Wagner (1):
  notification: add docs for system mail forwarding

 notifications.adoc | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)


Summary over all repositories:
  24 files changed, 899 insertions(+), 313 deletions(-)

-- 
murpp v0.4.0






More information about the pve-devel mailing list