Rewrite util_send_status_mail to go through the SMTP server

So emails get signed by qpsmtpd
This commit is contained in:
Daniel Berteaud 2020-02-27 18:32:32 +01:00
parent 437332781d
commit 972ef40482
1 changed files with 24 additions and 16 deletions

View File

@ -1,23 +1,31 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
use Mail::Send;
use esmith::ConfigDB; use esmith::ConfigDB;
use MIME::Lite;
use Net::SMTP;
my $c = esmith::ConfigDB->open_ro(); my $c = esmith::ConfigDB->open_ro();
my $domain = $c->get('DomainName')->value(); my $domain = $c->get('DomainName')->value();
my $host = $c->get('SystemName')->value(); my $host = $c->get('SystemName')->value();
my $z = $c->get('zabbix-agent'); my $z = $c->get('zabbix-agent');
my $dest = $z->prop('StatusRecipient') || 'admin@' . $domain; my $dest = $z->prop('StatusRecipient') || 'admin@' . $domain;
my $mail = new Mail::Send; my $smtp = Net::SMTP->new('localhost');
$mail->to("$dest"); my $mail = MIME::Lite->new(
$mail->set("From","zabbix-agent"); From => 'smeserver-status@' . $domain,
$mail->subject("[STATUS] $host.$domain"); To => $dest,
my $body = $mail->open; Subject => "[STATUS] $host.$domain",
print $body localtime(time)."\n", Data => localtime(time)."\n" .
"\n#>tail /var/log/messages :\n", "\n#>tail /var/log/messages :\n" .
`/usr/bin/tail \$(readlink /var/log/messages)`, `/usr/bin/tail \$(readlink /var/log/messages)` .
"\n#>netstat --numeric-hosts -tpu :\n", "\n#>netstat --numeric-hosts -tpu :\n" .
`/bin/netstat --numeric-hosts -tpu`; `/bin/netstat --numeric-hosts -tpu`
$body->close; );
$smtp->mail('smeserver-status@' . $domain);
$smtp->recipient($dest);
$smtp->data();
$smtp->datasend($mail->as_string);
$smtp->dataend();
$smtp->quit;