Nagios notifications - sending mail to admin's inbox (l


#1

Hello,
I’m trying to collect all the data needed to establish the process of sending notifications to an email address in Nagios.
I hope this thread will contain complete list and detailed steps to establish it from installation (version 3.0.3 debian) to admin’s inbox.

  1. Updating contacts.cfg
    The file can be found in the following location: /usr/local/nagios/etc/objects/contacts.cfg
    The basic data after installation regarding the person we want to send email contain minimal information:

define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
email user@company.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}

We need to add the notification configuration as the following:

define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
service_notification_period 24x7 ; service notifications can be sent anytime
host_notification_period 24x7 ; host notifications can be sent anytime
service_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downtime events
host_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime events
service_notification_commands notify-service-by-email ; send service notifications via email
host_notification_commands notify-host-by-email ; send host notifications via email
email user@company.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}

user@company is the mail address we want to get notifications.
The “notification” lines were from the templates.cfg found in /usr/local/nagios/etc/objects/templates.cfg

From the documentation:
Contacts are people involved in the notification process:
Contacts have one or more notification methods (cellphone, pager, email, instant messaging, etc.)
Contacts receive notifications for hosts and service they are responsible for.

  1. Editing email notifications commands found in commands.cfg (/usr/local/nagios/etc/objects/commands.cfg)

################################################################################

SAMPLE NOTIFICATION COMMANDS

These are some example notification commands. They may or may not work on

your system without modification. As an example, some systems will require

you to use “/usr/bin/mailx” instead of “/usr/bin/mail” in the commands below.

################################################################################

‘notify-host-by-email’ command definition

define command{
command_name notify-host-by-email
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$ **” $CONTACTEMAIL$
}

‘notify-service-by-email’ command definition

define command{
command_name notify-service-by-email
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$ **” $CONTACTEMAIL$
}

I guess I had to change it to “mailx” instead of “mail” since “mailx” is installed with Nagios.

  1. Do I need to changed/add/edit the administrator email address found in /etc/nagios/nagios.cfg?

ADMINISTRATOR EMAIL ADDRESS

The email address of the administrator of this machine (the one

doing the monitoring). Nagios never uses this value itself, but

you can access this value by using the $ADMINEMAIL$ macro in your

notification commands.

admin_email=nagios

Do I need to change admin_email=Nagios to user @ company.com?

  1. As I understood mailx (heirloom.sourceforge.net/mailx.html) is installed by default with Nagios.
    Do we need to change the definitions/files after installation? Edit existing files? Create new files? For example .mailrc @home directory.
    (forums.opensuse.org/archives/sf- … tions.html)
    There’re other alternatives for mailx (nagiosexchange.org/cgi-bin/s … tification) but I want to use what’s already given.

  2. Check that notification is enabled in Nagios.cfg (file can be found in /usr/local/nagios/etc/nagios.cfg):

NOTIFICATION LOGGING OPTION

If you don’t want notifications to be logged, set this value to 0.

If notifications should be logged, set the value to 1.

log_notifications=1

  1. Where we declare our SMTP server IP address/name?

  2. Other links/threads/post related (each contain some data):
    meulie.net/portal_plugins/fo … .php?10126
    nagioscommunity.org/wiki/ind … MTP_server
    linuxquestions.org/questions … os-651846/

Thoughts?
If I’m missing something her pls reply.


#2

"But nothing ever happens and I wonder


#3

Everything is working now. i’ll try to make asap a tutorial that will help to configure everything that’s needed.
Hip Hip Horray!


#4

You have the Nagios configuration here, but what about the SMTP server information? I’ve configured Nagios on Centos 5 with Sendmail if you would like that configuration.