当前位置: > Linux服务器 > 监控工具 >

nagios监控postfix队列的shell脚本分享(图文)

时间:2014-10-26 01:36来源:linux.it.net.cn 作者:it

用一个nagios插件,监控邮件队列中的邮件信息大小来做相应的警告。
对邮件队列的条目数和信息总量大小一起监控。
对于监控队列的条目数有一定的要求。

以下是该shell脚本的完整内容。
 

复制代码代码示例:

[root@mail ~]# cat /usr/local/nagios/libexec/check_postque
#!/bin/bash
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3

if [ "$#" == "10" ]
then
#Set variables
arg=${10}
w=$2
c=$4
W=$6
C=$8
mt="Mail queue is empty"

emp=`postqueue -c /etc/$arg -p`
if [ "$emp" = "$mt" ]; then
echo "OK : $mt"
exitstatus=$STATE_OK
else

crt=`postqueue -c /etc/$arg -p | grep Kbytes | sed -e 's/^.*--.//g' | awk '{print $1}'`
mg=`postqueue -c /etc/$arg -p | grep Kbytes | sed -e 's/^.*--.//g' | awk '{print $4}'`

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" ]
[[ $mg < $c  ||  $crt < $C ]]
then

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."
exitstatus=$STATE_OK
fi
fi

else
echo " "
echo "Please provide parameters to work with."
echo "Help : ./check_postque -w 20 -c 30 -W 1000000 -C 3000000 -p postfix"
echo "Where :"
echo "       -w = Request Warning limit"
echo "       -c = Request Critical limit"
echo "       -W = Message size Warning limit"
echo "       -C = Message size Critical limit"
echo "       -p = Postfix instance name"
echo " "

fi
exit $exitstatus

应用操作步骤:
1,修改nrpe.cfg文件,增加监控command
 

复制代码代码示例:
[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

前端效果,如下图:
nagios

(责任编辑:IT)
------分隔线----------------------------