1,首先咱们先得在/usr/local/nagios/etc/object/command.cfg 关于check_http的指令的配置!

}

define command{
command_name check_http
command_line $USER1$/check_http -H $HOSTADDRESS$ $ARG1$
}

2,监控主机设定文件

}

define host{
use linux-server (继承模板中linux-server的监控参数)
host_name source.rui.com (主机名称)
alias source.ruicom (主机别名)
address source.rui.com(IP地址)

}

}
define service {
use generic-service
host_name source.rui.com
service_description Core-source.rui.com
contact_groups ops_admin
check_command check_http!-H source.rui -u '/opsmon/opsmon.htm' -s 'Qunar OPS monitor page' -A 'nagios cn1'

}

注释:在这里 主机名就是source.rui ,URL是'/opsmon/opsmon.htm' ,整个URL就是www.source.rui.com/opsmon/opsmon.htm' !!!!!!!!!

3,这里介绍一下监控http服务参数描述

check_http -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>][-w <warn time>] [-c <critical time>] [-t <timeout>] [-L][-a auth] [-f <ok | warn | critcal | follow>] [-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] [-C <age>] [-T <content-type>]

常用参数-H 用于虚拟主机,并可以增加端口。例如,test.com:10000-I IP地址-S 基于SSL连接。默认端口为443 -u URL地址 -w 警告响应时间 响应时间超过指定时间则显示WARNING-c 临界报警响应时间 响应时间超过设定时间则显示CRITICAL-p 端口设定-e 监测服务器反馈的第一行(状态)信息是否包含匹配字符-N 不读取body部分,在读取header信息 -t timeout时间值 -v 显示服务器反馈的所有信息 -r 正则表达式匹配反馈页信息-R 同上,但可以不考虑大小写问题--invert-regex 反馈信息中包含字符则报警-L 反馈信息包含URL link-a 对需要基础认证的,提供用户名和密码,获取反馈值

}

举例:1.监控192.168.9.4机器http服务使用情况/usr/lib64/nagios/plugins/check_http -I 192.168.9.4HTTP OK: HTTP/1.1 302 Found – 619 bytes in 0.009 second response time |time=0.008873s;;;0.000000 size=619B;;;02.监控192.168.120.2机器http9090端口服务的使用情况/usr/lib64/nagios/plugins/check_http -I 192.168.120.2 -p 9090HTTP WARNING: HTTP/1.1 403 Forbidden3.监控192.168.120.2机器http9090端口服务的使用情况,当http返回200,403时,nagios返回OK/usr/lib64/nagios/plugins/check_http -I 192.168.120.2 -p 9090 -e 403,200HTTP OK HTTP/1.1 403 Forbidden – 389 bytes in 0.004 seconds |time=0.003794s;;;0.000000 size=389B;;;04.监测www.twitter.com能否访问;/usr/lib64/nagios/plugins/check_http -H www.twitter.comCRITICAL – Socket timeout after 10 seconds5.监测http://123.112.137.221:10009/nagios/能否访问;/usr/lib64/nagios/plugins/check_http -I 123.112.137.221 -p 10009 -u /nagios/HTTP WARNING: HTTP/1.1 401 Authorization6.检测http://www.abc.com/search.aspx?name=abc&id=100能否访问/usr/lib64/nagios/plugins/check_http -H www.abc.com -u “/search.aspx?name=abc&id=100″HTTP OK: HTTP/1.1 301 Moved Permanently – 486 bytes in 0.567 second response time |time=0.567176s;;;0.000000 size=486B;;;0