1

I need to run a shell script if a service is ok with monit, to link to my other monitoring system (nagios).

Basically what I need to achieve is to make monit send an alert when a service was restarted and another alert when the service is ok.

I have tried the following without any luck:

if 1 restarts within 1 cycles then exec "<send WARNING alert here>"
if 0 restarts within 5 cycles then exec "<send OK alert here>"

The above complains about "Error: zero or negative values not allowed in a action rate statement ''OK''"

if 1 restarts within 1 cycles then exec "<send WARNING alert here>"
else if succeeded for 5 cycles then exec "<send OK alert here>"

The above complains about the "else"... I believe the "If X Restarts" doesn't support an "else"

Any suggestions to achieve this?

Onitlikesonic
  • 1,161
  • 4
  • 15
  • 24

1 Answers1

1

Since you say that monit is feeding into NAGIOS, why not use NAGIOS to do the heavy lifting (ie, deciding about, and sending, notifications)? If monit monitors the restarts, it can use send_nsca to notify NAGIOS that a restart has happened.

NAGIOS in turn can receive this into a passive service which is designed to notify on a single alert, but is also defined with a freshness test such that if it hears nothing for a certain period (here, 60 mins) it invokes a script which returns "0 OK", and so will notify "OK" that amount of time after a restart notification.

define service{
        use                     <standard template>
        host_name               foo
        service_description     bar        
        active_checks_enabled   0
        passive_checks_enabled  1
        check_command           no-restarts-ok
        check_freshness         1
        max_check_attempts      1
        normal_check_interval   60
        }

and

define command{
        command_name    no-restarts-ok
        command_line    $USER1$/check_dummy 0 OK
}
MadHatter
  • 78,442
  • 20
  • 178
  • 229
  • Thanks MadHatter, indeed this would be a solution, i mostly use the freshness on the opposite case (when i don't receive anything then goes critical). Actually thought about this previously but was looking for something on monit iself that would alert when up and when restarted. I guess your suggestion is the way to go though since doesn't look like there are many other options – Onitlikesonic Apr 18 '13 at 10:26
  • Glad it works for you! – MadHatter Apr 18 '13 at 10:45