WAVE Log
logwatch のレポートを Brevo API でメール送信する

「logwatch → ファイル出力 → PHP で Brevo API 送信」という構成。

logwatch をインストール。

:~# dnf install logwatch

logwatch をファイル出力にするコマンド。

logwatch --output file --filename /var/log/logwatch-report.txt

PHP でファイルを読み込んで Brevo API 送信。

/usr/local/scripts ディレクトリ作成。

:~# mkdir -p /usr/local/scripts :~# chmod 755 /usr/local/scripts

PHPコード例:

:~# vi /usr/local/scripts/send-logwatch.php

<?php require_once '/usr/local/lib/vendor/autoload.php'; use Brevo\Brevo; use Brevo\TransactionalEmails\Requests\SendTransacEmailRequest; use Brevo\TransactionalEmails\Types\SendTransacEmailRequestSender; use Brevo\TransactionalEmails\Types\SendTransacEmailRequestToItem; // logwatch のレポートを読み込む $report = file_get_contents('/var/log/logwatch-report.txt'); // Brevo API クライアント $client = new Brevo(apiKey: 'YOUR_BREVO_API_KEY'); // メール送信 $result = $client->transactionalEmails->sendTransacEmail( new SendTransacEmailRequest([ 'subject' => 'Daily Logwatch Report', 'htmlContent' => nl2br(htmlspecialchars($report)), 'sender' => new SendTransacEmailRequestSender([ 'name' => 'Server', 'email' => '[email protected]', ]), 'to' => [ new SendTransacEmailRequestToItem([ 'email' => '[email protected]', 'name' => 'Your Name', ]), ], ]) ); echo "Sent: " . $result->messageId . PHP_EOL;

毎日実行するように cron に登録例:

:~# crontab -e

0 7 * * * /usr/sbin/logwatch --output file --filename /var/log/logwatch-report.txt 5 7 * * * /usr/bin/php /usr/local/scripts/send-logwatch.php