Nagios 以电子邮件形式发送每日警报历史记录

pra*_*tri 2 linux monitoring nagios

我知道我们可以使用 nagios 插件通过电子邮件通知来发送任何类型的严重警报的电子邮件。现在,我希望每天发送一封电子邮件作为过去一天的关键警报的报告。有人可以帮我解决这个问题。

qua*_*nta 6

现在,我希望每天发送一封电子邮件作为过去一天的关键警报的报告。

编辑将nagios.cfg轮换方法更改为每天:

# LOG ROTATION METHOD
# This is the log rotation method that Nagios should use to rotate
# the main log file. Values are as follows..
#   n   = None - don't rotate the log
#   h   = Hourly rotation (top of the hour)
#   d   = Daily rotation (midnight every day)
#   w   = Weekly rotation (midnight on Saturday evening)
#   m   = Monthly rotation (midnight last day of month)

log_rotation_method=d
Run Code Online (Sandbox Code Playgroud)

然后解析nagios.logCRITICAL 警报,如下所示:

awk '/SERVICE ALERT: .*;CRITICAL;HARD/ { print $0 }' nagios.log | \
    perl -pe 's/(\d+)/localtime($1)/e' | \
        mail -s "Nagios daily report $(date +%F)" <your_email>@domain.com
Run Code Online (Sandbox Code Playgroud)

如果需要,请在一天结束时将上述命令作为每日 cron 作业运行。