
如果 monit 可以正常使用服務,我需要執行 shell 腳本來連結到我的其他監控系統 (nagios)。
基本上我需要實現的是讓 monit 在服務重新啟動時發送警報,並在服務正常時發送另一個警報。
我嘗試過以下操作,但沒有任何運氣:
if 1 restarts within 1 cycles then exec "<send WARNING alert here>"
if 0 restarts within 5 cycles then exec "<send OK alert here>"
上面抱怨“錯誤:動作率聲明''OK''中不允許零或負值”
if 1 restarts within 1 cycles then exec "<send WARNING alert here>"
else if succeeded for 5 cycles then exec "<send OK alert here>"
上面抱怨了“else”......我相信“If X Restarts”不支援“else”
有什麼建議來實現這一目標嗎?
答案1
既然您說 monit 正在向 NAGIOS 提供信息,為什麼不使用 NAGIOS 來完成繁重的工作(即決定並發送通知)?如果 monit 監視重新啟動,它可以用來send_nsca
通知 NAGIOS 重新啟動已發生。
NAGIOS 反過來可以將其接收到被動服務中,該服務旨在通知單一警報,但也定義了新鮮度測試,因此如果它在一段時間內(此處為60 分鐘)沒有聽到任何消息,它將呼叫一個腳本,該腳本返回“0 OK”,因此將在重新啟動通知後的那段時間通知“OK”。
define service{
use <standard template>
host_name foo
service_description bar
active_checks_enabled 0
passive_checks_enabled 1
check_command no-restarts-ok
check_freshness 1
max_check_attempts 1
normal_check_interval 60
}
和
define command{
command_name no-restarts-ok
command_line $USER1$/check_dummy 0 OK
}