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?
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.
and