Tran Nghi's Site  - Make notes and share experience

Hướng dẫn setup / cài đặt SendmailAnalyzer trên Ubuntu 16.04

This post is also available in: English

SendmailAnalyzer as is name suggest is a free Sendmail/Postfix log analyzer. It process maillog files and generate dynamic statistics in HTML and graphical output. The reports are generated in real time so that it let you know at any moment what is going on your mail servers. It use time (hour, day, month and year views) and cross-linked navigation for easy use.

Project Page: http://sendmailanalyzer.darold.net/

SendmailAnalyzer Installation

2.1 Download resource and make install

[email protected]:~# wget "http://downloads.sourceforge.net/project/sa-report/sa-report/9.2/sendmailanalyzer-9.2.tar.gz"
[email protected]:~# tar xvzf sendmailanalyzer-9.2.tar.gz
[email protected]:~# perl Makefile.PL
[email protected]:~# make && make install

End of output:

-----------------------------------------------------------------------------
1. Start SendmailAnalyzer daemon with:

        /usr/local/sendmailanalyzer/sendmailanalyzer -f

   or use one of the starters script provided in the start_scripts/ directory.

2. Modify your httpd.conf to allow access to CGI scripts like follow:

        Alias /sareport /usr/local/sendmailanalyzer/www

        <Directory /usr/local/sendmailanalyzer/www>
            Options ExecCGI
            AddHandler cgi-script .cgi
            DirectoryIndex sa_report.cgi
            Order deny,allow
            Deny from all
            Allow from 192.168.1.0/24
        </Directory>

   If necessary, give additional host access to SendmailAnalyzer in httpd.conf.
   Restart and ensure that httpd is running.

3. Browse to http://mta.host.dom/sareport/ to ensure that things are working properly.

4. Setup a cronjob to run sa_cache and restart SendmailAnalyzer daemon after maillog logrotate as follow:

     # SendmailAnalyzer log reporting daily cache
     0 1 * * * /usr/local/sendmailanalyzer/sa_cache > /dev/null 2>&1
     # On huge MTA you may want to have five minutes caching
     #*/5 * * * * /usr/local/sendmailanalyzer/sa_cache -a > /dev/null 2>&1

5. Add an entry in /etc/logrotate.d/syslog to restart SendmailAnalyzer when maillog is rotated or create a cron job.

For more information, see /usr/local/sendmailanalyzer/doc/README file.
-----------------------------------------------------------------------------

2.2 Configure Sendmailanalyzer:

[email protected]:~# cd /usr/local/sendmailanalyzer/
[email protected]:~# vi sendmailanalyzer.conf

-----------------------------------------------------------------------------
# Path to the maillog file to analyse.
# Can be overwritten with --log or -l
LOG_FILE        /var/log/mail.log
-----------------------------------------------------------------------------

[email protected]:~# ./sendmailanalyzer -f
[email protected]:~# cp -p sendmailanalyzer /etc/init.d/sendmailanalyzer
[email protected]:~# service sendmailanalyzer restart

2.3 Configure Apache2:

[email protected]:~# vi /etc/apache2/sites-available/sendmailanalyzer.conf

-----------------------------------------------------------------------------
Alias /sareport /usr/local/sendmailanalyzer/www

<Directory /usr/local/sendmailanalyzer/www>
        Options ExecCGI
        AddHandler cgi-script .cgi
        DirectoryIndex sa_report.cgi
        AllowOverride all
        Require all granted
        #Order deny,allow
        #Deny from all
        Allow from all
</Directory>
-----------------------------------------------------------------------------

[email protected]:~# a2ensites sendmailanalyzer.conf
[email protected]:~# service apache2 reload

2.3 Addition step – Enable Apache CGI:

[email protected]:~# a2enmod cgi
[email protected]:~# service apache2 restart

2.4 Access Sendmailanalyzer via web-base:

  • ie: http://yourdomain.tld/sareport/

2.5 Setup Crontab

  • See the #4 of Output console on the step 2.1.

3. Troubleshooting with SendMailAnalyzer

1. Parsing old/missed log files – all log from scratch.

At the first time running SendMailAnalyzer, I got an little issue when view report for the past month/year,

[email protected]:~# service sendmailanalyzer stop
[email protected]:~# killall -e sendmailanalyzer
[email protected]:~# rm /usr/local/sendmailanalyzer/data/LAST_PARSED
[email protected]:~# rm /usr/local/sendmailanalyzer/data/* -R
[email protected]:~# for log in `ls -tr /var/log/mail*`; do /usr/local/sendmailanalyzer/sendmailanalyzer -bfl $log; done
[email protected]:~# service sendmailanalyzer start

2. No cache file found /usr/local/sendmailanalyzer/data/…/cache.pm

No cache file found (/usr/local/sendmailanalyzer/data/example/2018/04/cache.pm) , please run sa_cache as explain in the documentation (See Caching).

[email protected]:~# for month in 01 02 03 04 05 06 07 08 09 10 11 12 ; do /usr/local/sendmailanalyzer/sa_cache -s "example" -d "2018/$month"; done
Message