企業のメールサーバーを起動した後、その運用状況を確認する方法について考える必要があります。例えば、従業員が送受信したメールの数、メールアクティビティによる従業員のランキング、トラフィックデータ、スパム対策ルールの効果(ブロックの理由を含む)などです。これらのデータは、Postfixのログファイルに生の形式で記録されています。
ログファイルを解析するために、次のツールをインストールします:
apt install pflogsumm
cp /usr/sbin/pflogsumm /usr/local/bin
Postfixのログファイルのパスを指定してスクリプトの動作を確認します:
cat /var/log/mail.log | pflogsumm | more
出力は、種類ごとにグループ化された多数のデータを含みます:
Grand Totals ------------ messages
51 received 50 delivered 0 forwarded 0 deferred 0 bounced 472 rejected (90%) 0 reject warnings 0 held 0 discarded (0%)
151710 bytes received 151710 bytes delivered 4 senders 4 sending hosts/domains 11 recipients 7 recipient hosts/domains
Per-Day Traffic Summary
date received delivered deferred bounced rejected -------------------------------------------------------------------- May 14 2023 0 0 0 0 1 May 19 2023 45 44 0 0 31 May 20 2023 6 6 0 0 140 --More--
必要に応じて、レポートをメールで送信し、PDF添付ファイルとして送信するスクリプトを作成することも可能です。PDFレポートを生成してメールを送信するために、以下のパッケージをインストールします:
apt install mailutils a2ps
次の内容のスクリプトを作成します:
nano /usr/local/bin/report_pdf.sh
#!/usr/bin/env bash
rm /var/log/report.txt rm /var/log/report.ps rm /var/log/report.pdf cat /var/log/mail.log | pflogsumm | more >> /var/log/report.txt sleep 10 a2ps -b --header=mail.domain.tld --rows 1 --columns 1 /var/log/report.txt -o /var/log/report.ps ps2pdf -s1 /var/log/report.ps /var/log/report.pdf mail -s 'Mail Server Report' -a From:Mail-Server -A /var/log/report.pdf < /var/log/report.txt
実行権限を付与します:
chmod +x /usr/local/bin/report_pdf.sh
レポートを毎週金曜日の15時に受信するように、cronにタスクを追加します。ログは毎週更新されるため、金曜日に設定します:
crontab -e
0 15 * * 5 /usr/local/bin/report_pdf.sh