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

Move do_sendmail before first call

parent 06d52788
No related branches found
No related tags found
No related merge requests found
......@@ -147,6 +147,44 @@ sub notify(){
}
}
# Send subject, message by email to root
sub do_sendmail($$$){
my ($subject, $message, $retry) = @_;
utf8::encode($subject);
utf8::encode($message);
my $msg = MIME::Lite->new(
From => 'tetras-back',
To => 'root',
Subject => "[Tetras-back] $subject",
Type => 'multipart/mixed'
);
$msg->attr("content-type.charset" => "UTF-8");
$msg->attach(
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'
);
}
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");
}
}
# Send the mail and exit thread
sub end_backup($$){
my ($name, $errorcode) = @_;
......@@ -195,44 +233,6 @@ sub do_backup($){
return end_backup($name, $error);
}
# Send subject, message by email to root
sub do_sendmail($$$){
my ($subject, $message, $retry) = @_;
utf8::encode($subject);
utf8::encode($message);
my $msg = MIME::Lite->new(
From => 'tetras-back',
To => 'root',
Subject => "[Tetras-back] $subject",
Type => 'multipart/mixed'
);
$msg->attr("content-type.charset" => "UTF-8");
$msg->attach(
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'
);
}
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
sub get_uuid($){
my $dev = shift;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment