Need help?

Our experts will login to your server within 30 minutes to fix urgent issues.

We will keep your servers stable, secure and fast at all times for one fixed price per month.

Nagios email notification configuration – How we do it!!

Want to configure email notification in Nagios? We can help you do it.

Enabling an email notification in Nagios will help us to get the notification instantly when the server goes down.

At Bobcares, we often receive requests regarding Nagios as a part of our Server Management Services.

Today, let’s see how our Support Engineers set up email alerts in Nagios for our customers.

 

Nagios email notification

Nagios is an open source monitoring tool. It provides both notification and alert system. Monitoring the Nagios interface will not be feasible all the time. That’s where the email notification helps. With an email option, it can send an email to a contact or a group of contacts during any events.

However, to set up email notification for a user, we need to define in Nagios Object Contact configuration file. Usually, the file will be present in the Nagios folder as contacts.cfg.

Let us discuss how our Support Engineers setup mail notification in Nagios.

 

Email notification configuration in Nagios

Recently, one of the customers contacted us to set up email notification in his Nagios. Let us discuss how our Support Engineers set it up for our customers.

First, we log in to the Nagios server.

Then we stop Nagios service using the command

service nagios stop

Now we locate the contacts.cfg file. The file will be based on the Nagios configuration.

The default location of the contacts.cfg will be at

/usr/local/nagios/etc/objects/contacts.cfg

We edit the contact_name, alias, and email in the configuration file under the define contact section.

define contact {
contact_name Contact1
alias ContactNameAlias
email email-address
service_notification_period 24x7
service_notification_options w,u,c,r,f,s
service_notification_commands notify-service-by-email
host_notification_period 24x7
host_notification_options d,u,r,f,s
host_notification_commands notify-host-by-email

The service_notification_options help us define the service states for which the notification needs to be sent out to the contact email.

The w option notifies the warning service states, u for the unknown service states and c notify the critical service states and so on.

We use the host_notification_options to define the host state for which notifications need to be sent.

The d notify the down host state and u notify the unreachable state and so on.

Now we need to add the details regarding the mail group to send the email.

define contactgroup{
contactgroup_name Group1
alias GroupAlias
members Contact1,Contact2
}

Then in the template.cfg file at the Nagios location, we specify the contact name and contact group name.

We also specify the notification for individual service editing the parameter define service.

Then we edit the command.cfg file and add $NOTIFICATIONCOMMENT$\n after the $SERVICEOUTPUT$\n option. We add the below details in the file.

# '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$\n $NOTIFICATIONCOMMENT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}

Finally, we start the Nagios service using the command

service nagios start

That’s it and you will get email alerts on events related to the server.

[Trouble enabling email notifications in Nagios? We are available 24×7 to help.]

 

Conclusion

In this write-up, we have discussed the details on how our Support Engineers do the Nagios email notification configuration.


PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

nagios

Submit a Comment

Your email address will not be published. Required fields are marked *