I am trying to get an alert from monit if it fails to restart a service 5 times, but I get a syntax error
/etc/monit/monit.d/engine.conf:5: Error: syntax error 'alert'
any idea what's wrong with it?
/etc/monit/monitrc:
set daemon 120
set mailserver localhost
set eventqueue
basedir /var/monit # set the base directory where events will be stored
slots 100 # optionaly limit the queue size
set httpd port 2812
allow localhost
set logfile syslog
set alert root@localhost
include /etc/monit/monit.d/*
/etc/monit/monit.d/engine.conf (The only file in monit.d) :
check process engine with pidfile /var/run/engine.pid
group engine
start program = "/etc/init.d/engine start"
stop program = "/etc/init.d/engine stop"
if 5 restarts within 5 cycles then alert
version:
# monit -V
This is monit version 4.10.1
It looks like support for this was added in monit 5.1
From the changelog at http://mmonit.com/monit/dist/CHANGES.txt :
I was trying to use the exact same syntax as you (for the exact same reason), and found it was working on one server but another. When I compared versions, I found one was 5.2.5 and the other was 4.10.1
So the answer it seems is to upgrade to at least 5.1
I think it looks fine. Have you tried re-typing that line to rule out any hidden characters messing up the line?
Have you got a
set alert <email_address>
defined prior to this configuration?Ok,found the error.
alert
is not a valid event and you need to specify an event that will generate an alert. Without a specific event monit wouldn't know what to say to you.List of events from the manpage:
In your case I'd recommend exec. The full list of messages is:
Best of luck,
João Miguel Neves
I noticed something strange with alert and unmonitor parameter in monit 5.4-2 : If you use unmonitor parameter in the alert config line, it generates a syntax error :
When restarting monit, you get :
I solved this problem removing unmonitor in arguments :
I can't see the syntax change... Strange... Isn't it ?