14

I am trying to monitor HTTP status with 404 or 403 page. As you all know Monit takes those pages as failed connection, but how could I change that. I just want to monitor that it shows the 404 or 403 page.

I need to check it with this config if its possible.

This is my check config:

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;'"
cr0c
  • 1,116
  • 3
  • 15
  • 32

2 Answers2

14

Since version 5.8, Monit has the status option:

STATUS option can be used to explicitly test the HTTP status code returned by the HTTP server. If not used, the http protocol test will fail if the status code returned is greater than or equal to 400. You can override this behaviour by using the status qualifier.

For example to test that a page does not exist (404 should be returned in this case):

if failed
   port 80
   protocol http
   request "/non/existent.php"
   status = 404
then alert
alex9311
  • 103
  • 3
n.st
  • 736
  • 5
  • 16
9

The status didn't work for me (monit 5.6). I think it's supported from 5.8?

I ended up with a script which uses 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

Then I added the following monit configuration

check program http-check with path "/etc/monit/bin/http-check.sh"
  if status != 0
  then alert
czerasz
  • 547
  • 1
  • 8
  • 14