nagios监控fms(借助脚本)
修改后的脚本如下(需添加指示灯的状态)
# vi fms.sh
#!/bin/bash
Port=`netstat -ntpl | grep fmsadmin | grep -v "11110" | awk -F[:" "]+ '{print $5}'`
if [[ $Port == "1111" ]];then
echo "OK - fms is running"
exit 0
else
echo "CRITICAL - fms is down"
if [[ $Port == "1111" ]];then
echo "OK - fms is running"
exit 0
else
echo "CRITICAL - fms is down"
/sbin/service fms restart
exit 2
fi
exit 2
fi
:wq
注:0 指的是状态灯绿灯,2指的是红灯,黄灯不用 并且宕了之后再次check时就能自动重启
# cp fms.sh /usr/local/nagios/libexec
# chmod +x /usr/local/nagios/libexec/fms.sh
# mount /dev/cdrom /media/cdrom
# mount /dev/cdrom /media/cdrom
# rpm -ivh sudo-1.6.9pl7-3.el5.i386.rpm
# visudo
#Defaults requiretty (注释掉)
nagios ALL=(ALL) NOPASSWD:/usr/local/nagios/libexec/fms.sh (多个脚本的话设置多行)
:wq
# su - nagios -c 'sudo /usr/local/nagios/libexec/fms.sh' (看看执行是否成功)
# vi /usr/local/nagios/etc/nrpe.cfg
command[check_fms]=/usr/bin/sudo /usr/local/nagios/libexec/fms.sh
:wq
# killall nrpe
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
# vi /usr/local/nagios/etc/objects/ming.cfg
:wq
# su - nagios -c 'sudo /usr/local/nagios/libexec/fms.sh' (看看执行是否成功)
# vi /usr/local/nagios/etc/nrpe.cfg
command[check_fms]=/usr/bin/sudo /usr/local/nagios/libexec/fms.sh
:wq
# killall nrpe
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
# vi /usr/local/nagios/etc/objects/ming.cfg
define service{
use generic-service
host_name ming
service_description fms
check_command check_nrpe!check_fms
notifications_enabled 1
}
:wq
# service nagios restart
use generic-service
host_name ming
service_description fms
check_command check_nrpe!check_fms
notifications_enabled 1
}
:wq
# service nagios restart
本文转自linux博客51CTO博客,原文链接http://blog.51cto.com/yangzhiming/844136如需转载请自行联系原作者
yangzhimingg