|
本帖最后由 eecdc 于 2014-3-28 09:25 编辑
前一段时间在Cu论坛发现一个提问,问题是nagios关于检测主机http服务的.楼主刚开始想实 现的是检测主机的url是否正常,后来有回复用自定义脚本的.经过搜索,发现nagios自带的check_http命令可以使用-u url的方式来检测url的.经过试验,确实是可行的,发帖纪录下.
1.先运行check_http命令看下是否支持-u参数,注意返回的显示里面有没有
/usr/local/nagios/libexec/check_http
check_http: Could not parse arguments
Usage:
check_http -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]
[-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-a auth]
[-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]
[-e <expect>] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]
[-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]
[-A string] [-k string] [-S <version>] [--sni] [-C <warn_age>[,<crit_age>]]
[-T <content-type>] [-j method]
2.自定义一个command,名字随便起,我这里是check_http_u,当然了,我写的简单,你也可以加-w和-c等参数
define command{
command_name check_http_u
command_line $USER1$/check_http -I $HOSTADDRESS$ -u $ARG1$
}
3.给已经定义过的主机添加一个自定义服务,我这里写成URL1,你可以根据需要修改成其他的.
define service{
use local-service ; Name of service template to use
host_name xxx ;前面定义好的主机名
service_description URL1 ;
check_command check_http_u!'/path/index.html' ;
notifications_enabled 1;
}
4. 重启nagios服务,重启没有错误的话,浏览器访问你的nagios服务,过一段时间,就可以看到检测的结果了.
|
|