[pve-devel] [PATCH pve-manager 16/18] api: replication: send notifications via new notification module

Lukas Wagner l.wagner at proxmox.com
Mon Mar 27 17:18:55 CEST 2023


Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
---
 PVE/API2/Replication.pm | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/PVE/API2/Replication.pm b/PVE/API2/Replication.pm
index d70b4607..e3566a71 100644
--- a/PVE/API2/Replication.pm
+++ b/PVE/API2/Replication.pm
@@ -15,6 +15,7 @@ use PVE::QemuConfig;
 use PVE::QemuServer;
 use PVE::LXC::Config;
 use PVE::LXC;
+use PVE::Notification;
 
 use PVE::RESTHandler;
 
@@ -129,7 +130,17 @@ my sub _handle_job_err {
     $msg .= "\nError:\n$err";
 
     eval {
-	PVE::Tools::sendmail('root', "Replication Job: $job->{id} failed", $msg)
+	my $config = PVE::Notification::config();
+	# For backward compatibility, add ephemeral sendmail endpoint,
+	# so that root receives a notification even
+	# if there is no endpoint defined.
+	$config->add_sendmail_endpoint(
+	    "legacy-replication-sendmail",
+	    ["root"],
+	    undef, # TODO: read $mailfrom from datacenter.conf?
+	    "");
+
+	PVE::Notification::error("Replication Job: $job->{id} failed", $msg, $config);
     };
     warn ": $@" if $@;
 }
-- 
2.30.2






More information about the pve-devel mailing list