2

On debian jessie, I have configured monit to check for HAproxy particular port forwardings, and to restart it if failed like this:

check process haproxy with pidfile /run/haproxy.pid
   group www-data
   start program = "/bin/systemctl start haproxy.service"
   stop program = "/bin/systemctl stop haproxy.service"
   if failed port 8080 protocol http request "/checker" then restart
   if failed port 8081 protocol http request "/checker" then restart
   if failed port 8082 protocol http request "/checker" then restart
   if 8 restarts within 8 cycles then unmonitor

I know it is possible to setup noalert email in a particular check environment. I wonder if if it is possible to do the same for particular if within the same check. In this particular case I would like monit to alert me only if the check on port 8082 has failed, but not for the other 2.

I have tried to add something like this:

check process haproxy with pidfile /run/haproxy.pid
   group www-data
   start program = "/bin/systemctl start haproxy.service"
   stop program = "/bin/systemctl stop haproxy.service"
   if 8 restarts within 8 cycles then unmonitor

check host site-a with address localhost
  noalert email@address
  depends haproxy
  if failed port 8080 protocol http request "/checker" then exec "/usr/bin/monit restart haproxy"

check host site-b with address localhost
  noalert email@address
  depends haproxy
  if failed port 8081 protocol http request "/checker" then exec "/usr/bin/monit restart haproxy"

check host site-c with address localhost
  depends haproxy
  if failed port 8082 protocol http request "/checker" then exec "/usr/bin/monit restart haproxy"

This configuration works, but I need to exec monitlike an external program, and I wonder if there is a way to do it directly in an if constructwithin the same check. If I use the following, monit will start without complaining, but it does not consider the noalert instruct:

check process haproxy with pidfile /run/haproxy.pid
   group www-data
   start program = "/bin/systemctl start haproxy.service"
   stop program = "/bin/systemctl stop haproxy.service"
   if failed port 8080 protocol http request "/checker" then
     restart
     noalert email@address
   if failed port 8081 protocol http request "/checker" then
     restart
     noalert email@address
   if failed port 8082 protocol http request "/checker" then restart
   if 8 restarts within 8 cycles then unmonitor

Any idea?

Best regards

0

You must log in to answer this question.

Browse other questions tagged .