step 1 : check in templates.cfg . The configuration should be similar to the one below(in objects folder in my case)
# Generic contact definition template - This is NOT a real contact, just a template!
step 2 : check contacts.cfg
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit from generic-conta
alias Bishal Acharya ; Full name of user
# We only have one contact in this simple configuration file, so there is
# no need to create more than one contact group.
alias Nagios Administrators
Make sure we have contact and cotactgroup defined in contacts.cfg. In my case it is with my denominations.
step 3 : Check the commands.cfg file . Make sure we make /usr/bin/mailx in the configuration under Ubuntu systems. Also do install sendmail prior to doing this by using(sudo apt-get install sendmail) and check by command line that you can send mail by using command (mail firstname.lastname@example.org) . If you successfully sent your mail then your nagios too can send mail or else we again need to troubleshoot.
# 'notify-host-by-email' command definition
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $ADMINEMAIL$
# 'notify-service-by-email' command definition
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/bin/mailx -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $ADMINEMAIL$
Make sure ADMINEMAIL has been set accordingly in nagios.cfg file as
step 4 : Time to check few things
check whether notifications are set or not in nagios.cfg file if not set it to 1, similarly also make notifications to 1 in services and host definitions, Nagios cant sent notifications unless you enable them.
Now reload your nagios and test by stopping one of the services like ssh or other anyone If you are lucky you will receive notifications according to the timing settings. If not check your log file.
Common problem :
Warning: Contact 'nagiosadmin' service notification command '/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: PROBLEM\n\nService: SSH\nHost: bishal\nAddress: 127.0.0.1\nState: CRITICAL\n\nDate/Time: Mon Jun 29 17:24:26 JST 2009\n\nAdditional Info:\n\nConnection refused" | /usr/bin/mail -s "** PROBLEM Service Alert: bishal/SSH is CRITICAL **" email@example.com' timed out after 60 seconds
Solution for Nagios notification Timeout problem :
Go to nagios.cfg and increase the notification_timeout to some larger value, In my case i made it 600 from 60
Now again reload nagios and you should be alerted when any service goes down. Test it by stopping any service also we are notified when any service recovers. We may give our mobile phone email address so that we are alerted to our mobile phones when problem occurs instead of our computer.
Good Luck ! Comments are welcomed