2016-05-31 57 views
0

我试图监视服务。我的monit定义如下。Monit IF/ELSE语法

当我调用monit -r我收到/etc/monit/conf.d/authentication.monit:10: syntax error 'else'

check host self with address myhost 
start program = "/usr/bin/service start authentication" 
stop program = "/usr/bin/service stop authentication" 
if failed port 443 protocol https 
    request/
    with timeout 5 seconds 
    for 2 cycles 
    then restart 
if 1 restarts within 4 cycles then exec "/etc/monit/pagerduty-trigger authentication" else if passed for 2 cycles then exec "/etc/monit/pagerduty-resolve authentication" 

所有的文件似乎表明我的语法是正确的。

我试图遵循两个文档

pagerduty

primary docs

回答

0

语法是:

IF 测试 THEN 行动 [ELSE如果设置成功THEN *行动]

而且

的 “如果y周期内X,然后重新启动...” 语句不支持 “其他人” 部分:https://mmonit.com/monit/documentation/monit.html#SERVICE-RESTART-LIMIT

否则重启是有点非 - 因为没有反向重新启动

我试图让你的逻辑在这里如果其他行动,但不明白其他部分。

在这里,你想“停止然后‘当https://myhost:443/失败两次(称为T0) 然后在下一个周期,要运行脚本的/ etc/monit的/ pagerduty触发认证启动’服务”认证。 (称为T0 + 1周期) 这里为什么4周期内但不少于2,机器人好。

我想,在T0 + 1 + 2个周期,如果服务在线再次,要运行在“/ etc/monit的/ pagerduty排解认证”

一种解决方案是在你的来处理它失败,自定义脚本测试水平

if failed port 443 protocol https request/ with timeout 5 seconds for 2 cycles then exec "/var/lib/monit/scripts/notifyAndExecute.sh" else if succeeded then exec "/etc/monit/pagerduty-resolve authentication"

创建文件负责重新启动,并呼吁的/ etc/monit的/ pagerduty触发认证/var/lib/monit/scripts/notifyAndExecute.sh