Title: Configure Nagios Monitoring
Course: CIS 208: Linux/UNIX III: Intermediate System Administration, Networking, and Security ~ For IGNITE Review > Section: Learning Modules

Configure Nagios Monitoring

The configuration files for nagios monitoring are available in /etc/nagios.  The main file is /etc/nagios/nagios.cfg, and it includes other files.  Run "grep ^cfg_ /etc/nagios/nagios.cfg" to see the files and/or directories that are included.

The nagios.cfg file contains options for the service and some default values for hosts and services.  The default settings are quite good for a starting point.  If any configuration options are updated in this file or any other nagios configuration file, be sure to run the following command prior to restarting the service.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

If any critical errors are found, be sure to either fix them or restore the original version immediately.  Should the server reboot or the service be restarted, nagios will fail to run otherwise.

The users who are able to login to the website are managed in the /etc/nagios/cgi.cfg and the /etc/nagios/htpasswd files.  Create a new account by adding the user to htpasswd.

htpasswd  /usr/local/nagios/etc/htpasswd.users newuser

Next, grant permissions to the user in the cgi.cfg file.  Search for the lines which begin with "authorized_for" and add or remove individual access.

There are several types of objects in nagios, including contacts, groups, hosts, services, and timeperiods.  These are defined in the files in /etc/nagios/objects.  For example, here are three preconfigured timeperiods which are available for use.

define timeperiod{
timeperiod_name 24x7
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 workhours
alias           Normal Work Hours
Monday            09:00-17:00
Tuesday            09:00-17:00
Wednesday       09:00-17:00
Thursday          09:00-17:00
Friday               09:00-17:00
}

define timeperiod{
timeperiod_name none
alias           No Time Is A Good Time
}

The contacts are not the same as the web users, although it is possible to create a contact to correspond with each web user.  Here are the definitions of the default nagiosadmin contact and the admin group.

define contact{
contact_name             nagiosadmin
use                             generic-contact
alias                            Nagios Admin
email                          nagios@localhost
}
define contactgroup{
contactgroup_name        admins
alias                               Nagios Administrators
members                        nagiosadmin
}

A typical host definition inherits a template, signified by the "use" statement.  Here are the definitions of localhost, linux-server and generic-host.

define host{
use                       linux-server
host_name           localhost
alias                     localhost
address                127.0.0.1
}
define host{
name                            linux-server
use                               generic-host
check_period                    24x7
check_interval                  5
retry_interval                   1
max_check_attempts              10
check_command                     check-host-alive
notification_period                   workhours
notification_interval                 120
notification_options                 d,u,r
contact_groups                       admins
register                        0
}
define host{
name                  generic-host
notifications_enabled               1
event_handler_enabled           1
flap_detection_enabled            1
process_perf_data                   1
retain_status_information          1
retain_nonstatus_information    1
notification_period             24x7
register                        0
}

Likewise services use templates.  Notice that services need to be applied to one or more hosts.  In this example, the ssh service is checked on the localhost.

define service{
use                             local-service
host_name                  localhost
service_description                SSH
check_command                   check_ssh
notifications_enabled             0
}
define service{
name                             local-service
use                                generic-service
max_check_attempts                  4
normal_check_interval                5
retry_check_interval                   1
register                        0
}
define service{
name                            generic-service
active_checks_enabled                1
passive_checks_enabled              1
parallelize_check               1
obsess_over_service                    1
check_freshness                 0
notifications_enabled                   1
event_handler_enabled               1
flap_detection_enabled                1
process_perf_data               1
retain_status_information                   1
retain_nonstatus_information             1
is_volatile                     0
check_period                    24x7
max_check_attempts              3
normal_check_interval            10
retry_check_interval               2
contact_groups                  admins
notification_options                       w,u,c,r
notification_interval                       60
notification_period                         24x7
register                        0
}

It may take some time to get a feel for these configurations.  Generally speaking it is good to stay with the default options unless you have a good reason to change them.  Also, copy existing definitions when creating new objects, then update the name, host_name and other options as needed.

As always, run the following command prior to restarting nagios.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg