Monit reports "status succeeded" when exit code changes from one failure to another

Issue #608 new
Lior Chen created an issue

I have a custom test with a configuration similar to the following:

 check program myscript with path /usr/local/bin/myscript.sh
       if status = 3 for 2 cycles then exec "reload.sh"
       if status = 4 for 2 cycles then exec "restart.sh"

Now, if my script exits with 3 it will execute the reload which usually solves the problem. but sometimes it doesn't solve the problem, but only causes the status code to change to "4" in the next cycle. The problem is, monit counts that as a "success" - because the status is no longer 3. In that case I will get a "status succeeded (4)" alert.

I believe the problem is on the "validate.c" file, on these lines:

if (Util_evalQExpression(status->operator, s->program->exitStatus, status->return_value)) {
        rv = State_Failed;
        Event_post(s, Event_Status, State_Failed, status->action, "status failed (%d) -- %s", s->program->exitStatus, StringBuffer_length(s->program->output) ? StringBuffer_toString(s->program->output) : "no output");
} else {
        Event_post(s, Event_Status, State_Succeeded, status->action, "status succeeded (%d) -- %s", s->program->exitStatus, StringBuffer_length(s->program->output) ? StringBuffer_toString(s->program->output) : "no output");
}

Seems it counts any status change as success - even though I have a separate action configured for status "4".

I think that in the "else" it should only issue a "succeeded" if the status changed to "0" (which is agreed to be a success status).

Comments (0)

  1. Log in to comment