Hello Gerrit,
in general Monit send one event only.

> Monit by default sends just one notification if a service failed and
> another when/if it recovers.

Unfortunately, the handling of messages is different.
All the time a new messages occure a new event will be send if the
message match.

Keep in mind all tests are used.

>   if content = "CRIT:" then alert
>   if content = "WARN:" then alert
>   if content != "OK:" for 2 cycles then alert

If the message text contain "CRIT:" this will match the first line and
the third line. From my point of view, a mixture of "=" and "!=" is not
useful.

A script to handle the messages is more useful, sometimes.
But this will work with some messages only, see example
https://mmonit.com/wiki/Monit/ConfigurationExamples#HDDTemp
or
https://mmonit.com/monit/documentation/monit.html#PROGRAM-STATUS-TEST

I use something like the following to handle the message output.

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'"

The script handle the message and will end with a proper return code.
The command output is available in the "last output".

  last exit value              2
  last output                  WARN: tank/syncoid/[long path] newest
daily snapshot is 4d 2h 27m 6s old (should be < 2d 12h 0m 0s)

A suggestion only,
Lutz


Am 08.12.25 um 09:00 schrieb Gerrit Kühn:
> Hello,
> 
> I have this monit job:
> 
> 
> check program bak_sanoid with path "/usr/local/bin/sanoid
> --monitor-snapshots"  every 10 cycles
>       if content = "CRIT:" then alert
>       if content = "WARN:" then alert
>       if content != "OK:" for 2 cycles then alert
> [...]
> Several more of these, matching for concrete file paths.
> 
> 
> Last night sanoid met the WARN: condition because I had manually deleted
> an old snapshot, and it took another 24h until this re-appeared via the
> next backup cron job:
> 
> ---
> Description: content match on program output:
> WARN: tank/syncoid/[long path] newest daily snapshot is
> 3d 2h 27m 6s old (should be < 2d 12h 0m 0s)
> ---
> 
> In my experience, I get just *one* alert message from monit in such a case
> (when the condition is first met), and another one when the condition is
> ok again (see manual excerpt below).
> 
> However, in this case I got alert messages every 10 minutes (10 cycles).
> 
> Is that expected? The manual clearly says
> ---
> Monit by default sends just one notification if a service failed and
> another when/if it recovers.
> ---
> 
> I am not using any reminder statements. The monit version is 5.35.2. Any
> idea why this happens?
> 
> 
> cu
>   Gerrit
> 


Reply via email to