Allow monit to do multiple actions on an event

Issue #449 new
Former user created an issue

It would be really nice to be able to request monit to do multiple actions on an event:

For example:

check host myHost with address 192.168.1.1
  if ping failed then alert and exec "myscript"

Is there a way to do this now?

Thanks

Comments (9)

  1. Tildeslash repo owner

    the alert action is implicit ... even if you use just the "exec" action, alert will be sent:

    check host myHost with address 192.168.1.1
      if ping failed then exec "myscript"
    
  2. Loïc Mathaud

    Could we have various "exec" available, so?

    check host myHost with address 192.168.1.1
      if ping failed then exec "myscriptA" exec "myscriptB"
    
  3. Tildeslash repo owner

    @loicm you can execute multiple scripts like this:

    check host myHost with address 192.168.1.1
      if ping failed then exec "/bin/bash -c 'myscriptA; myscriptB'"
    
  4. JustQyx

    Hi @tildeslash

    If I configure a if not exist then monit will not auto restart the process like this?

    check process djipay_clockwork_prod with pidfile /u/apps/pay/shared/tmp/pids/clockworkd.clockwork.pid every 2 cycles
      start program = "/bin/bash -c 'export RAILS_ENV=production && cd /u/apps/pay/current && bundle exec clockworkd -c clockwork.rb --dir=. --pid-dir=/u/apps/pay/shared/tmp/pids --log-dir=/u/apps/pay/shared/log --log start'" as uid dji and gid dji
      stop program = "/bin/bash -c 'export RAILS_ENV=production && cd /u/apps/pay/current && bundle exec clockworkd -c clockwork.rb --dir=. --pid-dir=/u/apps/pay/shared/tmp/pids --log-dir=/u/apps/pay/shared/log --log stop'" as uid dji and gid dji with timeout 90 seconds
      if not exist then exec "/usr/local/bin/slack.sh"
      group app
    
  5. Tildeslash repo owner

    Yes. The default "if not exist" action is to restart the service. By setting the "exec" action you override the default one.

    You can use the same statement multiple times for multiple actions:

    if not exist then restart
    if not exist then exec "/usr/local/bin/slack.sh"
    
  6. JustQyx

    Hi, it is not work

    [UTC Jul 20 03:25:06] error : 'djipay_clockwork_dbeta' process is not running [UTC Jul 20 03:25:06] info : 'djipay_clockwork_dbeta' exec: /usr/local/bin/djipay_slack.sh [UTC Jul 20 03:25:37] error : 'djipay_clockwork_dbeta' process is not running [UTC Jul 20 03:25:37] info : 'djipay_clockwork_dbeta' exec: /usr/local/bin/djipay_slack.sh

    This is Monit version 5.6 Copyright (C) 2001-2013 Tildeslash Ltd. All Rights Reserved.

  7. Tildeslash repo owner

    Please upgrade Monit. Multiple existence tests support was added in Monit 5.12.0 (the latest release is 5.23.0), changelog excerpt:

    New: Support for multiple existence tests (available in the process, file, directory and fifo check context):
        if does not exist then alert
        if does not exist 3 times in 5 cycles then stop
    
  8. Log in to comment