monit:在 IF 构造中添加 NOALERT

monit:在 IF 构造中添加 NOALERT

在 debian jessie 上,我已经配置了 monit 来检查HAproxy特定的端口转发,如果失败则重新启动它,如下所示:

check process haproxy with pidfile /run/haproxy.pid
   group www-data
   start program = "/bin/systemctl start haproxy.service"
   stop program = "/bin/systemctl stop haproxy.service"
   if failed port 8080 protocol http request "/checker" then restart
   if failed port 8081 protocol http request "/checker" then restart
   if failed port 8082 protocol http request "/checker" then restart
   if 8 restarts within 8 cycles then unmonitor

我知道可以noalert email在特定check环境中进行设置。我想知道是否可以在if同一个环境中对特定环境执行相同操作check。在这个特定情况下,我希望 monit 仅在检查port 8082失败时提醒我,而不提醒其他 2 个。

我曾尝试添加类似这样的内容:

check process haproxy with pidfile /run/haproxy.pid
   group www-data
   start program = "/bin/systemctl start haproxy.service"
   stop program = "/bin/systemctl stop haproxy.service"
   if 8 restarts within 8 cycles then unmonitor

check host site-a with address localhost
  noalert email@address
  depends haproxy
  if failed port 8080 protocol http request "/checker" then exec "/usr/bin/monit restart haproxy"

check host site-b with address localhost
  noalert email@address
  depends haproxy
  if failed port 8081 protocol http request "/checker" then exec "/usr/bin/monit restart haproxy"

check host site-c with address localhost
  depends haproxy
  if failed port 8082 protocol http request "/checker" then exec "/usr/bin/monit restart haproxy"

此配置有效,但我需要exec monit像外部程序一样,我想知道是否有办法在if construct同一个程序中直接执行此操作check。如果我使用以下内容,monit将启动而不会出现任何抱怨,但它不考虑noalert指示:

check process haproxy with pidfile /run/haproxy.pid
   group www-data
   start program = "/bin/systemctl start haproxy.service"
   stop program = "/bin/systemctl stop haproxy.service"
   if failed port 8080 protocol http request "/checker" then
     restart
     noalert email@address
   if failed port 8081 protocol http request "/checker" then
     restart
     noalert email@address
   if failed port 8082 protocol http request "/checker" then restart
   if 8 restarts within 8 cycles then unmonitor

任何想法?

此致

相关内容