Monit使用404页面监视http状态

我正在尝试使用404或403页面监视HTTP状态。 大家都知道Monit把这些页面当作失败的连接,但是我怎么能改变这个页面。 我只想监视它显示404或403页面。

如果可能的话,我需要用这个configuration来检查它。

这是我的检查configuration:

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;'" 

从5.8版开始,Monit有status选项 :

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

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

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

status对我来说不起作用(monit 5.6)。 我认为它从5.8支持?

我结束了一个使用curl的脚本:

 #!/bin/bash # source: /etc/monit/bin/http-check.sh url="http://user:[email protected]/test_link/index.php" response=$(curl -sL -w "%{http_code}\\n" $url | grep 404) if [ "$response" = "404" ] then exit 0 else exit 1 fi 

然后我添加了下面的monitconfiguration

 check program http-check with path "/etc/monit/bin/http-check.sh" if status != 0 then alert