ghacks Technology News

Configure alerts for email and contact groups in Nagios

If you have been following my latest entries, you know I have been covering the Nagios monitoring system (see my articles “Quickly install Nagios on Ubuntu“, “Easily extend Nagios’ functionality“, and “Configure hostgroups for Nagios“.) This time around we are going to look at the notification function of Nagios. Specifically, I am going to show you how to set up Nagios for email alerts to a single email address and multiple addresses with the help of contact groups.

This article will assume the box hosting your Nagios installation has a working email server. If not, take a look at my Postfix articles here on Ghacks. Once that is up and running, email alerts are just a few steps away.

Assumptions

Outside of having a working email system, this article will assume you already have a functioning Nagios installation and that you are familiar with its configurations. I will also assume you have gathered all of the email addresses you need to use with Nagios. That being the case, let’s get with the configurations.

Defining your contact

The first item to tackle is to define your contact. This is done with the file /etc/nagios3/conf.d/contacts_nagios2.cfg. In this file you will see a section that looks like:

define contact{
contact_name USERNAME
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r,f,s
host_notification_options d,u,r,f,s
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
email email@localhost
}

Where all text above in bold is user-specific. NOTE: You will want to add a new define for each administrator that needs to be contacted via email. And make sure you define each user with his or her email address in the define.

Before you move on, it would be good to restart Nagios to make sure your definitions are correct. If there is an error you will get a warning in the output of the start command.

Define your contact group

In that same file you will also find a spot to group users together in contact groups. This comes in very handy because you can then define a set of users (administrators) who will only get warnings for certain services or certain hosts.

To define a group add an entry like so:
define contactgroup {
contactgroup_name       web-admins
alias                   Web Server Adminstrators
members                USERNAME1, USERNAME2
}

Where USERNAME1 and USERNAME2 are members for this group. NOTE: the usernames in this group MUST be defined in the define contact section above. If they are not, Nagios will throw errors when it attempts to start.

Attach groups to services

Finally you need to attach your groups to services. As you can see, above, I have created a web_admins group. It should be above that this group should be added to a corresponding service in the file /etc/nagios3/conf.d/services_nagios2.cfg. In this file you will have created an entry like:

define hostgroup {
hostgroup_name http-servers
service_description  HTTP
check_command  check_http
use generic-service
notification_interval 0
}

To this entry you will want to add the line:

contact_groups web-admins

Now when you restart Nagios anytime there is an issue with one of the HTTP servers, only the contact group you have assigned will be notified. Pretty slick.

Final thoughts

I hope you are starting to see just how flexible and powerful Nagios is. If not, don’t worry – there’s plenty more to come!

Enjoyed the article?: Then sign-up for our free newsletter or RSS feed to kick off your day with the latest technology news and tips, or share the article with your friends and contacts on Facebook or Twitter.

Related Articles:

Configure hostgroups for Nagios
How to install Nagios on Ubuntu server
Quickly install Nagios on Ubuntu
Nagios: Enable external commands
Easily extend Nagios’ functionality



About the Author:

Author: , Sunday April 4, 2010 -
Tags:, ,


Leave a Reply   Follow Ghacks   Subscribe To Comment Rss

Subscribe without commenting

© 2005-2012 Ghacks.net. All Rights Reserved. Privacy Policy - About Us