nagios監(jiān)控http(借助腳本)
站在用戶的角度思考問題,與客戶深入溝通,找到武邑網(wǎng)站設(shè)計與武邑網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:網(wǎng)站設(shè)計制作、成都網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、國際域名空間、雅安服務(wù)器托管、企業(yè)郵箱。業(yè)務(wù)覆蓋武邑地區(qū)。
修改后的腳本如下(需添加指示燈的狀態(tài))
# vi httpd.sh
#!/bin/bash
Port=`netstat -ntpl | grep httpd | awk -F[:" "]+ '{print $4}'`
if [ $Port == "80" ];then
echo "OK - http is running"
exit 0
else
echo "CRITICAL - http is down"
/sbin/service httpd restart
exit 2
fi
:wq
注:0 指的是狀態(tài)燈綠燈,2指的是紅燈,黃燈不用 并且宕了之后再次check時就能自動重啟
# cp httpd.sh /usr/local/nagios/libexec
# chmod +x /usr/local/nagios/libexec/httpd.sh
# 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/httpd.sh (多個腳本的話設(shè)置多行)
:wq
# su - nagios -c 'sudo /usr/local/nagios/libexec/httpd.sh' (看看執(zhí)行是否成功)
# vi /usr/local/nagios/etc/nrpe.cfg
command[check_http]=/usr/bin/sudo /usr/local/nagios/libexec/httpd.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 http
check_command check_nrpe!check_http
}
:wq
# service nagios restart