Nagios监控虚拟主机的http服务

在nagios中提供有check_http命令模版,用来监控http服务是否存在。

这个命令模版的定义如下:

# 'check_http' command definition
define command{
command_name check_http
command_line $USER1$/check_http -I $HOSTADDRESS$ $ARG1$
}

可以看出,-I参数是基于主机的HOSTADDRESS(即IP地址)来监测,那么就有了这样一个问题:如果是虚拟主机,IP不可访问,只能用域名访问,如何监测?

运行check_http脚本

#/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] [-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>]

可见check_http中存在有 -H <vhost> ,用以监测虚拟主机。

具体实现方法如下:

1. vi commands.cfg
添加一个新的command:check_http_by_domain
去除-I $HOSTADDRESS参数,保留ARG1用以传递域名参数

define command{
command_name check_http_by_domain
command_line $USER1$/check_http $ARG1$
}

2. 编辑主机配置文件<yourhost>.cfg
修改check_http服务中的check_command
check_command check_http_by_domain!-H test.dbalife.com
通过在command name后追加“!”提示符来传递参数

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章