我尝试在 monit 重新启动服务 5 次失败时收到警报,但收到语法错误
/etc/monit/monit.d/engine.conf:5: Error: syntax error 'alert'
知道它有什么问题吗?
在 /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(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
版本:
# monit -V
This is monit version 4.10.1
答案1
看起来 monit 5.1 中已经添加了对此的支持,
从以下更新日志中可以看出http://mmonit.com/monit/dist/CHANGES.txt:
Version 5.1
NEW FEATURES AND FUNCTIONS:
It is now possible to define any action for the restart timeout rule.
Multiple restart timeout rules can also be defined. Example:
if 3 restarts within 5 cycles then exec "/foo/bar"
if 8 restarts within 10 cycles then unmonitor
我尝试使用与您完全相同的语法(出于完全相同的原因),但发现它在一台服务器上可以运行,但在另一台服务器上却不行。当我比较版本时,我发现一个是 5.2.5,另一个是 4.10.1
因此答案似乎是升级到至少 5.1
答案2
我认为它看起来不错。您是否尝试过重新输入该行以排除任何隐藏字符弄乱该行?
答案3
您set alert <email_address>
在此配置之前有定义吗?
答案4
我注意到 monit 5.4-2 中的 alert 和 unmonitor 参数有些奇怪:如果在 alert 配置行中使用 unmonitor 参数,则会生成语法错误:
alert [email protected] on { uid, gid, unmonitor
} with the mail-format { subject: Alarm! }
重新启动 monit 时,您会得到:
Error: syntax error 'unmonitor'
我通过删除参数中的取消监视解决了这个问题:
alert [email protected] on { uid, gid
} with the mail-format { subject: Alarm! }
我看不到语法变化...奇怪...不是吗?