![根据每次检查使用邮件格式覆盖监控警报](https://linux22.com/image/696044/%E6%A0%B9%E6%8D%AE%E6%AF%8F%E6%AC%A1%E6%A3%80%E6%9F%A5%E4%BD%BF%E7%94%A8%E9%82%AE%E4%BB%B6%E6%A0%BC%E5%BC%8F%E8%A6%86%E7%9B%96%E7%9B%91%E6%8E%A7%E8%AD%A6%E6%8A%A5.png)
我目前对运行 HTTPS 的每个主机进行了两次监控检查:
check host www-example-https with address www.example.org
if failed
port 443
protocol https
then alert
check host www-example-certificate with address www.example.org
every "25 10 * * *"
if failed
port 443
protocol https
and certificate valid > 30 days
then alert
第一个警告我根本无法连接,并且每 2 分钟运行一次,而第二个提醒我证书的有效期少于 30 天,并且每天仅运行一次。
目前,这两项检查都会产生类似的警报消息,这意味着即将到期的证书看起来就像 HTTPS 完全失败了。因此,我想根据每个警报覆盖默认邮件选项。
我知道如果我想更改所有警报我可以这样做set mail-format
,但如果我使用块,我就无法弄清楚单个警报的语法if failed ... then alert
,并且在手册中找不到此特定用例的任何示例。
是否可以mail-format
根据每个警报覆盖上面定义的警报类型?
答案1
文档中有一个示例https://mmonit.com/monit/documentation/#CONFIGURATION-EXAMPLES
从个人测试来看,你无法避免“警报[电子邮件保护]“部分,因此,为了满足您的需要,它导致:
check host www-example-https with address www.example.org
if failed
port 443
protocol https
then alert
alert [email protected] with mail-format { # use local format
subject: https is down on www.example.org
message: https is down on www.example.org with port 443
Yours sincerely,
monit
}
check host www-example-certificate with address www.example.org
every "25 10 * * *"
if failed
port 443
protocol https
and certificate valid > 30 days
then alert
alert [email protected] with mail-format { # use local format
subject: https certificate expiration for www.example.org
message: https is certificate is less than 30 days on www.example.org with port 443
$SERVICE $EVENT at $DATE
Monit $ACTION $SERVICE at $DATE on $HOST: $DESCRIPTION.
Yours Pal,
MoMoMonit
}
另外,如果主机“失败”,则不会执行证书检查。
用一个 ”设置邮件格式“任何地方,更改所有通知