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

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

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:

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


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

if [ "$response" = "404" ]
  exit 0
  exit 1

Then I added the following monit configuration

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.