How to Install Mail Log Report pflogsumm on AlmaLinux

This article will walk you through the steps to install and use pflogsumm on AlmaLinux, a popular enterprise Linux distribution.

Managing email logs effectively is crucial for any server administrator. A detailed and concise log analysis helps diagnose issues, monitor server performance, and ensure the smooth functioning of email services. pflogsumm, a Perl-based tool, simplifies this process by generating comprehensive, human-readable summaries of Postfix logs.

This article will walk you through the steps to install and use pflogsumm on AlmaLinux, a popular enterprise Linux distribution.


What is pflogsumm?

pflogsumm is a log analysis tool specifically designed for Postfix, one of the most widely used Mail Transfer Agents (MTAs). This tool parses Postfix logs and generates detailed reports, including:

  • Message delivery counts
  • Bounce statistics
  • Warnings and errors
  • Traffic summaries by sender and recipient

By leveraging pflogsumm, you can gain valuable insights into your mail server’s performance and spot potential issues early.


Prerequisites

Before you begin, ensure you have the following:

  1. A server running AlmaLinux.
  2. Postfix installed and configured on your server.
  3. Root or sudo access to the server.

Step 1: Update Your AlmaLinux System

First, update your system packages to ensure you’re working with the latest versions:

sudo dnf update -y

This step ensures all dependencies required for pflogsumm are up to date.


Step 2: Install Perl

Since pflogsumm is a Perl script, Perl must be installed on your system. Verify if Perl is already installed:

perl -v

If Perl is not installed, use the following command:

sudo dnf install perl -y

Step 3: Download pflogsumm

Download the latest pflogsumm script from its official repository. You can use wget or curl to fetch the script. First, navigate to your desired directory:

cd /usr/local/bin

Then, download the script:

sudo wget https://raw.githubusercontent.com/bitfolk/pflogsumm/master/pflogsumm.pl

Alternatively, you can clone the repository using Git if it’s installed:

sudo dnf install git -y
git clone https://github.com/bitfolk/pflogsumm.git

Navigate to the cloned directory to locate the script.


Step 4: Set Execute Permissions

Make the downloaded script executable:

sudo chmod +x /usr/local/bin/pflogsumm.pl

Verify the installation by running:

/usr/local/bin/pflogsumm.pl --help

If the script executes successfully, pflogsumm is ready to use.


Step 5: Locate Postfix Logs

By default, Postfix logs are stored in the /var/log/maillog file. Ensure this log file exists and contains recent activity:

sudo cat /var/log/maillog

If the file is empty or does not exist, ensure that Postfix is configured and running correctly:

sudo systemctl status postfix

Step 6: Generate Mail Log Reports with pflogsumm

To analyze Postfix logs and generate a report, run:

sudo /usr/local/bin/pflogsumm.pl /var/log/maillog

This command provides a summary of all the mail log activities.


Step 7: Automate pflogsumm Reports with Cron

You can automate the generation of pflogsumm reports using cron. For example, create a daily summary report and email it to the administrator.

Step 7.1: Create a Cron Job

Edit the crontab file:

sudo crontab -e

Add the following line to generate a daily report at midnight:

0 0 * * * /usr/local/bin/pflogsumm.pl /var/log/maillog | mail -s "Daily Mail Log Summary" admin@example.com

Replace admin@example.com with your email address. This setup ensures you receive daily email summaries.

Step 7.2: Configure Mail Delivery

Ensure the server can send emails by verifying Postfix or your preferred MTA configuration. Test mail delivery with:

echo "Test email" | mail -s "Test" admin@example.com

If you encounter issues, troubleshoot your mail server setup.


Step 8: Customize pflogsumm Output

pflogsumm offers various options to customize the report:

  • –detail=hours: Adjusts the level of detail (e.g., hourly or daily summaries).
  • –problems-first: Displays problems at the top of the report.
  • –verbose-messages: Shows detailed message logs.

For example:

sudo /usr/local/bin/pflogsumm.pl --detail=1 --problems-first /var/log/maillog

Step 9: Rotate Logs for Better Performance

Postfix logs can grow large over time, impacting performance. Use logrotate to manage log file sizes.

Step 9.1: Check Logrotate Configuration

Postfix is typically configured in /etc/logrotate.d/syslog. Ensure the configuration includes:

/var/log/maillog {
    daily
    rotate 7
    compress
    missingok
    notifempty
    postrotate
        /usr/bin/systemctl reload rsyslog > /dev/null 2>&1 || true
    endscript
}

Step 9.2: Test Log Rotation

Force a log rotation to verify functionality:

sudo logrotate -f /etc/logrotate.conf

Step 10: Troubleshooting Common Issues

Here are a few common problems and their solutions:

Error: pflogsumm.pl: Command Not Found

Ensure the script is in your PATH:

sudo ln -s /usr/local/bin/pflogsumm.pl /usr/bin/pflogsumm

Error: Cannot Read Log File

Check file permissions for /var/log/maillog:

sudo chmod 644 /var/log/maillog

Empty Reports

Verify that Postfix is actively logging mail activity. Restart Postfix if needed:

sudo systemctl restart postfix

Conclusion

Installing and using pflogsumm on AlmaLinux is a straightforward process that significantly enhances your ability to monitor and analyze Postfix logs. By following the steps outlined in this guide, you can set up pflogsumm, generate insightful reports, and automate the process for continuous monitoring.

By integrating tools like pflogsumm into your workflow, you can maintain a healthy mail server environment, identify issues proactively, and optimize email delivery performance.