Complete Virtual Mail Server/awstats/ru

Введение
Even though postfix provides logs, having them graphically displayed and analyzed can give much more insight. is a popular log analyzer that can parse logs and setup proper results.

Установка
AWStats is a web-application but no longer relies on webapp-config. If it hasn't emerged already, it needs to be emerged.

Once installed, a config file needs to be created, either per domain, or one that handles all domains.

AWStats isn't installed via webapp-config, but rather a simple symlink is used.

AWStats
AWStats comes with reasonable defaults, but some need to be changed nevertheless.

For one, awstats assumes that vhosts aren't used. When using apache's default combined vhost logs for example, awstats will fail to run.

Assume apache's combined LogFormat is setup as follows:

The following changes then need to be made:

Next awstats needs to know about the domains and aliases to filter from the log file:

Also, awstats needs to store its database somewhere. Gentoo has created for this use, but it can be stored anywhere. Make sure the permissions are set so that the apache user can write to it:

Any other changes to the configuration file are optional, but interesting to look into:

Журналирование
awstats needs to process the apache log file to build its database. Once confirmed that it is working manually it can be automated.

Ручная настройка
First, awstats should be run from the console, to spot any initial errors:

This should list any issues and missing domain names from the config.

Cron
If everything is working perfectly, it can then be added to :

Remember to make the script executable if needed.

Logrotate
Awstats will process the log file every hour, but when logrotate rotates apache's log, some entries may be missing. This is easily solved however.

Apache
For awstats to be used from apache, the webhost needs to properly setup. In the alias section, the following needs to be added:

Finally, awstats needs the correct permissions to be accessible:

After a restart of apache, awstats should be available via http://stats.example.com/awstats/awstats.pl?config=stats.example.com. If no config option is passed to awstats, it uses the current hostname, which means in this case could have been omitted.

Awstats for mail log
AWStats is known for being an apache log parser. However it can also be used to parse mail logs.

Конфигурация
After copying to  quite a few changes are required to turn awstats into a mail log parser.

With those changes in place, a manual run should work without any issues:

Журналирование
To scan the mail log every hour, the existing awstats script in can be appended with the following:

Also syslog is getting rotated and thus awstats needs to parse the mail log file before the mail log is being rotated:

If logging of apache files is not desired, or webmail resides on a different server, the webserver log parsing can be removed from cron jobs.