当前位置: 首页 > others > 正文

nagios check_http 处理返回码302的情况

nagios check_http 处理返回码302的情况

使用nagios监控中发现这样一个问题,nagios的check_http对http返回码302的处理比较特殊,如果参数不当的话会影响监控的效果哦!

实际情况如下:
在web服务器配置的errpage页面指定了503跳转,如apache+resin的组合,如果apache找不到resin会返回503,捕获的页面会跳转到指定的页面上

1、正常情况:
/home/nagios/libexec/check_http -S -H 2hei.net -I 10.10.10.10 -u “/monitor.jsp” -P “” -s “OK”  -t 10
返回
HTTP OK HTTP/1.1 200 OK – 617 bytes in 0.345 seconds |time=0.345145s;;;0.000000 size=617B;;;0

如果页面返回值不包含“OK”,则
HTTP CRITICAL – string not found|time=0.034220s;;;0.000000 size=617B;;;0

如果停掉保留apache不动,停掉resin,则以外发生了,302跳转后状态仍然是OK,I服了U !!!
HTTP OK – HTTP/1.1 302 Found – 0.030 second response time |time=0.029908s;;;0.000000 size=517B;;;0

加入-v 参数后 看看详细结果:
https://2hei.net:443/monitor.jsp is 517 characters
STATUS: HTTP/1.1 302 Found
**** HEADER ****
Date: Wed, 16 Dec 2009 07:49:53 GMT
Server: Apache
Location: https://2hei.net/errorcode/503.html
Cache-Control: max-age=0
Expires: Wed, 16 Dec 2009 07:49:53 GMT
Vary: Accept-Encoding
Content-Length: 220
Connection: close
Content-Type: text/html; charset=iso-8859-1
**** CONTENT ****
<!DOCTYPE HTML PUBLIC “-//IETF//DTD HTML 2.0//EN”>
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href=”https://2hei.net/errorcode/503.html”>here</a>.</p>
</body></html>

HTTP OK – HTTP/1.1 302 Found – 0.030 second response time |time=0.029908s;;;0.000000 size=517B;;;0

丫难道是nagios check_http的bug?

在仔细看看nagios check_http 用法:

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>]

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

尝试使用了-e参数,问题搞定! yeah !!!

-e 指定check_http返回的第一行status中包含的字符串
STATUS: HTTP/1.1 302 Found

/home/nagios/libexec/check_http -S -H 2hei.net -I 10.10.10.10 -u “/monitor.jsp” -P “” -s “OK”  -t 10 -e “200”
这样只有返回码包含200的才会OK,其他状态码一律FATAL!
最后的command如下:
define command{
        command_name    check_https
        command_line    $USER1$/check_http -S -H $ARG1$ -I $HOSTNAME$ -u $ARG2$ -P $ARG3$ -s $ARG4$ -t $ARG5$ -e $ARG6$
        }

nagios的check_http果然很牛X。

本文固定链接: https://www.2hei.net/2009/12/16/nagios_check_http_302/ | 2hei.net

该日志由 u2 于2009年12月16日发表在 others 分类下,
原创文章转载请注明: nagios check_http 处理返回码302的情况 | 2hei.net

报歉!评论已关闭.