Nagios Network Monitoring System Setup on Ubuntu

Publié le 24 décembre 2008 par Theclimber

Nagios is a free, open-source tool that can be used to monitor network components and services. When it detects a problem, it can send alert messages by either e-mail or pager. It can also be configured so that only designated personnel can view status information for particular services or equipment. This tutorial will show you how to install Nagios 3 on an Ubuntu 8.10 server. Installation

Nagios3 is in the repository for Ubuntu 8.10.

Install Nagios

sudo apt-get install nagios3

You can see that it will install a number of packages to make it all work.

Once it is installed run a pre-flight check to verify it is working correctly.

Pre-Flight Check

sudo nagios3 -v /etc/nagios3/nagios.cfg

Create Nagios user

By default it should run and you should be able to login to the web interface after you create the nagios user. Move into the /etc/nagios3 directory and create a user to access the web interface.

cd /etc/nagios3
sudo htpasswd -c htpasswd.users nagios
New password:
Re-type new password:
Adding password for user nagios

Login into nagios webpage

Now login to the web interface with http://ip_address/nagios3

You will not have all of the rights to view everything but for the purposes of making sure it all works you will see it is all running. Now you need to configure it for your settings.

Basic Configuration

The configuration is where you will get to set up the services and hosts that you need.

Now, cd to the /etc/nagios3 directory.

cd /etc/nagios3

Here you will see the base file nagios.cfg. The additional configuration files are located in conf.d.

contacts_nagios2.cfg          generic-service_nagios2.cfg      localhost_nagios2.cfg
extinfo_nagios2.cfg           host-gateway_nagios3.cfg         services_nagios2.cfg
generic-host_nagios2.cfg      hostgroups_nagios2.cfg           timeperiods_nagios2.cfg

Check the "timeperiods_nagios2.cfg" file to define different time periods for when you want certain functions to happen. Here’s an example:

# Time periods
# All times are valid for all
# checks and notifications

define timeperiod{
timeperiod_name 24×7
alias              24 Hours A Day, 7 Days A Week
sunday          00:00-24:00
monday        00:00-24:00
tuesday         00:00-24:00
wednesday    00:00-24:00
thursday        00:00-24:00
friday            00:00-24:00
saturday        00:00-24:00
}

define timeperiod{
timeperiod_name 8×5
alias                8 Hours A Day, 5 Days A Week
monday          08:00-16:00
tuesday           08:00-16:00
wednesday     08:00-16:00
thursday         08:00-16:00
friday             08:00-16:00
}

Check, the "contacts_nagios2.cfg" file. This will define the types of notifications that individuals and groups will receive, and when they will be contacted.

# Contacts–Individuals and Groups

define contact{
contact_name                                greg
alias                                              Nagios Admin
service_notification_period          24×7
host_notification_period               24×7
service_notification_options        w,u,c,r
host_notification_options              d,r
service_notification_commands    notify-by-email
host_notification_commands         host-notify-by-email
email                                              greg@localhost
}

The email account that you add for the Nagios Admin should be your main email account as this will be used to send you information.

# contact groups
# Nagios only talks to contact groups, not individuals
# Members must be Nagios users, alias and contact_group
# are whatever you want

define contactgroup{
contactgroup_name               admins
alias                                       Nagios Administrators
members                                 greg
}

In this file, each person who is to be a contact must have his own "define contact" section. Each person must also be a member of a "contactgroup". Also, each person who is to be a contact must have a system account on the Nagios server, have a Nagios password, and be a member of the "nagios" group. (This group will be created automatically when you install Nagios.)

sudo useradd -m -G nagios greg

If you haven’t yet created the Nagios password database, you’ll use the "htpasswd" command with the -c option to create the new file.

sudo htpasswd -c /etc/nagios/htpasswd.users nagios

If the database has already been created, and you just want to add a new user to it, then omit the -c option. You can also add a line into the file using this script http://home.flash.net/cgi-bin/pw.pl