ODT Export
 

Postfix Statistics with Zabbix

This is a nice way to take postfix mail stats and input them into Zabbix.

There are a few shortcomings to this method as for data representation, but it is still a very efficient way to get the data into zabbix on busy mail servers.

Needed programs:

Install steps:

  1. Install pflogsumm and logtail on the host you want to monitor
  2. Create items in zabbix for pfreceived, etc etc (as you see in the bash script below). Remember we are using zabbix_sender so the items have to be of type “ZABBIX trapper”
  3. Save the bash script onto the host you want to monitor and modify the script where necessary
  4. Create a crontab line as described below
  5. Update zabbix_agentd.conf per below and create associated item as active check.

CODE

crontab line:

0/30 * * * * root   /usr/local/sbin/zabbix-postfix.sh

zabbix-postfix.sh:

#!/bin/bash
 
MAILLOG=/var/log/mail.log
DAT1=/tmp/zabbix-postfix-offset.dat
DAT2=$(mktemp)
PFLOGSUMM=/usr/sbin/pflogsumm
ZABBIX_CONF=/etc/zabbix/zabbix_agentd.conf
 
function zsend {
  /usr/bin/zabbix_sender -c $ZABBIX_CONF -k $1 -o $2
}
 
/usr/sbin/logtail -f$MAILLOG -o$DAT1 | $PFLOGSUMM -h 0 -u 0 --no_bounce_detail --no_deferral_detail --no_reject_detail --no_no_msg_size --no_smtpd_warnings > $DAT2
 
zsend pfreceived `grep -m 1 received $DAT2|cut -f1 -d"r"`
zsend pfdelivered `grep -m 1 delivered $DAT2|cut -f1 -d"d"`
zsend pfforwarded `grep -m 1 forwarded $DAT2|cut -f1 -d"f"`
zsend pfdeferred `grep -m 1 deferred $DAT2|cut -f1 -d"d"`
zsend pfbounced `grep -m 1 bounced $DAT2|cut -f1 -d"b"`
zsend pfrejected `grep -m 1 rejected $DAT2|cut -f1 -d"r"`
zsend pfrejectwarnings `grep -m 1 "reject warnings" $DAT2|cut -f1 -d"r"`
zsend pfheld `grep -m 1 held $DAT2|cut -f1 -d"h"`
zsend pfdiscarded `grep -m 1 discarded $DAT2|cut -f1 -d"d"`
zsend pfbytesreceived `grep -m 1 "bytes received" $DAT2|cut -f1 -d"b"`
zsend pfbytesdelivered `grep -m 1 "bytes delivered" $DAT2|cut -f1 -d"b"`
 
rm $DAT2

zabbix_agentd.conf line:

UserParameter=pfmailq,mailq | grep -v "Mail queue is empty" | grep -c '^[0-9A-Z]'

Discussion

lauerdk, 2010/04/26 17:00

Any created a template with triggers and graphs for this script?

frater, 2010/10/23 12:58

Nice this logtail. I didn't know it existed and wrote the same thing in bash a while ago. Always funny to see you've reinvented the wheel.

I'm now always using my lastmins function which uses the timestamp (http://www.linuxquestions.org/questions/linux-software-2/show-last-10-minutes-of-the-log-836057), but this seems to fit in nicely as it's less time critical.

The only thing I altered was replacing the “cut -f1…” with “awk '{print $1}'” A bit more elegant.

Thanks… will try it

frater, 2010/10/25 14:22

If you want a template, take a look at this thread: http://www.zabbix.com/forum/showthread.php?p=74271 You need to use the script I altered..

bnaranjo, 2010/11/19 23:13

hi frater, i wonder if you can help me, i use your template and your script, but im unable to get the statistics in zabbix server, i've checked the logs and i couldn´t find anything to solve the problem, however if i run the script in the postfix server i can actually see the statitics, but i dont know the sender is not sending them to the zabbix server,

first i had a problem running the agentd (i had an error “can not chdir(/var/spool/clientmqueue/): Permission denied. Program mode requires special privileges, e.g., root or TrustedUser.”) due to file permission but with a chmod -R 755 /var/spool/mqueue i'solved it, after i had an error that cannot create /tmp/zabbix-postfix-offset.dat same permissions issue, fixed after chmod -R 777 /tmp, im not very savy with linux centos, thats why i dont know what else to do to make this work.

please help!!

Thank you

 
howto/monitor/mail/postfix/monitoringpostfix.txt · Last modified: 2010/02/05 19:27 by richlv
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki