XWall · The Mail Filter
MRTG (Multi Router Traffic Grapher)

XWall has an interface to collect real time statistic data that can be used to feed another program which then creates a graphic out of the data.

The state-of-the-art program for this purpose is MRTG (Multi Router Traffic Grapher).

MRTG generates HTML pages containing GIF images which provide a LIVE visual representation of XWall's data. More info on MRTG at http://people.ee.ethz.ch/~oetiker/webtools/mrtg.

Live demo of MRTG and XWall

How it works
A Perl script opens a connection on port 25 to XWall and sends a special ESMTP command. XWall will then return the current data as a delimited list of values. The Perl script parses the return value and extract two of the values and outputs them in such a way that MRTG accepts the data as an input for the graph.

A sample connection looks like:

Connection opened by yourmrtg.domain.com [10.0.0.1]
> 220 yoursrv.domain.com ESMTP XWall
< HELO yourmrtg.domain.com
> 250 yoursrv.domain.com
< XBMRTG
> 250 326127,0,1143,240,7677,5035316,626304505,0,13,0
< QUIT
> 221 closing transmission channel
Connection closed with yourmrtg.domain.com [10.0.0.1]

XWall configuration

By default XWall does not allow access to the data. To allow access you need to add the following lines to XWall.ini.

MRTG=True
MRTGAllowIP=10.0.0.1

Note: Substitute 10.0.0.1 with the IP address of your MRTG machine.

Installation - (MRTG is already installed and working):

Download mrtg.zip

Extract GetMRTG.pl file to c:\mrtg\run

Extract sample-mrtg.cfg to c:\mrtg\bin

Inside the sample-mrtg.cfg file, replace all instances of yourserver.yourdomain.com with the hostname of the XWall server

Merge sample-mrtg.cfg into your existing mrtg.cfg

On the XWall server, add the commands from sample.ini to XWall. ini to permit MRTG to query the XWall server

Run MRTG, usually by using a command line like

"C:\Program Files\Perl\bin\Perl.exe" C:\mrtg\bin\mrtg C:\mrtg\run\mrtg.cfg
"C:\Program Files\
Perl\bin\Perl.exe"
C:\mrtg\bin\mrtg
C:\mrtg\run\mrtg.cfg

Look for new html files in the c:\mrtg\html folder

Installation - (MRTG is not installed):

Download and extract MRTG to c:\mrtg

Download and install ActivePerl

Under the c:\mrtg folder, create a folder called html and another called run

Download mrtg.zip

Extract GetMRTG.pl file to c:\mrtg\run

Extract sample-mrtg.cfg to c:\mrtg\bin

Rename sample-mrtg.cfg to mrtg.cfg

Inside the mrtg.cfg file, replace all instances of yourserver.yourdomain.com with the hostname of the XWall server

On the XWall server, add the commands from sample.ini to XWall. ini to permit MRTG to query the XWall server

From a command line in the c:\mrtg\bin folder, type

perl.exe mrtg mrtg.cfg

Look for new html files in the c:\mrtg\html folder

Make sure

perl.exe mrtg mrtg.cfg

is running every 5 minutes or else the graphs will not update

MRTG.CFG configuration

A sample MRTG.CFG file:

# Todo:
#
# - Change yourserver.yourdomain.com to the name of the
# machine where XWall is running
#
# - Change C:\mrtg\HTML if necessary
#
# - Change C:\mrtg\run\getmrtg.pl if necessary
#
#

WorkDir: C:\mrtg\HTML\
Interval:5

# Global Definitionen
Kilo[_]: 1024

#
# Inbound and outbound SMTP queue
#
Target[xwall.qc]: `C:\mrtg\run\getmrtg.pl yourserver.yourdomain.com 1 2`
Options[xwall.qc]: gauge , absolute , unknaszero , nopercent , noinfo , integer
MaxBytes[xwall.qc]: 100000
YLegend[xwall.qc]: SMTP-Queue
ShortLegend[xwall.qc]: Msg
Legend1[xwall.qc]: Inbound SMTP-Queue
Legend2[xwall.qc]: Outbound SMTP-Queue
LegendI[xwall.qc]: &nbsp;In:&nbsp;
LegendO[xwall.qc]: &nbsp;Out:&nbsp;
Title[xwall.qc]: yourserver.yourdomain.com - XWall
PageTop[xwall.qc]: <H1>XWall - SMTP-Queue - yourserver.yourdomain.com</H1>

#
# Inbound and outbound Exchange queue
#
Target[xwall.eqc]: `C:\mrtg\run\getmrtg.pl yourserver.yourdomain.com 15 16`
Options[xwall.eqc]: gauge , absolute , unknaszero , nopercent , noinfo , integer
MaxBytes[xwall.eqc]: 100000
YLegend[xwall.eqc]: Exch-Queue
ShortLegend[xwall.eqc]: Msg
Legend1[xwall.eqc]: Incoming Exch-Queue
Legend2[xwall.eqc]: Outbound Exch-Queue
LegendI[xwall.eqc]: &nbsp;In:&nbsp;
LegendO[xwall.eqc]: &nbsp;Out:&nbsp;
Title[xwall.eqc]: yourserver.yourdomain.com - XWall
PageTop[xwall.eqc]: <H1>XWall - Exch-Queue - yourserver.yourdomain.com</H1>

#
# Inbound and outbound SMTP connection count
#
Target[xwall.cc]: `C:\mrtg\run\getmrtg.pl yourserver.yourdomain.com 7 8`
Options[xwall.cc]: gauge , absolute , unknaszero , nopercent , noinfo , integer
MaxBytes[xwall.cc]: 100000
YLegend[xwall.cc]: Connections
#ShortLegend[xwall.cc]: Connections
ShortLegend[xwall.cc]: c
Legend1[xwall.cc]: Incoming Connections
Legend2[xwall.cc]: Outbound Connections
LegendI[xwall.cc]: &nbsp;In:&nbsp;
LegendO[xwall.cc]: &nbsp;Out:&nbsp;
Title[xwall.cc]: yourserver.yourdomain.com - XWall
PageTop[xwall.cc]: <H1>XWall - Connections - yourserver.yourdomain.com</H1>

#
# Inbound and outbound SMTP message per hour
#
Options[xwall.mc]: nopercent , noinfo , integer , perhour
Target[xwall.mc]: `C:\mrtg\run\getmrtg.pl yourserver.yourdomain.com 3 4`
MaxBytes[xwall.mc]: 300000
YLegend[xwall.mc]: Messages/hour
ShortLegend[xwall.mc]: Messages/hour
Legend1[xwall.mc]: Inbound Messages
Legend2[xwall.mc]: Outbound Messages
LegendI[xwall.mc]: &nbsp;In:&nbsp;
LegendO[xwall.mc]: &nbsp;Out:&nbsp;
Title[xwall.mc]: yourserver.yourdomain.com - XWall
PageTop[xwall.mc]: <H1>XWall - Messages - yourserver.yourdomain.com </H1>

#
# Spam and block message per hour
#
Options[xwall.sc]: nopercent , noinfo , integer , perhour
Target[xwall.sc]: `C:\mrtg\run\getmrtg.pl yourserver.yourdomain.com 25 26`
MaxBytes[xwall.sc]: 300000
YLegend[xwall.sc]: Messages/hour
ShortLegend[xwall.sc]: Messages/hour
Legend1[xwall.sc]: Blocked Messages
Legend2[xwall.sc]: Spam Messages
LegendI[xwall.sc]: &nbsp;Block:&nbsp;
LegendO[xwall.sc]: &nbsp;Spam:&nbsp;
Title[xwall.sc]: yourserver.yourdomain.com - XWall
PageTop[xwall.sc]: <H1>XWall - Spam - yourserver.yourdomain.com </H1>

#
# Greylisting message per hour
#
Options[xwall.gc]: nopercent , noinfo , integer , perhour
Target[xwall.gc]: `C:\mrtg\run\getmrtg.pl yourserver.yourdomain.com 27 28`
MaxBytes[xwall.gc]: 300000
YLegend[xwall.gc]: Messages/hour
ShortLegend[xwall.gc]: Messages/hour
Legend1[xwall.gc]: Greylisting Messages
Legend2[xwall.gc]: Not Used
LegendI[xwall.gc]: &nbsp;Grey:&nbsp;
LegendO[xwall.gc]: &nbsp;NU:&nbsp;
Title[xwall.gc]: yourserver.yourdomain.com - XWall
PageTop[xwall.gc]: <H1>XWall - Greylisting - yourserver.yourdomain.com </H1>


#
# Inbound and outbound SMTP byte count
#
Target[xwall.bc]: `C:\mrtg\run\getmrtg.pl yourserver.yourdomain.com 5 6`
Options[xwall.bc]: nopercent , noinfo , integer
MaxBytes[xwall.bc]: 10737418240
YLegend[xwall.bc]:
ShortLegend[xwall.bc]:
Legend1[xwall.bc]: Inbound Bytes
Legend2[xwall.bc]: Outbound Bytes
LegendI[xwall.bc]: &nbsp;In:&nbsp;
LegendO[xwall.bc]: &nbsp;Out:&nbsp;
Title[xwall.bc]: yourserver.yourdomain.com - XWall
PageTop[xwall.bc]: <H1>XWall - Bytes - yourserver.yourdomain.com </H1>

#
# Outbound SMTP rate
#
Target[xwall.ro]: `C:\mrtg\run\getmrtg.pl yourserver.yourdomain.com 23 24`
Options[xwall.ro]: gauge , absolute , nopercent , noinfo , integer
MaxBytes[xwall.ro]: 100
AbsMax[xwall.ro]: 1000
YLegend[xwall.ro]: Rate
ShortLegend[xwall.ro]: /1000
Legend1[xwall.ro]: Messages > 60 sec
Legend2[xwall.ro]: Messages > 900 sec
LegendI[xwall.ro]: &nbsp;&gt;&nbsp;60 sec:&nbsp;
LegendO[xwall.ro]: &nbsp;&gt;&nbsp;900 sec:&nbsp;
Title[xwall.ro]: yourserver.yourdomain.com - XWall
PageTop[xwall.ro]: <H1>XWall - Rate - yourserver.yourdomain.com </H1>
Perl script for MRTG (getmrtg.pl)

This is the Perl script to collect the data:

#
# Query XWAll for statistic values to feed into MRTG
#
#
# Call with: GetMRTG hostname InData OutData Verbose
#
# Sample ( w verbose ) : GetMRTG exchange.domain.com 3 4 1
# Sample ( w/o verbose ): GetMRTG exchange.domain.com 3 4
#
# InIndex and OutIndex can be one of:
#
# 1 InboundSMTPQueueCount
# 2 OutboundSMTPQueueCount
#
# 3 InboundSMTPMsgCount
# 4 OutboundSMTPMsgCount
# 5 InboundSMTPByteCount
# 6 OutboundSMTPByteCount
# 7 InboundSMTPConnectionCount
# 8 OutboundSMTPConnectionCount
#
# 9 InboundPOP3MsgCount
# 10 OutboundPOP3MsgCount
# 11 InboundPOP3ByteCount
# 12 OutboundPOP3ByteCount
# 13 InboundPOP3ConnectionCount
# 14 OutboundPOP3ConnectionCount
#
# 15 InboundExchQueueCount
# 16 OutboundExchQueueCount
#
# 17 InboundExchByteCount
# 18 OutboundExchByteCount
# 19 InboundExchMsgCount
# 20 OutboundExchMsgCount
# 21 InboundExchConnectionCount
# 22 OutboundExchConnectionCount
#
# 23 OutboundSMTPRate1
# 24 OutboundSMTPRate1
#
# 25 InboundSMTPMsgBlockCount
# 26 InboundSMTPMsgSpamCount
#
# 27 InboundSMTPGreyCount
# 28 NotUsed
#
# 29 InboundVirusCount
# 30 OutboundVirusCount
#

use Socket;
use Text::ParseWords;
use POSIX qw(strftime);

( $Host , $InIndex , $OutIndex , $Verbose ) = @ARGV ;

$Verbose = 0 unless $Verbose ;
$Port = 25 ;

$Proto = (getprotobyname('tcp'))[2];

$ThisAddr = (gethostbyname(""))[4];
$ThisHost = gethostbyaddr($ThisAddr, AF_INET);
$SMTPAddr = (gethostbyname($Host))[4];

#$this = pack('Sna4x8', AF_INET, 0, $ThisAddr);
$smtp = pack('Sna4x8', AF_INET, $Port, $SMTPAddr);

if ( $Verbose )
{
print " Host: $Host\n" ;
print " InIndex: $InIndex\n" ;
print "OutIndex: $OutIndex\n" ;
}

if (!socket(S, AF_INET, SOCK_STREAM, $Proto)) { die $!; }
#if (!bind(S, $this)) { die $!; }
if (!connect(S, $smtp)) { die $!; }

$oldfh = select(S); $| = 1; select($oldfh);

if (eof(S))
{
print "Unable to read from Port";
exit(-1);
}

# get the greeting line
$Greeting = <S>; if (/^[45]/) { close S; die "$_\n"; }

if ( $Verbose )
{
print "$Greeting";
}
# Remove the first 4 chars from gretting ( "220 " )
$Greeting = substr( $Greeting , 4 ) ;


# Send HELO
if ( $Verbose )
{
print "HELO $ThisHost\n";
}
print S "HELO $ThisHost\r\n";
$_ = <S>; if (/^[45]/) { close S; die "$_\n"; }
if ( $Verbose )
{
print "$_";
}


# Send command to get statistic
if ( $Verbose )
{
print "XBMRTG\n";
}
print S "XBMRTG\r\n";


# Get the values
$_ = <S>; if (/^[45]/) { close S; die "$_\n"; }
if ( $Verbose )
{
print "$_";
}

# Filter OutIndex the one we need
# and print them to STDOUT
# Also save UpTime
$UpTime = 0 ;
$InData = 0 ;
$OutData = 0 ;

@words = &quotewords(',', 0, "$_");
$i = 0;
foreach (@words)
{
$UpTime = substr( $_ , 4 ) if ( $i == 0 ) ;
$InData = $_ if ( $i == $InIndex ) ;
$OutData = $_ if ( $i == $OutIndex ) ;
$i++;
}

# Disconnect from host
if ( $Verbose )
{
print "QUIT\n";
}
print S "QUIT\r\n";
$_ = <S>; if (/^[45]/) { close S; die "$_\n"; }
if ( $Verbose )
{
print "$_";
}

close S;

# Print values
print "$InData\n" ;
print "$OutData\n" ;

# Print UpTime
$Days = int( $UpTime / 86400 ) ;
if ( $Days > 0 )
{
print "$Days days ";
$UpTime -= ( $Days * 86400 ) ;
}
$UpTimeStr = strftime( "%H:%M:%S", gmtime( $UpTime ) ) ;
print "$UpTimeStr\n" ;
print "$Greeting\n" ;

You can download the sample files and the Perl script from here

© 1996-2017 DataEnter GmbH
Wagramerstrasse 93/5/10 A-1220 Vienna, Austria
support@dataenter.co.at
2017-01-04 / Phone
2017-01-04 / Tablet
Changed: 2017-01-04
Server
Desktop
Copyright © 1996-2017 DataEnter GmbH
Wagramerstrasse 93/5/10 A-1220 Vienna, Austria
Fax: +43 (1) 2020770
support@dataenter.co.at