Monit IF / ELSE语法

时间:2016-05-31 18:09:36

标签: monit

我试图监控服务。我的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

2 个答案:

答案 0 :(得分:0)

语法是:

  

如果测试那么行动 [如果成功那么*行动]

另外

"如果x在y周期内重新启动,那么......"声明不支持" else"部分:https://mmonit.com/monit/documentation/monit.html#SERVICE-RESTART-LIMIT

重启 重启有点无意义,因为重启

没有任何矛盾

我试图让你的逻辑在这里进行if then else动作但不理解 else 部分。

在这里你想要"然后停止"开始" https://myhost:443/失败两次时的服务"身份验证(称为T0) 然后在下一个周期,您要运行脚本 / etc / monit / pagerduty-trigger authentication 。 (称为T0 + 1周期) 这里为什么在4个周期内但不少于2个,机器人确定。

我想在T0 + 1 + 2周期,如果再次在线服务,你想运行" / etc / monit / pagerduty-resolve authentication"

一种解决方案是使用自定义脚本

失败的测试级别处理它

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"

创建文件 /var/lib/monit/scripts/notifyAndExecute.sh ,负责重新启动并调用 / etc / monit / pagerduty-trigger身份验证

答案 1 :(得分:0)

我不确定你是否还在看这个。我还将Monit与Pagerduty集成在一起。我有一个更简单的示例正在工作。我注意到的是'else'似乎仅支持“ else if成功”。我认为这只是'else'的简化版本,无法添加您尝试的更复杂的表达方式。

这是我的示例,当服务(monit中的process)不存在时触发,并在服务出现时解决。

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"