A email notification will be send for each job when the job fails.
This message will only send when an error occurs and the fail count is on 1.
Reviewed-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Acked-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
# passing $now and $verbose is useful for regression testing
sub run_jobs {
# passing $now and $verbose is useful for regression testing
sub run_jobs {
- my ($now, $logfunc, $verbose) = @_;
+ my ($now, $logfunc, $verbose, $mail) = @_;
my $iteration = $now // time();
my $iteration = $now // time();
while (my $jobcfg = PVE::ReplicationState::get_next_job($iteration, $start_time)) {
my $guest_class = $lookup_guest_class->($jobcfg->{vmtype});
while (my $jobcfg = PVE::ReplicationState::get_next_job($iteration, $start_time)) {
my $guest_class = $lookup_guest_class->($jobcfg->{vmtype});
- PVE::Replication::run_replication($guest_class, $jobcfg, $iteration, $start_time, $logfunc, 1, $verbose);
+
+ eval {
+ PVE::Replication::run_replication($guest_class, $jobcfg, $iteration, $start_time, $logfunc, $verbose);
+ };
+ if (my $err = $@) {
+ warn "$jobcfg->{id}: got unexpected replication job error - $err";
+ my $state = PVE::ReplicationState::read_state();
+ my $jobstate = PVE::ReplicationState::extract_job_state($state, $jobcfg);
+ eval {
+ PVE::Tools::sendmail('root', "Replication Job: $jobcfg->{id} failed", $err)
+ if $jobstate->{fail_count} == 1 && $mail;
+ };
+ warn ": $@" if $@;
+ };
+
$start_time = $now // time();
}
};
$start_time = $now // time();
}
};
default => 0,
optional => 1,
},
default => 0,
optional => 1,
},
+ mail => {
+ description => "Send an email notification in case of a failure.",
+ type => 'boolean',
+ default => 0,
+ optional => 1,
+ },
},
},
returns => { type => 'null' },
code => sub {
my ($param) = @_;
},
},
returns => { type => 'null' },
code => sub {
my ($param) = @_;
+ die "Mail and id are mutually exclusive!\n"
+ if $param->{id} && $param->{mail};
+
my $logfunc;
if ($param->{verbose}) {
my $logfunc;
if ($param->{verbose}) {
- PVE::API2::Replication::run_jobs(undef, $logfunc);
+ PVE::API2::Replication::run_jobs(undef, $logfunc, 0, $param->{mail});
-ExecStart=/usr/bin/pvesr run
+ExecStart=/usr/bin/pvesr run --mail 1