Image

Knowledge base → Postfix mail server monitoring with PDF report

[Virtual servers]
Date of publication: 22.05.2023

After you have launched your corporate mail server, the question arises of how to view its performance indicators: the number of mail received and sent by employees, the rating of employees by mail activity, traffic indicators, as well as the effectiveness of the anti-spam rules, including the reasons for blocking. All of this data is available raw in the postfix service log file. 

To analyze the log file, we will install the utility:

apt install pflogsumm
cp /usr/sbin/pflogsumm /usr/local/bin

Let's check the script by specifying the path to the postfix log file:

cat /var/log/mail.log | pflogsumm | more

The output will contain a large amount of data grouped by type:

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--

If necessary, you can create a script that will send a report by mail, as well as a PDF attachment, for further forwarding. To generate a pdf report and send a letter, install the necessary packages:

apt install mailutils a2ps

Let's create a script with the following content:

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 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 to@domain.tld -A /var/log/report.pdf < /var/log/report.txt

Assign execution rights:

chmod +x /usr/local/bin/report_pdf.sh

Let's add a task to cron so that the report comes once a week, since the log is updated weekly, for example, on Friday at 15:00:

crontab -e

0 15 * * 5 /usr/local/bin/report_pdf.sh





No Comments Yet