Configure Nagios

This will guide you through a basic setup of a host and some services for Nagios.


First thing to note is that Nagios Core has no web based UI for configuring hosts, services or commands.



Adding a Host


To start the configuration, add a host. You can choose the default location to create a hosts file;


Any new files/directories created must be added to nagios.cfg;


New files are added as follows;


Once you have created the new file, open it with your text editor;


A simple linux host is defined as follows;


The “use” part of this host definition is taken from;


Here you can choose the default settings for a host, e.g. contact groups, notifications enabled, retry attempts.


A full list of possible host definitions can be found here;


If you wish to set a specific setting for just a few hosts, adding it to the hosts.cfg folder overrides the template.



Plugin Usage and Adding Commands


Commands are added through the commands.cfg file located here;


Adding a command requires a plugin for the command you wish to add, as well as knowledge on how to use the plugin.


The default locations for plugins you wish to add can be found here;


To know what command is required for a plugin to work, you can request help on the plugins usage;


Note that some plugins may require pre-requisites, which will be prompted when you attempt to use the plugin in the command line.


An example would be the plugin check_ping which has the following output when you use the “-h” argument;


This helps you understand how to define a command.


Now edit the commands.cfg file and look for the check_ping command definition;


– This is the name you use to define this command. This is used in the service definition to reference this command.

– This is defined in /usr/local/nagios/etc/objects/resources.cfg. In this case it defines the plugin directory being used (/usr/local/nagios/libexec).
“check_ping” requires the arguments -H, -w and -c.


– This defines the host which needs to be checked, and is common in nearly all plugins. The $HOSTADDRESS$ part is an inbuilt Nagios macro which uses the hostname defined in the service command. This won’t need to be defined in each service which uses this commands, as you will see below.

– This sets the warning value which is required for the plugin to work. The $ARG1$ is defined in the service command.


– This sets the critical value which is required for the plugin to work. The $ARG2$ is defined in the service command.


– This argument is an optional addition to the command definition. By not using $ARG3$ we are saying that every time this command is used, set “-p” to “5”.

Adding Services


Now you have a host and a command, you need a service!


This services config file can be created/found in the same place as the host file;


Remember to add this location to nagios.cfg if it isn’t already there.


Now you need to add some services to the config file for your host.


The service for ping is defined as follows;


With regards to the “check_command”, this is where you define the command to be used for this service by entering the “command_name” defined in commands.cfg.


– This is the “command_name”. This is always entered first.


After the command_name, you must enter the details for $ARG1$, $ARG2$, etc. These are separated by an exclamation mark, “!”.


– This the response time of the ping request. If it’s sufficient for this argument, you will receive a WARNING status.


– This the response time of the ping request. If it’s sufficient for this argument, you will receive a CRITICAL status.

As before, the “use” part is defined in templates.cfg.


A full list of service definitions can be found here;


Adding a definition to services.cfg overrides the template.

You now have a new host configured with the ping service.





If you will have, say, 10 linux servers, all requiring the “ping” command, it would be best to define a hostgroup in the host and service definitions instead of the host name.


A hostgroup is created as follows;



Note that when adding hostgroups/hostgroup_name to the host/service definitions, respectively, they are seperated by commas.


These basic steps can be repeated for most plugins – the only differences come when using NRPE, NSCA, or a custom plugin, but even then the basics are essential, or when you are missing pre-requisites for the plugin to work.

When you are finished with your customization, run the command below to confirm that there are no issues with the configuration files;

Any problems are made apparent to you after running this command, telling you both the file and line where the error occurs.


This makes debugging errors very easy.


If there are no problems, you can restart nagios and head to the web page;


On a web browser;

http://<nagios server ip>/nagios


The following will be how the ping service is displayed;


Tags: , ,


on July 5, 2018

We have started using medium for our blogging. Please click here to see our latest posts.

on February 9, 2015

BaseX Blog Introduction This 'Blurt/Blog' details my experiences of a recent

on December 4, 2013

iCosts - The Legal Costs Calculator - Demo

on December 4, 2013

Lync XMPP + Video - Demo

Contact Us

9th Floor Capital House
40-42 Weston Street
SE1 3QD 0207 100 1499 Follow us Like us

Specialists in integrated and flexible communications

Copyright © 2013 Globility Limited. All rights reserved.