不正狼 发表于 2019-1-16 11:25:49

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| -I[-u ] [-p ]
  [-w ] [-c ] [-t ] [-L]
  [-a auth] [-f ] [-e ]
  [-s string] [-l] [-r| -R ] [-P string]
  [-m :] [-4|-6] [-N] [-M ] [-A string]
  [-k string] [-S] [-C ] [-T ]
  可见check_http中存在有 -H,用以监测虚拟主机。
  具体实现方法如下:
  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. 编辑主机配置文件.cfg
  修改check_http服务中的check_command
  check_command check_http_by_domain!-H test.dbalife.com
  通过在command name后追加“!”提示符来传递参数

页: [1]
查看完整版本: Nagios监控虚拟主机的http服务