Initially, configuring Nagios can seem daunting, and there is a fair amount of startup overhead to getting things going. But keep in mind that:
- It is not as hard or as time-consuming as it initially seems.
- It is well worth the effort.
Nagios uses the following configuration files:
- nagios.cfg: This is the main Nagios configuration file, containing global settings for the package. It defines directory locations for the package's various components, the user and group context for the daemon, what items to log, log file rotation settings, various time-outs and other performance-related settings, and additional items related to some of the package's advanced features (such as enabling event handling and defining global event handlers).
- Object configuration files: This class of files specifies which hosts and services are monitored. In addition, they can be used to define host and service test commands, host groups, alerts and their recipients, event handlers, and other object-specific settings used by Nagios.
- cgi.cfg: This file holds settings related to the Nagios displays, including paths to Web page items and scripts, and per-item icon and sound selections. The file also defines allowed access to Nagios's data and commands.
- resource.cfg: This file defines macros that may be used within other settings for clarity and security purposes, such as to hide passwords from view in CGI programs.
The package provides sample starter versions of all of these file. We will consider some aspects of these file types in the remainder of this article.
Nagios configuration files are generally stored in /usr/local/nagios/etc.
The nagios.cfg File
This configuration file contains directives that apply to the entire Nagios monitoring system. Here is an annotated sample version illustrating some of its most important features:
The first part of the configuration file specifies various file locations, including the general log file, files holding service check command and notification and event handler command definitions (
These directives specify logging settings, including how often logs are rotated (here, daily), the archive directory for old files, whether to log significant problems to syslog as well, and whether to log individual event types.
# Global settings nagios_user=nagios nagios_group=nagios date_format=us admin_email=nagadmin admin_pager=19995551212
These lines specify various global settings, including the user/group as which the nagios daemon runs, the output format for dates (here, US style), and the administrator's email address. The final item sets the value of the
Settings related to event handlers. You can optionally define a single event handler for all host failures and service failures in this file if appropriate. Commands are defined in an object configuration file.
These directives control the number of maximum checks that can be made at the same time (0 means an unlimited number), as well as time-outs for various types of commands (values in seconds).
These lines tell Nagios to retain information about host and service status between sessions, saving the values every 60 seconds, and reloading them when the facility starts up.
These directives enable "passive checks": status data produced by external commands which Nagios imports periodically.
These directives allow you to save Nagios data externally for long term analysis or other purposes. The commands specified here must be defined in some object configuration file. The simplest such command simply writes the command's output to an external file: e.g., echo
Note that the directives appear in a slightly different order in the sample nagios.cfg file provided with the package.