Table of Contents
Nagios Core Configuration - nagios.cfg, cgi.cfg, resource.cfg
In the case that you have followed steps mentioned at installation of the Nagios Core document at this web page it is located at:
“/opt/nagios-<VERSION>/etc/nagios.cfg”
“/opt/nagios-<VERSION>/etc/cgi.cfg”
“/opt/nagios-<VERSION>/etc/resource.cfg”
Preface
Nagios Core is using several configuration files that have direct or indirect definition of the relation to each other.
In this document I would like to describe the functionality of the main configuration files used at Nagios Core. On another hand I think that it is pointless to copy the whole official documentation from Nagios project in to tis document. According to this I will try to find the balance between information that can help to understand how it is working and pointing to official documentation.
nagios.cfg
Nagios Core 3 “nagios.cfg” documentation: http://nagios.sourceforge.net/docs/nagioscore/3/en/configmain.html
Nagios Core 4 “nagios.cfg” documentation: http://nagios.sourceforge.net/docs/nagioscore/4/en/configmain.html
The main configuration file of Nagios Core is called “nagios.cfg”. In the case that you have followed steps mentioned at installation of the Nagios Core document at this web page it is located at “/opt/nagios-<VERSION>/etc/nagios.cfg” .
Mentioned configuration file will be used at start of Nagios Core demon. It is including the configuration of Nagios Core, as well it is possible to define additional files that can provide particular configuration used at Nagios Core.
According to this it is common to split the configuration across several files. It is possible to create file system hierarchy that will provide the possibility to logical grouping of the configuration objects.
Please:
- Backup the file before you will change it. In case that you will need to do roleback it really hand.
- After you has done the change validate the configuration integrity with:
# /opt/nagios-<VERSION>/bin/nagios -v /opt/nagios-<VERSION>/etc/nagios.cfg # -v is for Validation . . . Total Warnings: 0 # you'll get this!!! Total Errors: 0 Things look okay - No serious problems were detected during the pre-flight check
cfg_file (split the configuration)
In the case that you are looking for way how to logical order the configuration across the file system. This is one of the main parameter that will be interesting for you.
With help of “cfg_file”used at “nagios.cfg”config file, it is possible to configure multiple paths to several different files across the file system.
In this case each configuration parameter is including only one configuration file that will be included in to Nagios Core configuration.
Example:
# grep cfg_file nagios.cfg cfg_file=/opt/nagios-4.0.7/etc/objects/commands.cfg cfg_file=/opt/nagios-4.0.7/etc/objects/contacts.cfg cfg_file=/opt/nagios-4.0.7/etc/objects/timeperiods.cfg cfg_file=/opt/nagios-4.0.7/etc/objects/templates.cfg cfg_file=/opt/nagios-4.0.7/etc/objects/localhost.cfg
cfg_dir (split the configuration)
In the case that you are looking for way how to logical order the configuration across the file system without defining each configuration file. This is one of the main parameter that can help you.
With help of “cfg_dir”used at “nagios.cfg”config file, it is possible to configure multiple folders where it is possible to store configuration of Nagios Core. This will prevent the need to define each configuration file with “cfg_file” parameter.
All configuration files need to have
name in“*.cfg”format. It mean that Nagios Core will take in to account only files that are using suffix “.cfg”, located at the defined directory.
In the case that you would like to build a hierarchical structure like:
|-- Customer # Directory |-- Customer-HostGroup.cfg # Config file |-- Customer-ServiceGroup.cfg # Config file |-- Region # Directory |-- Region-HostGroup.cfg # Config file |-- Region-ServiceGroup.cfg # Config file |-- Town # Directory |-- Town-HostGroup.cfg # Config file |-- Town-ServiceGroup.cfg # Config file |-- Street # Directory |-- Street-HostGroup.cfg # Config file |-- Street-ServiceGroup.cfg # Config file |-- Host.cfg # Config file |-- Service.cfg # Config file
It is possible to build this hierarchy direct at file system like directory structure. In this case it will be enough to configure “cfg_dir” variable with the path to the top of the file system hierarchy “Customer”. In case like this Nagios Core will take recursively all included folders and directories to look for files with suffix “.cfg” to include then in to Nagios Core configuration.
Example:
# grep cfg_dir nagios.cfg cfg_dir=/opt/nagios-4.0.7/etc/objects/Customer1 cfg_dir=/opt/nagios-4.0.7/etc/objects/Customer2 cfg_dir=/opt/nagios-4.0.7/etc/objects/Customer3 cfg_dir=/opt/nagios-4.0.7/etc/objects/Customer4 cfg_dir=/opt/nagios-4.0.7/etc/objects/Customer5
date_format
Nagios Core is using as default the US format of the time. In some cases it is too confusing for the peoples that are using this tool. According to this it is sometime better to change it to another format.
Supported formats are:
# us (MM-DD-YYYY HH:MM:SS) # euro (DD-MM-YYYY HH:MM:SS) # iso8601 (YYYY-MM-DD HH:MM:SS) # strict-iso8601 (YYYY-MM-DDTHH:MM:SS)
Example:
# grep date_format nagios.cfg date_format=strict-iso8601
User/Group
In UX world each process has his owner and owner group. Based on this it is possible to restrict access rights to some resources at OS level.
Nagios Core is using as well definition of User and Group that will be used for running Nagios Core demon. According to this all files and directories that need to be accessible for Nagios Core demon need to belong to the right user and group.
Configure the user and group:
# grep -e "nagios_user" -e "nagios_group" nagios.cfg nagios_user=nagios nagios_group=nagios
enable_notifications
In the case that you are building a failover Nagios Core infrastructure. It is handy to know that it is possible to enable/disable to send any notification out of Nagios Core with one parameter at “nagios.cfg” file.
Example:
# grep enable_notifications nagios.cfg enable_notifications=1 # 1 = enable notifications, 0 = disable notifications
Passive Monitoring
In case that you are going to integrate Nagios Core with another tools. That are able to send unsolicited messages to Nagios Core to change the status of monitored object. It is required to enable this at “nagios.cfg” configuration file.
To enable passive monitoring it is required to configure this parameters:
# grep accept_passive nagios.cfg accept_passive_service_checks=1 # 1 = accept passive checks, 0 = reject passive checks accept_passive_host_checks=1 # 1 = accept passive checks, 0 = reject passive checks
External Command Interface
The design of the Nagios Core is so nice, easy and brilliant. It is providing us interface that can be used for passive monitoring, as well for changing of parameters at running Nagios Core.
In general this interface is a named pipe (FIFO). According to this we can just write our commands in to mentioned FIFO file like in to any standard file.
To enable it you will need to configure:
# grep check_external_commands nagios.cfg # This option allows you to specify whether or not Nagios should check for external commands. check_external_commands=1 # 0 = disable commands, 1 = enable commands # grep command_file nagios.cfg # This is the file that Nagios checks for external command requests. command_file=/opt/nagios-4.0.7/var/rw/nagios.cmd # Path to the file
Any way this is not topic of this document, as well it is not really common to use it in this way.
Event Broker
Nagios Core is able to integrate additional components. In this way it is possible to integrate Nagios Core with several different tools. One of the integration way is to use Nagios Core Event Broker (called as well NEB).
In this way the Nagios Core will share operational status with another application. In this way it is possible to integrate for example MySQL backend for Nagios Core.
Example:
# grep event_broker_options nagios.cfg # Enable NEB event_broker_options=-1 # 0 = Broker nothing , -1 = Broker everything , <other> = See documentation # grep broker_module nagios.cfg # Configure NEB # broker_module=<modulepath> [moduleargs] #broker_module=/somewhere/module1.o #broker_module=/somewhere/module2.o arg1 arg2=3 debug=0
Embedded Perl (ePN)
it is obsolete at Nagios 4
cgi.cfg
Nagios Core 3 “cgi.cfg” documentation: http://nagios.sourceforge.net/docs/nagioscore/3/en/configcgi.html
Nagios Core 4 “cgi.cfg” documentation: http://nagios.sourceforge.net/docs/nagioscore/4/en/configcgi.html
In the “cgi.cfg” configuration file it is possible to configure parameters related to Nagios Core Web GUIand CGI scripts. In most case you will not really need to change it. On another hand in the case that you would like to play with your Nagios Core web interface here are the configuration parameters.
In the case that you have followed steps mentioned at installation of the Nagios Core document at this web page it is located at “/opt/nagios-<VERSION>/etc/cgi.cfg”.
main_config_file
This parameter is defining PATH to main Nagios Core config file.
Example:
# grep main_config_file cgi.cfg main_config_file=/opt/nagios-4.0.7/etc/nagios.cfg
physical_html_path
Path to directory including “index.php” that will be called when you will be started when you are using Web GUI
Example :
# grep physical_html_path cgi.cfg physical_html_path=/opt/nagios-4.0.7/doc
url_html_path
Definition of URL that will be used to access the main web page of Nagios Core
Example:
Used URL is http://127.0.0.1/nagios # grep url_html_path cgi.cfg url_html_path=/nagios
show_context_help
Providing help information that can be called directly from web browser.
Example:
# grep show_context_help cgi.cfg show_context_help=1 # 0 = disables , 1 = enables
use_authentication
Enable/Disable user authentication for accessing of Nagios Core Web GUI
# grep use_authentication cgi.cfg use_authentication=1 # 0 = disables , 1 = enables
Ignore Contact configuration
At each Host or Service related configuration it is possible to specify who can see the status of the particular object.
In case that you are using one administrator account that need to see all configured objects it is possible to enable it at this please to see all objects of Nagios Core (even it was not declared as a contact for particular object).
Example:
# grep authorized_for_ cgi.cfg authorized_for_system_information=nagiosadmin authorized_for_configuration_information=nagiosadmin authorized_for_system_commands=nagiosadmin authorized_for_all_services=nagiosadmin authorized_for_all_hosts=nagiosadmin authorized_for_all_service_commands=nagiosadmin authorized_for_all_host_commands=nagiosadmin #authorized_for_read_only=user1,user2
default_statusmap_layout
This option allows you to specify the default layout method the statusmap CGI should use for drawing hosts. If you do not use this option, the default is to use user-defined coordinates.
Valid options are as follows:
0 = User-defined coordinates
1 = Depth layers
2 = Collapsed tree
3 = Balanced tree
4 = Circular
5 = Circular (Marked Up)
Example:
# grep default_statusmap_layout cgi.cfg default_statusmap_layout=5
default_statuswrl_layout
This option allows you to specify the default layout method the statuswrl (VRML) CGI should use for drawing hosts. If you do not use this option, the default is to use user-defined coordinates.
Valid options are as follows:
0 = User-defined coordinates
2 = Collapsed tree
3 = Balanced tree
4 = Circular
Example:
# grep default_statuswrl_layout cgi.cfg default_statuswrl_layout=4
refresh_rate
This option allows you to specify the refresh rate in seconds of various CGIs (status, statusmap, extinfo, and outages).
Example:
# grep refresh_rate cgi.cfg refresh_rate=90
result_limit
This option allows you to specify the default number of results displayed on the status.cgi. This number can be adjusted from within the UI after the initial page load. Setting this to 0 will show all results.
Example:
# grep result_limit cgi.cfg result_limit=100
resource.cfg
The “resource.cfg” configuration file is including all paths (on file system) that are used at Nagios Core. It is possible to define 32 different paths.
In the case that you have followed steps mentioned at installation of the Nagios Core document at this web page it is located at “/opt/nagios-<VERSION>/etc/resource.cfg”.
Example:
# grep -v -e "^$" -e "^#" /opt/nagios-4.0.7/etc/resource.cfg $USER1$=/opt/nagios-4.0.7/libexec # Path to monitoring scripts used at Nagios Core
URL's
Nagios Core 3 “nagios.cfg” documentation: http://nagios.sourceforge.net/docs/nagioscore/3/en/configmain.html
Nagios Core 4 “nagios.cfg” documentation: http://nagios.sourceforge.net/docs/nagioscore/4/en/configmain.html
Nagios Core 3 “cgi.cfg” documentation: http://nagios.sourceforge.net/docs/nagioscore/3/en/configcgi.html
Nagios Core 4 “cgi.cfg” documentation: http://nagios.sourceforge.net/docs/nagioscore/4/en/configcgi.html