Adding a postfix template to Zabbix

Submitted by rmiddle on Fri, 01/28/2011 - 17:52

I am switching over to Zabbix it just works better then Zenoss for me.  During the process I added in templates for postfix.  Those are outlined here.

<a href="http://www.zabbix.com/wiki/howto/monitor/mail/postfix/monitoringpostfix">This wiki article</a> and <a href="http://www.zabbix.com/forum/showthread.php?t=19723#post74271">This forum post</a>

To summarize what is there.

# You 1st install pflogsumm and logtail
apt-get install pflogsumm logtail

#Then add to /etc/zabbix/zabbix_agentd.conf and restart the agent.
nano -w /etc/zabbix/zabbix_agentd.conf 
<code>
UserParameter=postfix.mailq,mailq | grep -v "Mail queue is empty" | grep -c '^[0-9A-Z]'
</code>

#Then create the file 
nano -w /usr/local/sbin/zabbix-postfix.sh

<code>
#!/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
DEBUG=1

function zsend {
  key="postfix[`echo "$1" | tr ' -' '_' | tr '[A-Z]' '[a-z]' | tr -cd [a-z_]`]"
  value=`grep -m 1 "$1" $DAT2 | awk '{print $1}'`
  [ ${DEBUG} -ne 0 ] && echo "Send key \"${key}\" with value \"${value}\"" >&2
  /usr/bin/zabbix_sender -c $ZABBIX_CONF -k "${key}" -o "${value}" 2>&1 >/dev/null
}

/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 received
zsend delivered
zsend forwarded
zsend deferred
zsend bounced
zsend rejected
zsend held
zsend discarded
zsend "reject warnings"
zsend "bytes received"
zsend "bytes delivered"
zsend senders
zsend recipients

rm $DAT2
</code>

#Then chmod the file.
chmod 700 /usr/local/sbin/zabbix-postfix.sh

#Then add a cron entry for it.  The site says every 30 min.  I am doing it every min as my servers are busier to get more data into the system.
nano -w /etc/cron.d/zabbix_postfix

<code>
* * * * * root   /usr/local/sbin/zabbix-postfix.sh
</code>

#Depending on your setup you might need to allow sudo access.
echo zabbix ALL = NOPASSWD: `which mailq` >> /etc/sudoers

#Then import the attached file as a <a href="http://www.middleswarth.us/wp-content/uploads/2014/04/postfix_stat.xml_.txt">template (postfix_stat.xml)</a>.

Although this is a good start this template has no triggers or graphic's attached to it so I will need to add those in at some point.
 

tax_term_view
Category Tags
Linux Linux