Skip to content
Snippets Groups Projects
Verified Commit 06d52788 authored by David Beniamine's avatar David Beniamine
Browse files

Better handling of email failure

parent 7c545c19
No related branches found
No related tags found
No related merge requests found
......@@ -158,7 +158,7 @@ sub end_backup($$){
}else{
$Logger->alert($subject);
}
do_sendmail("$subject", $MESSAGES{$errorcode}{message});
do_sendmail("$subject", $MESSAGES{$errorcode}{message}, 0);
kill("SIGUSR2", $$);
return $status." ".time();
}
......@@ -196,8 +196,8 @@ sub do_backup($){
}
# Send subject, message by email to root
sub do_sendmail($$){
my ($subject, $message) = @_;
sub do_sendmail($$$){
my ($subject, $message, $retry) = @_;
utf8::encode($subject);
utf8::encode($message);
......@@ -212,18 +212,25 @@ sub do_sendmail($$){
Type => 'text/plain; charset=UTF-8',
Data => $message,
);
if($retry==0){
# Add your text message.
$msg->attach(Type => 'text/plain; charset=UTF-8',
Path => "$LOGDIR/message.log",
Filename => 'message.log',
Disposition => 'inline'
);
try{
$msg->send;
$Logger->info("Etat envoyé par email");
}catch{
$Logger->alert("Echec lors de l'envoi du mail: '$_'");
};
}
eval{ $msg->send() };
if($@){
if($retry == 0){
$Logger->info("Seconde tentative d'envoi courriel sans piece jointe");
do_sendmail($subject,$message,1);
}else{
$Logger->alert("Echec d'envoi du courriel");
}
}else{
$Logger->info("Etat envoyé par courriel");
}
}
# Retrieve uuid of given device
......@@ -384,7 +391,8 @@ sub start_daemon(){
}else{
$Logger->alert("Commande inconnue : '$line'");
do_sendmail("Erreur: commande inconnue",
"Je viens de recevoir la commande '$line' que je ne sais pas traiter");
"Je viens de recevoir la commande '$line' que je ne sais pas traiter",
0);
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment