So I was looking for a quick way to get SMTP statistics for the Postfix install on an ISPConfig 3 server and thought I would share the configuration for anyone else that would want to do that.

After following one of the “Perfect Server” tutorials like this one below for Ubuntu 14.04 you can configure awstats and the cron to generate some SMTP stats from your postfix mail logs.

http://www.howtoforge.com/the-perfect-server-ubuntu-14.04-nginx-bind-mysql-php-postfix-dovecot-and-ispconfig3

1. Copy maillogconvert.pl to the aws directory..

root@server.com:/root/# cp /usr/share/doc/awstats/examples/maillogconvert.pl /usr/share/awstats

2. Create awstats postfix database directory:

root@server.com:/root/# mkdir /var/lib/awstats/postfix

3. Copy the AWStats Config as a template /etc/awstats/awstats.conf to /etc/awstats/awstats.postfix.conf

root@server.com:/root/# cp /etc/awstats/awstats.conf /etc/awstats/awstats.postfix.conf

4. Edit the /etc/awstats/awstats.postfix.conf file and modify the options specified.

root@server.com:/root/# nano /etc/awstats/awstats.postfix.conf


# line 51: change
LogFile="/usr/share/awstats/maillogconvert.pl standard < /var/log/mail.log |" # line 63: change LogType=M # line 122 make it comment and add the line below # LogFormat=1 LogFormat="%time2 %email %email_r %host %host_r %method %url %code %bytesd" # line 153 specify hostname SiteDomain="server.com" # line 222: change DirIcons="./icon" # line 831: change like below LevelForBrowsersDetection=0 LevelForOSDetection=0 LevelForRefererAnalyze=0 LevelForRobotsDetection=0 LevelForSearchEnginesDetection=0 LevelForKeywordsDetection=0 LevelForFileTypesDetection=0 LevelForWormsDetection=0 # line 905: change your language Lang="en" # line 949: change like below ShowMonthStats=UHB ShowDaysOfMonthStats=HB ShowDaysOfWeekStats=HB ShowHoursStats=HB ShowDomainsStats=0 ShowHostsStats=HBL ShowRobotsStats=0 ShowEMailSenders=HBML ShowEMailReceivers=HBML ShowSessionsStats=0 ShowPagesStats=0 ShowFileTypesStats=0 ShowOSStats=0 ShowBrowsersStats=0 ShowOriginStats=0 ShowKeyphrasesStats=0 ShowKeywordsStats=0 ShowMiscStats=0 ShowHTTPErrorsStats=0 ShowSMTPErrorsStats=1

5. Comment out the include at the bottom of the /etc/awstats/awstats.postfix.conf file.


#-----------------------------------------------------------------------------
# INCLUDES
#-----------------------------------------------------------------------------

# You can include other config files using the directive with the name of the
# config file.
# This is particularly useful for users who have a lot of virtual servers, so
# a lot of config files and want to maintain common values in only one file.
# Note that when a variable is defined both in a config file and in an
# included file, AWStats will use the last value read for parameters that
# contains one value and AWStats will concat all values from both files for
# parameters that are lists of values.
#

# Include "/etc/awstats/awstats.conf.local"

6. Install apache2-utils with apt-get if not already installed.

root@server.com:/root/# apt-get install apache2-utils

7. Create the .htpasswd password db to protect the cgi with basic auth.

Remember the username and password you setup here.

root@server.com:/root/# htpasswd -c /etc/nginx/.htpasswd_postfix

8. Add the location to the ISPConfig NginX configuration : /etc/nginx/sites-enabled/000-ispconfig.vhost

Add this code just before the example for phpmyadmin that should be commented out...


location = /awstats.pl {
root /usr/lib/cgi-bin;
gzip off;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
# Not needed if already in fastcgi_params.
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd_postfix;
}

9. Do the first run of awstats to generate the database .

root@server.com:/root/# /usr/lib/cgi-bin/awstats.pl -config=postfix -update

10. Add this line to /etc/cron.d/awstats to keep the database up to date every hour.

00 * * * * root /usr/lib/cgi-bin/awstats.pl -config=postfix -update

11. Symlink the "icon" directory to the ISPConfig web root so we can see the icons..

root@server.com:/root/# ln -s /usr/share/awstats/icon/ /usr/local/ispconfig/interface/web/

12. Restart NginX to get the new configuration

root@server.com:/root/# service nginx restart

13. Visit the ISPConfig 3 Web UI

You should now be able to visit your ISPConfig 3 web interface and after authenticating view the parsed log statistics.

An Example URL : http://server.com:8080/awstats.pl?config=postfix

You will be prompted for the username and password you set up earlier to view the statistics.