About Nagios Configuration
This is a quick manual on Nagios configuration files. We will be explaining which configuration files you need to edit to add hosts, services, contacts and groups. Learn how to configure your Nagios from Linux console and check the configuration for errors.
In this Nagios configuration How To guide we will explain most of the files that are needed for Nagios to monitor your hosts and services and send alerts.

Nagios main configuration files:
-
nagios.cfg
Nagios.cfg is the main configuration file for your Nagios Core. This is where the location of Nagios log file, status.dat file, lock file and host and services state update interval is defined. It also defines Nagios user and group under which Nagios instance is running. By default you do not need to change any of the lines in this file and Nagios should be working perfectly. But this is the file you should add a line to, if you have a separate configuration file for monitoring Linux (or other) hosts (cfg_file=/usr/local/nagios/etc/objects/linux.cfg). If you have installed MK Livestatus, this is where you will have to define a “broker_module” – broker_module=/usr/local/lib/mk-livestatus/livestatus.o /usr/local/nagios/var/rw/live.
-
cgi.cfg
This configuration file defines Nagios access for people or groups. It focuses on Nagios web frontend configuration. You can define exactly what kind of rights certain users or groups have – authorized_for_all_services, authorized_for_all_hosts, authorized_for_read_only, … This is also where the main configuration file is defined and physical path to Nagios HTML files is configured. It also defines the URL Html path – if url_html_path=/nagios this means that Nagios is available at http://hostname.domainname/nagios. You can also define sound actions for certain alerts. By default this fileonly needs editing on user access rights.
Nagios Host and Services configuration files:
You can keep all of the hosts and services in one configuration file if you like, but i prefer you separate hosts and services based on operating systems. Host and services configuration files are usually located at /usr/local/nagios/etc/objects. Every host and services configuration file must also be defined in nagios.cfg file!
I will show you how to configure a separate .cfg file for Linux hosts. When creating a new linux.cfg file we first have to define host and service templates – and if needed hostgroup and service group templates.
Below is and example of linux.cfg file with defined host, service, host group and service group templates and a Linux host foo.geekpeek.net with defined services for PING, SWAP usage and Current Logged in Users.
-
linux.cfg
##### EXAMPLE LINUX.CFG #####
##### HOST AND SERVICE TEMPLATES #####
define host {
name linuxsrv-server ; The name of this host template
use generic-host ; Inherit default values from the generic-host template
check_period 24x7 ; By default, Windows servers are monitored round the clock
check_interval 1 ; Actively check the server every 5 minutes
retry_interval 1 ; Schedule host check retries at 1 minute intervals
max_check_attempts 10 ; Check each server 10 times (max)
check_command check-host-alive ; Default command to check if servers are "alive"
notification_period 24x7 ; Send notification out at any time - day or night
notification_interval 30 ; Resend notifications every 30 minutes
notification_options d,r ; Only send notifications for specific host states
contact_groups admins ; Notifications get sent to the admins
hostgroups linuxsrv-servers ; Host groups that Windows servers should be a member of
register 1 ; DONT REGISTER THIS - ITS JUST A TEMPLATE
}
define service {
name linuxsrv-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
is_volatile 0 ; The service is not volatile
check_period 24x7 ; The service can be checked at any time of the day
max_check_attempts 3 ; Re-check the service up to 3 times in order to determine its final (hard) state
normal_check_interval 5 ; Check the service every 10 minutes under normal conditions
retry_check_interval 2 ; Re-check the service every two minutes until a hard state can be determined
contact_groups hpunix-servers ; Notifications get sent out to everyone in the 'admins' group
notification_options w,u,c,r ; Send notifications about warning, unknown, critical, and recovery events
notification_interval 60 ; Re-notify about service problems every hour
notification_period 24x7 ; Notifications can be sent out at any time
register 1 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
}
define hostgroup {
hostgroup_name linux-servers
alias My Linux Servers
}
define servicegroup {
servicegroup_name MyServiceGroup
alias My Services
members Host1, Host2, Host3, Service1, Service2, Service3
}
##### DEFINED HOSTS AND SERVICES #####
define host {
use linuxsrv-server
host_name foo.geekpeek.net
alias Linux Server
address 192.168.123.150
contact_groups admins,linuxadm,aplicat
}
define service {
use linuxsrv-service
host_name foo.geekpeek.net
service_description PING
check_command check_ping!100.0,20%!500.0,60%
contact_groups admins,linuxadm,aplicat
}
define service{
use linuxsrv-service
host_name foo.geekpeek.net
service_description SWAP usage
check_command check_nrpe!check_swap
contact_groups admins,linuxadm,aplicat
}
define service{
use linuxsrv-service
host_name foo.geekpeek.net
service_description Current Logged in Users
check_command check_nrpe!check_users
contact_groups admins,linuxadm,aplicat
}
##### END #####
With this linux.cfg file we have defined a host foo.geekpeek.net in Nagios. This host is now visible in Nagios web frontend and Nagios is actively checking the state of the host and defined services. Of course client foo.geekpeek.net also has to have Nagios plugins and Nrpe service installed and properly configured.
Nagios Commands and Contacts configuration files:
-
commands.cfg
Command definitions for Nagios are defined in commands.cfg file. With these commands Nagios checks for hosts and services. Nagios locally runs a defined command, which responds back with the state of a host or a service. You can test these commands by running them from Linux console manually and checking their output.
##### EXAMPLE DEFINED COMMANDS #####
define command {
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
define command {
command_name check_telnet
command_line $USER1$/check_tcp -H $HOSTADDRESS$ -p 23
}
##### END #####
-
contacts.cfg
 M
Contacts and groups are defined in contacts.cfg file. Just one contact is defined in Nagios by default – this is the Nagios admin. All of the other contacts need to be defined additionally. Below is a sample of defined contacts.
##### EXAMPLE DEFINED CONTACTS #####
define contact {
contact_name concact1 ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias My Contact1 ; Full name of user
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
email contact1@geekpeek.net ; Contacts email address
}
define contact {
contact_name concact2 ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias My Contact2 ; Full name of user
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
email contact2@geekpeek.net ; Contacts email address
}
##### EXAMPLE DEFINED CONTACT GROUPS #####
define contactgroup {
contactgroup_name admins
alias Nagios Administrators
members contact1,contact2
}
define contactgroup{
contactgroup_name sys_admins
alias System Administrators
members user1,user2,user3,user4
}
##### END #####
Nagios configuration check:
There is a simple way to test the Nagios configuration for errors. You should do this everytime you change any of the nagios configuration files to make sure, that the next time you will stop and start Nagios service the service will start and not fail because of some syntax error.
This is the way to check Nagios configuration for errors:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
The output should be something like this:
Nagios Core 3.5.0 Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors Copyright (c) 1999-2009 Ethan Galstad Last Modified: 03-15-2013 License: GPL Website: http://www.nagios.org Reading configuration data... Read main config file okay... Processing object config file '/usr/local/nagios/etc/objects/commands.cfg'... Processing object config file '/usr/local/nagios/etc/objects/contacts.cfg'... Processing object config file '/usr/local/nagios/etc/objects/timeperiods.cfg'... Processing object config file '/usr/local/nagios/etc/objects/templates.cfg'... Processing object config file '/usr/local/nagios/etc/objects/mail.cfg'... Processing object config file '/usr/local/nagios/etc/objects/backup.cfg'... Processing object config file '/usr/local/nagios/etc/objects/windows.cfg'... Processing object config file '/usr/local/nagios/etc/objects/linux.cfg'... Processing object config file '/usr/local/nagios/etc/objects/networking.cfg'... Processing object config file '/usr/local/nagios/etc/objects/aix.cfg'... Processing object config file '/usr/local/nagios/etc/objects/hpux.cfg'... Processing object config file '/usr/local/nagios/etc/objects/localhost.cfg'... Read object config files okay... Running pre-flight check on configuration data... Checking services... Checked 1259 services. Checking hosts... Checked 119 hosts. Checking host groups... Checked 10 host groups. Checking service groups... Checked 3 service groups. Checking contacts... Checked 27 contacts. Checking contact groups... Checked 10 contact groups. Checking service escalations... Checked 0 service escalations. Checking service dependencies... Checked 0 service dependencies. Checking host escalations... Checked 0 host escalations. Checking host dependencies... Checked 0 host dependencies. Checking commands... Checked 82 commands. Checking time periods... Checked 5 time periods. Checking for circular paths between hosts... Checking for circular host and service dependencies... Checking global event handlers... Checking obsessive compulsive processor commands... Checking misc settings... Total Warnings: 0 Total Errors: 0 Things look okay - No serious problems were detected during the pre-flight check
Pingback: Nagios Core 3.5.0 CentOS install
Pingback: MK Livestatus CentOS install
Pingback: Nagios migration to a new Linux server
Pingback: Nagios 3.5.0 RPM install on CentOS
Pingback: Pnp4Nagios install – CentOS
Pingback: CHECK_NRPE: Error - Could not complete SSL handshake GeekPeek.Net
Pingback: Socket timeout after 10 seconds - Nagios GeekPeek.Net
Pingback: Nagios Core 4.0.0. Install on CentOS 6 | GeekPeek.Net
Pingback: Nagios3 on Ubuntu 14 server lts – webconfiguration
Pingback: Nagios configuration – How to configure Nagios – GeekPeek.Net | Tech @ MilneandFletch