* [pve-devel] [PATCH proxmox-mail-forward] do not forward on PBS systems if co-installed with PVE
@ 2023-11-21 15:53 Lukas Wagner
2023-11-21 16:32 ` [pve-devel] applied: " Thomas Lamprecht
0 siblings, 1 reply; 2+ messages in thread
From: Lukas Wagner @ 2023-11-21 15:53 UTC (permalink / raw)
To: pve-devel
With the newly built-in targets/matchers, we should not add
a target/matcher manually any more. In fact, this broke mail
forwarding on PBS because 'default-matcher' already existed as a
built-in and could thus not be created.
We now simply do an early return.
Also initialize notify-context before instantiating the config,
since that already requires the context to be set.
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
src/main.rs | 38 ++++++++++++++------------------------
1 file changed, 14 insertions(+), 24 deletions(-)
diff --git a/src/main.rs b/src/main.rs
index e56bc1e..4662ffa 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -25,8 +25,6 @@ use anyhow::Error;
use proxmox_notify::context::pbs::PBS_CONTEXT;
use proxmox_notify::context::pve::PVE_CONTEXT;
-use proxmox_notify::endpoints::sendmail::SendmailConfig;
-use proxmox_notify::matcher::MatcherConfig;
use proxmox_notify::Config;
use proxmox_sys::fs;
@@ -74,48 +72,40 @@ fn forward_common(mail: &[u8], config: &Config) -> Result<(), Error> {
/// 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();
let config = Config::new(&config, &priv_config)?;
- proxmox_notify::context::set_context(&PVE_CONTEXT);
forward_common(mail, &config)
}
/// 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 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 {
- // TODO: This can be removed once PBS has full notification integration
- let mut config = Config::new("", "")?;
- if !has_pve {
- proxmox_notify::api::sendmail::add_endpoint(
- &mut config,
- &SendmailConfig {
- name: "default-target".to_string(),
- mailto_user: Some(vec!["root@pam".to_string()]),
- ..Default::default()
- },
- )?;
-
- proxmox_notify::api::matcher::add_matcher(
- &mut config,
- &MatcherConfig {
- name: "default-matcher".to_string(),
- target: Some(vec!["default-target".to_string()]),
- ..Default::default()
- },
- )?;
+ // 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
};
- proxmox_notify::context::set_context(&PBS_CONTEXT);
forward_common(mail, &config)?;
Ok(())
--
2.39.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* [pve-devel] applied: [PATCH proxmox-mail-forward] do not forward on PBS systems if co-installed with PVE
2023-11-21 15:53 [pve-devel] [PATCH proxmox-mail-forward] do not forward on PBS systems if co-installed with PVE Lukas Wagner
@ 2023-11-21 16:32 ` Thomas Lamprecht
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2023-11-21 16:32 UTC (permalink / raw)
To: Proxmox VE development discussion, Lukas Wagner
Am 21/11/2023 um 16:53 schrieb Lukas Wagner:
> With the newly built-in targets/matchers, we should not add
> a target/matcher manually any more. In fact, this broke mail
> forwarding on PBS because 'default-matcher' already existed as a
> built-in and could thus not be created.
> We now simply do an early return.
>
> Also initialize notify-context before instantiating the config,
> since that already requires the context to be set.
>
> Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
> ---
> src/main.rs | 38 ++++++++++++++------------------------
> 1 file changed, 14 insertions(+), 24 deletions(-)
>
>
applied, thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-11-21 16:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-21 15:53 [pve-devel] [PATCH proxmox-mail-forward] do not forward on PBS systems if co-installed with PVE Lukas Wagner
2023-11-21 16:32 ` [pve-devel] applied: " Thomas Lamprecht
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal