Chu*_*uck 1 web-services monitor nagios
我正在尝试使用Nagios的check_http插件监视Web服务.
我试图监控的网址包括url参数.
事实证明check_http插件在检查时会忽略url参数.
这是我的配置.
define command{
command_name check_http
command_line $USER1$/check_http -I $HOSTADDRESS$ $ARG1$
}
define service{
use local-service ; Name of service template to use
host_name pear
service_description HTTP
check_command check_http!-u http://pear.com/total?eId=12345&env=abcde
notifications_enabled 0
}
Run Code Online (Sandbox Code Playgroud)
尝试-u使用相对路径而不是完整URL 替换传入的值.
在此示例中,-H将提供hostname(),该主机名$HOSTADDRESS$取自主机定义的address字段pear.传递给-u参数的值应该是相对路径,例如:/total?eId=12345&env=abcde.我们将添加-u到check_http_with_args命令定义中,因此我们不必将它作为我们的服务定义中的参数的一部分传递.
define host {
host_name pear
alias pear
address pear.com
use linux-server
contact_groups admins
notification_interval 0
notification_period 24x7
notifications_enabled 1
register 1
}
define command{
command_name check_http_with_args
command_line $USER1$/check_http -H $HOSTADDRESS$ -u $ARG1$
}
define service {
service_description pear_total_http
use generic-service
check_command check_http_with_args!/total?eId=12345&env=abcde
host_name pear
contact_groups admins
notification_interval 0
notification_period 24x7
notifications_enabled 1
flap_detection_enabled 1
register 1
}
Run Code Online (Sandbox Code Playgroud)
最后,Nagios执行的命令应该转换成如下所示的内容:
/usr/local/nagios/libexec/check_http -H pear.com -u /total?eId=12345&env=abcde
Run Code Online (Sandbox Code Playgroud)
您可以尝试从命令行执行上述操作,以确保它适合您.
注意:将路径替换为check_httpNagios服务器上与安装位置对应的实际路径.
check_http我们引用的手册页的相关部分:
Run Code Online (Sandbox Code Playgroud)-H, --hostname=ADDRESS Host name argument for servers using host headers (virtual host) Append a port to include it in the header (eg: example.com:5000) ... -u, --url=PATH URL to GET or POST (default: /)
资料来源:https://www.monitoring-plugins.org/doc/man/check_http.html
编辑:
要从评论中回答您的问题,-k或者--header=将允许您传入标题.
Run Code Online (Sandbox Code Playgroud)-k, --header=STRING Any other tags to be sent in http header. Use multiple times for additional headers资料来源:https://www.monitoring-plugins.org/doc/man/check_http.html
因此,要指定Accept标头,我将修改以下内容:
define command{
command_name check_http_with_args
command_line $USER1$/check_http -H $HOSTADDRESS$ -u "$ARG1$" -k "$ARG2$"
}
define service {
service_description pear_total_http
use generic-service
check_command check_http_with_args!/total?eId=12345&env=abcde!Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
host_name pear
contact_groups admins
notification_interval 0
notification_period 24x7
notifications_enabled 1
flap_detection_enabled 1
register 1
}
Run Code Online (Sandbox Code Playgroud)
...添加-k "$ARG2$"到command_line所述的command定义和添加Accept: <MIME types>(例如Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8)与check_command所述的service定义.
另外,我包$ARG1$的-u "$ARG1$"部分command_line用双引号,因为我怀疑&的eId=12345&env=abcde是使shell认为命令结束前刚刚被终止&.用双引号括起参数应该使整个字符串看作一个完整的参数.
| 归档时间: |
|
| 查看次数: |
30426 次 |
| 最近记录: |