monit的IF / ELSE语法

问题描述 投票:0回答:2

我试图监视服务。我monit的定义如下。

当我调用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

monit
2个回答
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


0
投票

我不知道,如果你正在看这个。我也有Pagerduty整合monit的。我有一个简单的例子这是工作。我注意到的是“其他”出现“如果成功了别人”只支持。我认为这是简单的“其他”的长手版,但无添加更复杂的表达式,你正试图能力。

这是我的例子时触发服务(在monit的过程中)不存在,当它解决。

check process tomcat8 with pidfile /var/run/tomcat8.pid
    if not exist
    then exec "/etc/monit/pagerduty-trigger tomcat8"
    else if succeeded then exec "/etc/monit/pagerduty-resolve tomcat8"
© www.soinside.com 2019 - 2024. All rights reserved.