用一个nagios插件,监控邮件队列中的邮件信息大小来做相应的警告。
对邮件队列的条目数和信息总量大小一起监控。
对于监控队列的条目数有一定的要求。
以下是该shell/ target=_blank class=infotextkey>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' | linuxjishu/13830.html target=_blank class=infotextkey>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
2,重启nrpe监控进程
3,在nagios主机上添加一条监控service
4,重启nagios服务,使配置生效。
前端效果,如下图: