Linux – Nagios Sending Daily Alert History as Email

linuxmonitoringnagios

I know that we can use nagios plugin notify-by-email to send emails for any kind of critical alerts. Now I want one email to be sent as a report for the critical alerts of last one day daily. Can someone please help me to solve this.

Best Answer

Now I want one email to be sent as a report for the critical alerts of last one day daily.

Edit the nagios.cfg to change the rotation method to daily:

# 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

then parse the nagios.log for the CRITICAL alerts, something like this:

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 the above command at the end of day as a daily cron job if you want.

Related Topic