用一个nagios插件,监控邮件队列中的邮件信息大小来做相应的警告。
以下是该shell脚本的完整内容。
复制代码代码示例:
[root@mail ~]# cat /usr/local/nagios/libexec/check_postque
if [ "$#" == "10" ]
emp=`postqueue -c /etc/$arg -p`
crt=`postqueue -c /etc/$arg -p | grep Kbytes | sed -e 's/^.*--.//g' | awk '{print $1}'` if [[ $mg > $c || $crt > $C ]] then echo "Critical : Queue has $mg messages in $crt Kbytes, higher then critical limit." exitstatus=$STATE_CRITICAL elif
# [ "$mg" -gt "$w" -o "$crt" -gt "$W" ] echo "Warning : Queue has $mg messages in $crt Kbytes, higher then warning limit." exitstatus=$STATE_WARNING else
echo "OK : Mail queue has $mg messages in $crt Kbytes."
else
fi
应用操作步骤:
复制代码代码示例:
[root@mail ~]# grep post /usr/local/nagios/etc/nrpe.cfg
command[check_postque]=/usr/local/nagios/libexec/check_postque -w 10 -c 30 -W 3000000 -C 5000000 -p postfix #队列数大于10告警,30严重告警。邮件大小总计300M告警,邮件大小总计500M严重告警
2,重启nrpe监控进程
复制代码代码示例:
[root@mail ~]# ps aux |grep nrpe|grep -v "grep" |awk '{print $2}'|xargs kill -9;/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
3,在nagios主机上添加一条监控service
复制代码代码示例:
[root@nagios ~]# tail -6 /usr/local/nagios/etc/objects/services/mail.cfg
define service{ use generic-service host_name mail service_description check_postque check_command check_nrpe!check_postque }
4,重启nagios服务,使配置生效。
复制代码代码示例:
[root@nagios ~]# /etc/init.d/nagios restart
前端效果,如下图: |