Deploy AWStats on CentOS 7 to report SMTP traffic

Let’s look at deploying AWStats on CentOS 7 Mail gateway running postfix and MailScanner
1. First lets install httpd if not yet installed

yum install httpd

2. In order to install AWStats we will need to install and add EPEL repository

yum install epel-release

3. Now we can install AWStats

yum install awstats

AWStats Configuration

1. Edit /etc/awstats/awstats.”name of your server”.conf


# line 50: change

LogFile="/usr/share/awstats/tools/maillogconvert.pl standard < /var/log/maillog |
"
# line 62: change

LogType=M
# line 122: comment out and add like follows

#
LogFormat=1
LogFormat="%time2 %email %email_r %host %host_r %method %url %code %bytesd"
# line 848: change like follows

LevelForBrowsersDetection=0

LevelForOSDetection=0

LevelForRefererAnalyze=0

LevelForRobotsDetection=0

LevelForSearchEnginesDetection=0

LevelForKeywordsDetection=0

LevelForFileTypesDetection=0

LevelForWormsDetection=0
# line 966: change like follows

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

2. Now we need to make sure we grant access to web pages. Below is sample of configuration for 192.168.0/24 subnet

/etc/httpd/conf.d/awstats.conf
#
# Content of this file, with correct values, can be automatically added to
# your Apache server by using the AWStats configure.pl tool.
#


# If using Windows and Perl ActiveStat, this is to enable Perl script as CGI.
#ScriptInterpreterSource registry


#
# Directives to add to your Apache conf file to allow use of AWStats as a CGI.
# Note that path "/usr/share/awstats/" must reflect your AWStats install path.
#
Alias /awstatsclasses "/usr/share/awstats/wwwroot/classes/"
Alias /awstatscss "/usr/share/awstats/wwwroot/css/"
Alias /awstatsicons "/usr/share/awstats/wwwroot/icon/"
ScriptAlias /awstats/ "/usr/share/awstats/wwwroot/cgi-bin/"


#
# This is to permit URL access to scripts/files in AWStats directory.
#

    Options None
    AllowOverride None
    
        # Apache 2.4	
        Require ip 192.168.0.0/24
    
    
        # Apache 2.2
        Order allow,deny
        Allow from 192.168.0.0/24
        Allow from ::1
    

# Additional Perl modules

    SetEnv PERL5LIB /usr/share/awstats/lib:/usr/share/awstats/plugins


3. At this point we will need to restart httpd service to apply new configuration


4. And finally generate reports

/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config="name of your server" -update 

# for example if server name is host1.local
/usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=host1.local -update 

5. Now you can access stats

http://host1.local/awstats/awstats.pl

6. Its also a good idea to setup cron job to refresh output. This is example of running it every hour.

#crontab -e
0 * * * */usr/share/awstats/wwwroot/cgi-bin/awstats.pl -config=host1.local -update