I am running M/Monit 5.14 on Debian Jessie. I have a check like this:
check program myscript with path "/etc/monit/scripts/test.sh"
if status != 0 then exec "/etc/monit/scripts/record_failure.sh"
if status == 0 then exec "/etc/monit/scripts/record_success.sh"
The idea is that these record
scripts will send a record of the result of this test every time it runs. Sure, there are other ways to do this, but this is just a particular route I took in this case. I'm more concerned with the fact that adding the status == 0
line makes the monit check always fail, even though the last result in monit status
is 0
and record_success.sh
is being run.
There's nothing about this documented on the site. Is it failing the check because there is a matching condition, or did I mess up the syntax?
Although this is an old post, I just came accross the same issue and it would have been helpful to have a solution.
According to the Serivce Testing General Syntax the right structure to check for testing a program should be
IF <test> THEN <action> [ELSE IF SUCCEEDED THEN <action>]
As you can see, the successful case (0 by convention) should be specified by the succeeded
keyword.
In this case the following change should make it happy:
check program myscript with path "/etc/monit/scripts/test.sh"
if status != 0 then exec "/etc/monit/scripts/record_failure.sh"
else if succeeded then exec "/etc/monit/scripts/record_success.sh"