使用 404 页面监控 http 状态

mYz*_*Yzk 13 http monit

我正在尝试使用 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;'"
Run Code Online (Sandbox Code Playgroud)

n.s*_*.st 14

从 5.8 版开始,Monit 有以下status选项

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

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

if failed
   port 80
   protocol http
   request "/non/existent.php"
   status = 404
then alert
Run Code Online (Sandbox Code Playgroud)


cze*_*asz 8

status没有为我工作(monit的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
Run Code Online (Sandbox Code Playgroud)

然后我添加了以下monit配置

check program http-check with path "/etc/monit/bin/http-check.sh"
  if status != 0
  then alert
Run Code Online (Sandbox Code Playgroud)