#/bin/bash
#Tool to Parse GWIA XML Log File
#written by Christian Mies
#written on 02/18/2006

GWIALogDir=$1

if [ $# -ne 1 ];
then
   echo Usage: check_gwiaRL /path/to/*.GWIA.003.xml/File
   exit 1
fi

if [ $1 = "--help" ];
then
   echo
   echo For using this Plugin you need the Product Redline and maybe a Mountpoint via NCP or SMB to your GW Server
   echo If anybody knows a possibility to connect to a SOAP Interface by BASH, please let me know by email:
   echo mail@etmiesje.de
   echo 
   echo Usage: check_gwiaRL /path/to/_*_.GWIA.003.xml_File
   echo

   echo written by Christian Mies
   exit 1
fi

test -d $GWIALogDir
if [ $? -ne 0 ];
then
   echo CRITICAL - $GWIALogDir is not reachable
   exit 2
fi


GWIAFILE=`find $GWIALogDir -type f | grep -i "GWIA"|cut -c 1-`


OUT=`egrep -i "gwiasmtpdMessagesOut" $GWIAFILE | cut -f 3 -d' '|cut -c 8- |head -1 | tr -d "\""`
IN=`egrep -i "gwiasmtpdMessagesIn" $GWIAFILE | cut -f 3 -d' '|cut -c 8- |head -1 | tr -d "\""`
ALL=$(expr $OUT + $IN)

echo OK - Incoming: $IN GW Mails, Outgoing $OUT GW Mails \| incoming=$IN\;\;\;\; outgoing=$OUT\;\;\;\;\;
