How to send an "Everything is OK" notification from Nagios?
I use the following setup to send an email once per day. This let's me know that all is well with my Nagios server, the email system and the Nagios config.
# nagios/objects/localhost.cfg
....
# Send a message once per day to make sure nagios is working ok
define service{
use local-service
host_name localhost
service_description Nagios is OK
check_command check_all_is_well
check_period morning ; this is a custom period
normal_check_interval 60
; setting this to an hour and making the check_period
; interval 59 minutes long each day ensures it only
; happens once per day in a specific window
}
and in you timeperiods config file:
# nagios/objects/timeperiods.cfg
....
define timeperiod{
timeperiod_name morning
alias First thing in the am
monday 06:00-6:59
tuesday 06:00-6:59
wednesday 06:00-6:59
thursday 06:00-6:59
friday 06:00-6:59
saturday 06:00-6:59
sunday 06:00-6:59
}
And the check_all_is_ok command is a simple wrapper around sendmail:
# check_all_is_ok
#!/bin/bash
echo "All is well from Nagio on `hostname`" \
| /etc/nagios/sendmail -s "Nagios on PIP is OK" <your email address>
echo "OK: nagios is ok on `hostname`";
exit 0
It doesn't check that there haven't been problems in the prior 24 hours, but you could add some grep-ping of the logs as guanta suggested if you need that. You could also accomplish the once a day requirement by setting normal_check_interval to 1440 (24 hours), but I want the check to be run in a specific window each day.
If you configured daily log rotation (log_rotation_method=d
), you can write a script to count the number of alerts in nagios.log
, something like this:
[ `grep -c ALERT var/nagios.log` -eq 0 ] && echo "Everything is OK!" | mail -s "Nagios daily report" your@email
Put it into a cron job to run at the end of day, before you go to bed.
If you don't, refer to this topic to filter according to the date.
For the benefit of others: I just went through this question myself and the most simple solution came up to the mind is this, checking nagios process every 8 hrs to make sure nagios is running
#crontab -e
Add the following
* */8 * * * /usr/local/nagios/libexec/check_nagios -t 20 -e 5 -F /usr/local/nagios/var/status.dat -C /usr/local/nagios/bin/nagios > /var/local/nagios_stats && sendemail -f "NAGIOS STATUS [email protected]" -u Nagios Process Status -s smtp.gmail.com:587 -xu [email protected] -xp SenderPassword -o tls=yes -t [email protected] -m < /var/local/nagios_stats
Don't forget to
Creating file in /var/local/nagios_stats
(or somewhere else but change it in the crontab)
SenderAddress,RecipientAddress,MailPassword