Hello Tobias,
this is the way how monit handle tests, all the time the test match, an
alert notification is send. And all the time the test does not match, a
success notification will send.

I use a script to send status notifications to a central system.
The status information can be evaluated differently depending on the
return code or based on an additional test in the central system only.

check program Pgsp_Check with path "/usr/local/etc/monit/scripts/pgsp.sh"
  if status > 2 then exec "/usr/local/etc/monit/scripts/zexec.sh Error"
  if status = 2 then exec "/usr/local/etc/monit/scripts/zexec.sh Warning"
  if status > 1 then exec "/usr/local/etc/monit/scripts/zexec.sh Info"
     else if succeeded then exec "/usr/local/etc/monit/scripts/zexec.sh Ok"

There is no direct distinction or gradation in the monitor, only a
distinction is made between "Success" and "Failure" (or "Changed").
Thus, if the return code is greater than one, the result is incorrect
(status "Status failed") and if it is one or less, it is OK (status "OK").

Based on your sample you can use a script to send notifications.

> CHECK PROGRAM MyContainer PATH /bin/check_container my_container
>   if status != 0 for 5 cycles then restart
>   if status != 0 for 10 cycles then alert

CHECK PROGRAM MyContainer PATH /bin/check_container my_container
  if status != 0 for 5 cycles then restart
  if status != 0 for 10 cycles then exec
"/usr/local/etc/monit/scripts/zexec.sh Error"
     else if succeeded then exec "/usr/local/etc/monit/scripts/zexec.sh Ok"

Unfortunately the restart still send notifications, perhaps.

Sorry, a suggestion only,
Lutz


Am 09.02.25 um 22:11 schrieb Tobias Langner via This is the general
mailing list for monit:
> Hey,
> 
> I use monit to monitor the health of a bunch of docker containers that
> sometimes die/become unhealthy for various reasons, when they are
> configured to be restarted by monit, which most of the time fixes the
> issue.
> 
> I'd like to only be notified by monit when the restart does not fix the
> problem and the container is still unhealthy. I thought to configure
> something like
> 
> CHECK PROGRAM MyContainer PATH /bin/check_container my_container
>   if status != 0 for 5 cycles then restart
>   if status != 0 for 10 cycles then alert
>   ...
> 
> in the hope that I would only get notified when the script returns a
> failure for 10 cycles. However, I also get a notification after five
> cycles, usually followed by one immediately after, telling me that
> everything is good again.
> 
> How can I configure monit in a way to not get notified in such a case?
> One way I came up with was to create to separate rules, one to restart
> only that uses noalert to entirely supress alerts, and another one to
> alert. But that seems like overkill.
> 
> Thanks for your help, best,
> 
>   Tobias
> 
> PS: My request is the same as in this thread
> <https://lists.nongnu.org/archive/html/monit-general/2014-05/msg00016.html>
> but since a) the solution there does not work for me as I generally
> don't have an execution failure and b) it is more than 10 years old, I
> thought to rather create a new thread.
> 
> 
> 


  • Suppress ale... Tobias Langner via This is the general mailing list for monit
    • Re: Sup... M/Monit Support
    • Re: Sup... Lutz Mader

Reply via email to