Monit Monitor 404页的HTTP状态


12

我正在尝试使用404或403页面监视HTTP状态。众所周知,Monit将这些页面视为失败的连接,但是我该如何更改。我只想监视它显示的是404还是403页面。

如果可能,我需要使用此配置进行检查。

这是我的检查配置:

check process httpd with pidfile /var/run/httpd.pid
  start program = "/etc/init.d/httpd start"
  stop program = "/etc/init.d/httpd stop"
    if failed host hostname port 80
    protocol HTTP request "/"
    then exec "/bin/bash -c '/bin/echo -e "hostname\thttpd\t3\tFAILED" | /usr/sbin/send_nsca -H nagiosserver -c /etc/send_nsca.cfg; /usr/bin/monit restart nginx;'"

Answers:


13

从5.8版开始,Monit可以status选择

STATUS选项可用于显式测试HTTP服务器返回的HTTP状态代码。如果未使用,则如果返回的状态码大于或等于400,则http协议测试将失败。您可以使用状态限定符来覆盖此行为。

例如,要测试一个页面是否不存在(在这种情况下应返回404):

if failed
   port 80
   protocol http
   request "/non/existent.php"
   status = 404
then alert

6

那个status对我不起作用(监测5.6)。我认为它从5.8开始受支持吗?

我最终得到了一个使用curl的脚本:

#!/bin/bash
# source: /etc/monit/bin/http-check.sh

url="http://user:password@domain.com/test_link/index.php"

response=$(curl -sL -w "%{http_code}\\n" $url | grep 404)

if [ "$response" = "404" ]
then
  exit 0
else
  exit 1
fi

然后我添加了以下monit配置

check program http-check with path "/etc/monit/bin/http-check.sh"
  if status != 0
  then alert
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.