7

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

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
6

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
  • 1
    You're right, status is only supported since version 5.8. (I've also added that to my answer.) – n.st Aug 19 '14 at 23:19

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.