2016-05-31 51 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