Alphamonk IT Systems Home | Articles | Contact Us | Services





Login
Username:

Password:

Remember me



Lost Password?

Register now!
Articles > Nagios > Nagios Configuration Basics

Nagios Configuration Basics

Published by Alphamonk on 2008/12/21 (1961 reads)
Nagios Config File Basics

Nagios is an open source application that can monitor any device on a network. Out of the box with a few configuration modifications Nagios can monitor a host’s availability on the network, Using the server client software model Nagios can preform more in-depth monitoriing of remote services, ports, and resources. The Nagios application is installed on a Server. This server is defined as the Nagios server. This Nagios server can not do much more than tell you the status of remote hosts and a bit more information about the local servers resource availability. To get more data from remote hosts Nagios uses a plug-in that is installed on the monitored device to get information about particular resources on the remote device like disk space usage, uptime (CPU usage), service availability .

Nagios is configured using ini style configuration files. These files use ascii text so the configuration files are as easy for you to decipher as they are for the computer to understand. The main configuration files are cgi.cfg, nagios.cfg resource.cfg.

cgi.cfg

The cgi.cfg file allows you to modify user permissions and set paths for the nagios system. The excerpt below shows the path where the main nagios configuration file (nagios.cfg) is located.

#################################################################
#
# CGI.CFG - Sample CGI Configuration File for Nagios 3.0.5
#
# Last Modified: 10-07-2007
#
#################################################################
# MAIN CONFIGURATION FILE
# This tells the CGIs where to find your main configuration file.
# The CGIs will read the main and host config files for any other
# data they might need.

main_config_file=/usr/local/nagios/etc/nagios.cfg

nagios.cfg

This configuration file specifies where the other configuration files are located and what their names are. I personally do a lot of editing on this file because I like the old style of separate configuration files for services, contactgroups, hosts and hostgroups. (Old habits die hard)
##############################################################################
#
# NAGIOS.CFG - Sample Main Config File for Nagios 3.0.5
#
# Read the documentation for more information on this configuration
# file. I've provided some comments here, but things may not be so
# clear without further explanation.
#
# Last Modified: 10-15-2008
#
##############################################################################


# LOG FILE
# This is the main log file where service and host events are logged
# for historical purposes. This should be the first option specified
# in the config file!!!

log_file=/usr/local/nagios/var/nagios.log


# OBJECT CONFIGURATION FILE(S)
# These are the object configuration files in which you define hosts,
# host groups, contacts, contact groups, services, etc.
# You can split your object definitions across several config files
# if you wish (as shown below), or keep them all in a single config file.

# You can specify individual object config files as shown below:
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_file=/usr/local/nagios/etc/objects/linuxservices.cfg
cfg_file=/usr/local/nagios/etc/objects/windowsservices.cfg
cfg_file=/usr/local/nagios/etc/objects/adminservices.cfg
cfg_file=/usr/local/nagios/etc/objects/contactgroups.cfg
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg

resources.cfg

This configuration file sets the path to the plug in directory
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
###########################################################################
#
# RESOURCE.CFG - Sample Resource File for Nagios 3.0.5
#
# Last Modified: 09-10-2003
#
# You can define $USERx$ macros in this file, which can in turn be used
# in command definitions in your host config file(s). $USERx$ macros are
# useful for storing sensitive information such as usernames, passwords,
# etc. They are also handy for specifying the path to plugins and
# event handlers - if you decide to move the plugins or event handlers to
# a different directory in the future, you can just update one or two
# $USERx$ macros, instead of modifying a lot of command definitions.
#
# The CGIs will not attempt to read the contents of resource files, so
# you can set restrictive permissions (600 or 660) on them.
#
# Nagios supports up to 32 $USERx$ macros ($USER1$ through $USER32$)
#
# Resource files may also be used to store configuration directives for
# external data sources like MySQL...
#
###########################################################################


The next set of configuration files are in the resources directory. The files in here are commands.cfg, contacts.cfg, localhost.cfg, printer.cfg, switch.cfg, template.cfg, timperiods.cfg, windows.cfg

commands.cfg

A sample commands.cfg file is installed when you run the configure script. It will contain some basic check commands that nagios can use. In our case we’ll be using the check_host_alive command. #################################################################################
# SAMPLE HOST CHECK COMMANDS
#################################################################################
# This command checks to see if a host is "alive" by pinging it
# The check must result in a 100% packet loss or 5 second (5000ms) round trip
# average time to produce a critical error.
# Note: Only one ICMP echo packet is sent (determined by the '-p 1' argument)
# 'check-host-alive' command definition
define command{
command_name check-host-alive
command_line $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 1
}

contactgroups.cfg

A contact group definition is used to group one or more contacts together for the purpose of sending out alert/recovery notifications. When a host or service has a problem or recovers, Nagios will find the appropriate contact groups to send notifications to, and notify all contacts in those contact groups.
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagios-admin
}

contacts.cfg

A contact definition is used to identify someone who should be contacted in the event of a problem on your network.
define contact{
contact_name nagios-admin
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7
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 youremail@mail.com
}

hostgroups.cfg

The hostgroups.cfg file allows you to organize your devices into logical groups like swtiches, firewalls, citrix servers etc… Groups are pretty easy to create. All you need to do is define the group and assign devices. When assigning devices you must use the hostname used in the hosts.cfg file.


define hostgroup{
hostgroup_name Linux Servers
alias Linux Servers
members ZEUS
}
Multiple devices can be added by using “,” (commas) as delimiters for your entries.
define hostgroup{
hostgroup_name Linux Servers
alias Linux Servers
members ZEUS,HADES,POSEIDON
}

hosts.cfg

hosts.cfg contain all the unique information that pertains to a individual host. There are many options that can be configured for hosts. One way to keep your configurations smaller and reduce repetition is by using templates. Templates allow you to set common settings that can be used for multiple hosts.
# Generic host definition template - This is NOT a real host, just a template!
define host{
name generic-host ; The name of this host template
notifications_enabled 1 ; Host notifications are enabled
event_handler_enabled 1 ; Host event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
failure_prediction_enabled 1 ; Failure prediction is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program

restarts
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL

HOST, JUST A TEMPLATE!
}
Once your template is setup you can begin adding hosts…
define host{
use generic-host ; Name of host template to use
host_name ZEUS ; Name of device being monitored
alias ZEUS ; Longer name or description of device
address 127.0.0.1 ; IP or FQDN of device being monitored
check_command check-host-alive ; Short name of command used to check if

host is up or down, usually a ping
max_check_attempts 10 ; Number of reties before an alert is sent
check_period 24x7
notification_interval 120 ; Time period to wait until re-notifying

contacts
notification_period 24x7 ; Time period where notifications are

allowed to be sent
notification_options d,r
contact_groups admins ; Groups that are notified when

notifications are sent
}

resource.cfg

The resource.cfg file is used to define resources external to nagios such as plugins.

services.cfg

A service definition is used to identify a “service” that runs on a host. The term “service” is used very loosely. It can mean an actual service that runs on the host (POP, SMTP, HTTP, etc.) or some other type of metric associated with the host (response to a ping, number of

logged in users, free disk space, etc.).
Again, a template is created to set some of the more common options.



# Generic service definition template - This is NOT a real service, just a template!
define service{
name generic-service ; The 'name' of this service template
active_checks_enabled 1 ; Active service checks are enabled
passive_checks_enabled 1 ; Passive service checks are enabled/accepted
parallelize_check 1 ; Active service checks should be parallelized

(disabling this can lead to major performance problems)
obsess_over_service 1 ; We should obsess over this service (if necessary)
check_freshness 0 ; Default is to NOT check service 'freshness'
notifications_enabled 1 ; Service notifications are enabled
event_handler_enabled 1 ; Service event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
failure_prediction_enabled 1 ; Failure prediction is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program

restarts
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL

SERVICE, JUST A TEMPLATE!
}

# Define a service to "ping" a machine
define service{
use generic-service ; Name of service template to use
host_name ZEUS
service_description PING
is_volatile 0
check_period 24x7
max_check_attempt s 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_options w,u,c,r
notification_interval 960
notification_period 24x7
check_command check_ping!100.0,20%!500.0,60%
}

timeperiods.cfg

The timeperiods.cfg file allows us to set time schedules for nagios to enable or disable checks and notifications.

Plugins


Plugins are the what make the Nagios server work with remote host. There are many plugins available for Nagios. I prefer to use nagios_statd version (2) plugins, as the base version that I modify to write additional plugins to make Nagios work with the unique services, host and devices that I want to monitor.

Navigate through the articles
Nagios notifications Next article
Voters total: 0
Average: 0
The comments are owned by the poster. We aren't responsible for their content.
Main Menu
ads
AddTo Social bookmarking block




� 2008 All Rights Reserved