Search code examples
curlmonitormonit

monit only exec y if x is true


I'm trying to use monit to monitor a Confluence instance.

check process catalina with pidfile /usr/local/Confluence/work/catalina.pid
   start program = "/etc/init.d/confluence start"
   stop program = "/etc/init.d/confluence stop"
   if does not exist then
   ...
   if failed host confluence.dev.opt port 80 protocol http then
   ...
   else if succeeded then
   ...

Each of those if statements calls a separate bash script to send curl Requests to a status page that sends email updates to subscribers of said page.

Sometimes, catalina.pid can exist with a pid value in it but no one can connect, as if the process has become stale. However, if the confluence pid is actually missing then both the first and second checks will fail, as well as the third being executed twice, causing 4 separate curl requests to be executed, resulting in spam.

Is there any way that I can only execute the second check when the first check has passed?


Solution

  • You can use the depends on statement : https://mmonit.com/monit/documentation/monit.html#SERVICE-DEPENDENCIES

    Make sure also to seperate your checks into tiny checks.