Tuesday, June 21, 2016

[Zabbix] How to monitor Postfix data on Zabbix 3.0


1. Import template from: https://raw.githubusercontent.com/incognico/scripts/master/zabbix/postfix/smtp_and_postfix_passive_checks_zabbix_template.xml or http://pastebin.com/akwa89gG

2. Enable Remote Commands in Agent Config
3. In /etc/zabbix/zabbix_agentd.d/userparameter_postfix.conf :
UserParameter=postfix.pfmailq,mailq | grep -c '^[0-9A-Z]'
UserParameter=postfix[*],/usr/local/bin/postfix-zabbix-stats.bash $1
4. Install logtail and pflogsumm
5. crontab -e : */5 * * * * root PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin && $(which logtail) /var/log/maillog > /tmp/logtailoffset && $(which pflogsumm) /tmp/logtailoffset -h 0 -u 0 --bounce_detail=0 --deferral_detail=0 --reject_detail=0 --no_no_msg_size --smtpd_warning_detail=0 > /tmp/pflogsummoffset && chown zabbix:zabbix /tmp/pflogsummoffset
6. Add /usr/local/bin/postfix-zabbix-stats.bash and chmod+x it.
 #!/bin/bash  
pfkey=$(echo "$1" | tr '_' ' ')

if [ "$pfkey" = "bytes received" ]; then
        number=$(cat /tmp/pflogsummoffset | grep -e 'bytes received' | cut -c1-7 | xargs)
        echo "$(($number *1024))"
elif [ "$pfkey" = "bytes delivered" ]; then
        number=$(cat /tmp/pflogsummoffset | grep -e 'bytes delivered' | cut -c1-7 | xargs)
        echo "$(($number *1024))"
else
        cat /tmp/pflogsummoffset | grep -E $pfkey | cut -c1-7 | head -1 | xargs
fi


No comments:

Post a Comment