restart and alert email

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

restart and alert email

sashk

Hi,

I have following check:

check program script with path "/path/to/check_script" as uid "user" and gid "user"
    start program = "/path/to/script start" as uid "user" and gid "user"
    stop program  = "/path/to/script stop" as uid "user" and gid "user"
    if 2 restarts within 10 cycles then alert
    if status != 0 then restart

What happens: every time check fails, I receive failure email, then two minutes later I receive success email.

Two questions:

  1. Why success email arrives two minutes after failure? start/stop programs are pretty quick and execution time take few seconds.
  2. Is there a way to configure monit not to alert me unless 2 restarts happen within 10 cycles and status is still not zero?

Thanks.

Reply | Threaded
Open this post in threaded view
|

Re: restart and alert email

Lutz Mader
Hallo,
based on your sample

check program script with path "/usr/local/etc/monit/scripts/test.sh"
  start program "/usr/local/etc/monit/scripts/test.sh start"
  stop program "/usr/local/etc/monit/scripts/test.sh stop"
  if 2 restarts within 10 cycles then alert
  if status != 0 then restart

and monitrc with "set daemon 60", the daemon check cycle time.

[2021-01-12T23:15:31+0100] error    : 'script' status failed (1) --
program test script at Di 12 Jan 2021 23:14:31 CET for script
[2021-01-12T23:15:31+0100] info     : 'script' trying to restart
[2021-01-12T23:15:31+0100] info     : 'script' stop:
'/usr/local/etc/monit/scripts/test.sh stop'
[2021-01-12T23:15:37+0100] info     : 'script' start:
'/usr/local/etc/monit/scripts/test.sh start'
[2021-01-12T23:16:42+0100] error    : 'script' service restarted 2 times
within 6 cycles(s) - alert
[2021-01-12T23:16:42+0100] info     : 'script' status succeeded (0) --
program test script at Di 12 Jan 2021 23:15:42 CET for script

And your question

>  1. Why success email arrives two minutes after failure? start/stop programs are
>     pretty quick and execution time take few seconds.

I got a "Status failed Service script" mail and after a minute
the "Status succeeded Service script" mail from my local mail server.

My suggestion, check your mail server or the cycle time.


>  2. Is there a way to configure monit not to alert me unless 2 restarts happen
>     within 10 cycles and status is still not zero?

From my point of view, you can not configure this.

With regards,
Lutz

Reply | Threaded
Open this post in threaded view
|

Re: restart and alert email

Lutz Mader
Hello,
sometimes monit need a second cycle to get the script status, for some
detail information see
https://mmonit.com/monit/documentation/monit.html#PROGRAM-STATUS-TEST

> Thank you for your answer. For some reason, for me 'script' status
> succeeded (0) message shows up only in the end of second cycle.
>
> In any case, do I understand correctly, that monit will always alert me
> if script status fails no matter if monit will able to restart the
> service? I was under impression that "if 2 restarts within 10 cycles
> then alert" would control when alerts will be sent.

You get an additional alert for this rule, if two restarts are done in a
timeframe of ten cycles. However, you also get a warning for every
failure and also for successes.

With regards,
Lutz