monit:如何发送类似警报的电子邮件

monit:如何发送类似警报的电子邮件

我想要针对以下情况定制一条警报消息:

if cpu > 75% for 2 cycles then exec "command|mail -s subject [email protected]"

到 monitrc 配置文件

我如何添加该命令?

  check process apache with pidfile /var/run/apache2.pid
    start program = "/etc/init.d/apache2 start" with timeout 60 seconds
    stop program  = "/etc/init.d/apache2 stop"
    if cpu > 60% for 2 cycles then alert
    if cpu > 80% for 5 cycles then restart      # 10minutes
    if totalmem > 200.0 MB for 5 cycles then restart
    if children > 250 then restart
    if loadavg(5min) greater than 10 for 8 cycles then stop
    if failed host 192.168.1.200 port 80 protocol http 
       and request "/monit/token"
       then restart

为什么我添加该行后,即使条件满足也不会发送电子邮件?有什么想法吗?

答案1

将命令放入 shellscript 中

if cpu > 75% for 2 cycles then exec "/full/path/custom_email.sh"

然后 /full/path/custom_email.sh 将包含类似

#!/bin/bash
command|mail -s subject [email protected]

相关内容