最新消息:

使用Zabbix监控Postfix

Zabbix admin 6164浏览 0评论

使用Zabbix监控Mysql
使用Zabbix监控Mongodb
使用Zabbix监控Postfix

操作系统:Centos 5.5 x86_64

Zabbix版本:1.8.1

1.安装pflogsumm
下载地址:http://jimsun.linxnet.com/postfix_contrib.html

perl -MCPAN -e “install Date::Calc”

tar xvf pflogsumm-1.1.3.tar.gz
cd pflogsumm-1.1.3
cp pflogsumm.pl /usr/local/bin/pflogsumm
chmod 755 /usr/local/bin/pflogsumm
cp pflogsumm.1 /usr/local/man/man1/pflogsumm.1
chmod 644 /usr/local/man/man1/pflogsumm.1

2.安装logtail
rpm包可以到这里下载:http://rpm.pbone.net/index.php3/stat/3/limit/2/srodzaj/1/dl/40/search/logtail/field%5B%5D/1/field%5B%5D/2

rpm -ivh http://mirrors.sohu.com/fedora-epel/5Server/x86_64/epel-release-5-4.noarch.rpm
yum -y install logcheck.noarch

3.zabbix客户端配置文件
最后增加:
UserParameter=postfix.mailq,mailq | grep -v “Mail queue is empty” | grep -c ‘^[0-9A-Z]’

4.建立一个脚本
# cat /usr/local/zabbix/sbin/zabbix-postfix.sh
#!/bin/bash
MAILLOG=/var/log/maillog
DAT1=/tmp/zabbix-postfix-offset.dat
DAT2=$(mktemp)
PFLOGSUMM=/usr/local/bin/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/local/zabbix/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 –bounce_detail=0 –deferral_detail=0 –reject_detail=0 –no_no_msg_size –smtpd_warning_detail=0 > $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

5.添加执行权限,并给zabbix用户授权
chmod +x /usr/local/zabbix/sbin/zabbix-postfix.sh

echo zabbix ALL = NOPASSWD: `which mailq` >> /etc/sudoers

6.添加一个计划任务
# crontab -e
#check postfix
*/30 * * * * /usr/local/zabbix/sbin/zabbix-postfix.sh

7.导入postfix_status模板

模板下载:postfix_stat.xml
configuration–>Templates–>Import Template

zabbix_postfix1

然后将模板里面的Item添加到相关的邮件服务器监控主机。
选择Template App Postfix–>Items–>选择所有的Item

zabbix_postfix2

选择Copy selected to…,选择Go(14),然后选择你的主机,将Item添加到要监控的主机里。

选择主机–>Graphs–>添加图形。

查看数据图:

zabbix_postfix3

 

参考:
http://www.zabbix.com/wiki/howto/monitor/mail/postfix/monitoringpostfix

http://www.zabbix.com/forum/showthread.php?t=7577

转载请注明:爱开源 » 使用Zabbix监控Postfix

您必须 登录 才能发表评论!