# Xmailgraph 0.2 - statistics by rrdtool of xmailserver
# released under the GNU General Public License
#
# copyright (c) 2004-04-20 waaf.net computing gbr
#
# see http://dev.waaf.net/
#
# Changes:
#
# v0.1
# 2003-10-24    Achim Schmidt <schmidt@waaf.net>
# 2003-10-30    Achim Schmidt <schmidt@waaf.net>
# - Now greps all logfiles of the actual year
# - SNDR=EIPMAP lines inside smtp-log is recognized as spam
#
# 0.2
# 2003-11-30    Achim Schmidt <schmidt@waaf.net>
# - Added Feature of counting viruses logged inside antivirus-****
# 2003-04-20	Achim Schmidt <schmidt@waaf.net>
# - Added a line to xmailgraph.pl for grepping out "FWD" instead of "SMTP" - this
#   is needed, if a smarthost for smtp is set - thank to andreas_AT_bratell.com

-----------------------------------------------------------------------------
Before you start:

Check, that you have the following programms installed:
- "grep" (from gnu-utils) and "wc" (from gnu-coreutils)
- "xmailserver" with logging enabled from http://www.xmailserver.org/
- "rrdtool" (apt-get install rrdtool) from
  http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/
- additional xmailgraph can analyze the logfiles generated by
  SpamAssassin Filter from http://www.drakeconsult.com/xmail/
- additional xmailgraph can analyze the logfiles generated by
  AntiVirus Filter from http://www.lindeman.org/filters.html

-----------------------------------------------------------------------------
Installation:

0. You can use install.sh, which includes the default-installation steps (without 5-7)
   If You have 0.1 running please use update.sh.

   If You do so, please take a look at the script to use and ajust the vars!

1. copy the xmailgraph.pl to $MAIL_ROOT/bin/
   e.g. $ cp xmailgraph.pl /var/MailRoot/bin/

2. create a directory where the graphs and the webside can be accessed
   e.g. $ mkdir /var/www/xmailgraph

3. copy the html- & gif-files to the directory created in 2.
   e.g. $ cp *.html /var/www/xmailgraph/
        $ cp *.gif /var/www/xmailgraph/

4. Create the RRDs - best under $MAIL_ROOT/logs/ so they are backuped with
   the normal logfiles:
   e.g. (change /var/MailRoot/ to your $MAIL_ROOT) - run the following
   commands at console:

   rrdtool create /var/MailRoot/logs/WN_xmail_smtp.rrd --start -601 --step 600 \
    DS:sent:ABSOLUTE:1200:0:U DS:recv:ABSOLUTE:1200:0:U DS:bounce:ABSOLUTE:1200:0:U \
    RRA:AVERAGE:0.5:1:198 RRA:AVERAGE:0.5:7:198 RRA:AVERAGE:0.5:35:198 RRA:AVERAGE:0.5:385:198 \
    RRA:MAX:0.5:1:198 RRA:MAX:0.5:7:198 RRA:MAX:0.5:35:198 RRA:MAX:0.5:385:198

   rrdtool create /var/MailRoot/logs/WN_xmail_spam.rrd --start -601 --step 600 \
    DS:spam1:ABSOLUTE:1200:0:U DS:spam2:ABSOLUTE:1200:0:U \
    RRA:AVERAGE:0.5:1:198 RRA:AVERAGE:0.5:7:198 RRA:AVERAGE:0.5:35:198 RRA:AVERAGE:0.5:385:198 \
    RRA:MAX:0.5:1:198 RRA:MAX:0.5:7:198 RRA:MAX:0.5:35:198 RRA:MAX:0.5:385:198

   rrdtool create /var/MailRoot/logs/WN_xmail_pop3.rrd --start -601 --step 600 \
    DS:pop3:ABSOLUTE:1200:0:U \
    RRA:AVERAGE:0.5:1:198 RRA:AVERAGE:0.5:7:198 RRA:AVERAGE:0.5:35:198 RRA:AVERAGE:0.5:385:198 \
    RRA:MAX:0.5:1:198 RRA:MAX:0.5:7:198 RRA:MAX:0.5:35:198 RRA:MAX:0.5:385:198

   rrdtool create /var/MailRoot/logs/WN_xmail_antivirus.rrd --start -601 --step 600 \
    DS:virus:ABSOLUTE:1200:0:U \
    RRA:AVERAGE:0.5:1:198 RRA:AVERAGE:0.5:7:198 RRA:AVERAGE:0.5:35:198 RRA:AVERAGE:0.5:385:198 \
    RRA:MAX:0.5:1:198 RRA:MAX:0.5:7:198 RRA:MAX:0.5:35:198 RRA:MAX:0.5:385:198


5. Take a look at /var/MailRoot/bin/xmailgraph.pl and adjust the vars:
   my ($hostname) = "xmail.example.com";	# Hostname used inside graphs
   my ($dir_of_pngs) = "/var/www/xmailgraph/";	# Where to put the graphs
   my ($path_to_xmail_logs) = "/var/MailRoot/logs/";	# Where are the xmail-Logs
   my ($path_to_rrd) = "/var/MailRoot/logs/";		# Where are the RRDs located

   and others if needed (paths of rrdtool, ...)

6. Tell Cron-Daemon, that it should run xmailgraph.pl every 10 Minutes.
   e.g. add thge following line to /etc/crontab:
   */10 *     * * *   root    ( /var/MailRoot/bin/xmailgraph.pl 2>/dev/null )

7. Wait for about an hour and then go to http://$YOURHOSTNAME/xmailgraph/ or the according
   directory created in step 2.

Have a lot of fun...

- Achim Schmidt
http://achim.schmidt.tc
