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.
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
Any created a template with triggers and graphs for this script?
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
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..
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