If you use Postgrey (and you should do it) on your mail servers and you want to have some statistics on the amount of greylisted messages and other information, you should find useful the following script.

The scripts assume that you have installed Postgrey (http://postgrey.schweikert.ch/) on RHEL (http://www.redhat.com) or CentOS (http://www.centos.org).
If you are using other distros you may fix some path problems.

Create a file called “greylisting_statistics.sh” in your “/usr/local/bin” folder with the following content :



echo -n "Total amount of GreyListed messages" > $LOGFILE
cat /var/log/maillog | /usr/sbin/postgreyreport --delay=300 >> $LOGFILE
echo -ne  "n" >> $LOGFILE
echo -ne  "-------------------------------------n" >> $LOGFILE
echo -ne  "-------------------------------------n" >> $LOGFILE
echo -n "Get only the top 20 sources getting greylisted out" >> $LOGFILE
cat /var/log/maillog | postgreyreport | awk '{print $1}' | sort | uniq -c | sort -nr | head -n20 >> $LOGFILE
echo -ne  "n" >> $LOGFILE
echo -ne  "-------------------------------------n" >> $LOGFILE
echo -ne  "-------------------------------------n" >> $LOGFILE
echo -n "Get a list of the top 20 email address that the greylisted sources are sending email to"  >> $LOGFILE
cat /var/log/maillog | postgreyreport | awk '{print $4}'  | sort  | uniq -c | sort -nr | head -n20
echo -ne  "n" >> $LOGFILE
echo -ne  "-------------------------------------n" >> $LOGFILE
echo -ne  "-------------------------------------n" >> $LOGFILE

cat $LOGFILE | mail -s "Greylisting Statistics of `hostname` for `date +%Y-%m-%d`" $YOURMAIL
#--- End of file ---

Assign to it the correct ownership and permission by running :

chmod 700 /usr/local/bin/greylisting_statistics.sh
chown root:root /usr/local/bin/greylisting_statistics.sh

Schedule the execution using “crontab -e” and adding the following line to have a daily based statistics :

59 23 * * * /usr/local/bin/greylisting_statistics.sh

Hope this help


Print This Post Print This Post
Print Friendly, PDF & Email

Un Commento a “How-To create statistics for Greylisted messages using Postgrey”

Lascia un Commento

CAPTCHA * Time limit is exhausted. Please reload CAPTCHA.

3D Tags