Setting Up Email Alerts for Network Monitoring with Nagios

5025

 

For any network administrator, a good monitoring tool is worth its weight in dilythium crystals (or gold, depending upon your needs).Of course there are a lot of monitors out there. Some of these monitors do just about everything – and cost just about everything as well. Some of them are simple to install and use, but do very little. And then there’s Nagios. For the open source community, Nagios is the standard by which all other monitors are measured. And although Nagios is incredibly flexible, it does come with a price: time.

 

To get the basic Nagios up and running is simple. To get Nagios perfected for your particular network can take some time. Why? One of the tools Nagios does not have is an auto-discovery tool. What that means is that you have to manually configure all machines that you want to monitor. It’s not that difficult, but when compared to auto-discovery, it is a bit of a hurdle. And once you have every device configured, you then have to set up alerts and enable external commands to further the functionality of Nagios.

In my first Nagios article (see “Installing Nagios: An enterprise worthy network monitor“) I instructed you on how to install Nagios, configure the basics, and have your network monitored. Today, I am going to show you how to configure Nagios for email alerts that can be associated with certain services to certain administrators. It is a very flexible system that can keep administrators aware of issues they are responsible for and no more. Once you have completed this article (along with the original) you should have a Nagios installation not only monitoring your network, but also keeping you apprised of the status of that network.

Setting Up Email Alerts

What good is a network monitoring tool if you have to sit at a monitor and constantly be watching and waiting for trouble to occur. What you need is a monitoring system that will alert you when something is amiss. It is possible to set Nagios up for this feature. And it doesn’t take too much time and effort to pull off. I will say that you must have a working email system up and running. If you do not, take a look at my article “Install and configure a Postfix mail server” and find out how to quickly set up a solid mail server. Once you have that done all you will need is the email addresses you want to use for your alerts.

The configuration file you will be using is /etc/nagios3/conf.d/contacts_nagios2.cfg. Although we are working with Nagios3, the “2” in the configuration file name is correct. Within this file you will find a section that looks like:

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

The text in bold you see above will be the text you need to configure for your alerts. If you need more than one email address to be alerted, you have to add a defined for each user.  Most of the definitions above will be pretty obvious. The service_notification flags are defined as such:

  • w = notify on warning states
  • c = critical states
  • r = recovery
  • f = start/stop of flapping
  • d = notify on down states
  • u = notify on unreachable states
  • s = notify on stopped states

You can pick and choose what states you want to be alerted for.

Once you have edited this file, save it, close it, and restart Nagios with the command:

/etc/init.d/nagios3 restart

You are now ready to move on. The next section will be to define a contact group. Contact groups allow you to group people together so it is easier to alert specific people to certain events. This way you can have web-admins, file-server-admins, firewall-admins, and so on. Each group would have a specific user (or users) associated with it who would be alerted if a problem arises.

Go back to the same file you were just editing and look for the section labeled CONTACT GROUPS. In this section you will define a group like so:

define contactgroup {

     contactgroup_name   GROUPNAME

     alias GROUP ALIAS

     members USERNAME1, USERNAME2

}

All fields in BOLD are user specific.

Once you have defined all of your groups, save that file and close it. Now you have to attach groups to services so those groups will be alerted when something is wrong with their specific service. To do this open up the file /etc/nagios3/conf.d/services_nagios2.cfg. In this file you will find a few pre-defined groups (HTTP, SSH, and PING). Let’s say you created a contact group called Web-Admins and want to associate that group with all HTTP services. To do this look for the section:

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

To this section add the following line:

contact_groups Web-Admins

Save the file and close it. Now restart Nagios again and your monitoring system will begin sending out any HTTP errors to everyone associated with the Web-Admin group. Pretty nifty, eh?

Final Thoughts

The Nagios network monitoring tool is a very flexible tool that can monitor any sized network. And now, as you can see, Nagios can also keep any sized administrative team alert of any issues that are going on with devices and/or services. In my next Nagios article I am going to show you how to enable external commands so that Nagios can be even more functional, flexible and reliable.