Network Monitoring With Nagios Plugins
Network Monitoring with Nagios Plugins
Server - Nagios

One of the major concepts of creating checks is to remember that all plugins with Nagios will require three elements to be configured.   There must be a host definition, a service definition and a command definition.  Think of it as a triangle each time you want to use a plugin.


Nagios Plugin Triangle

For more detailed Nagios training, check out our live, online, instructor-led Nagios classes.

These three definitions are all located in three separate files, hosts.cfg, services.cfg and commands.cfg.  You may need to create hosts.cfg and services.cfg as they are not created by default.  These files must be located in:


RPM Repository

Host Defintion

Nagios needs to know an IP Address of the host you want to check.  This is configured in the hosts.cfg file.  The hosts.cfg file does not exist initially so you will need to create it.  In this example the host_name is “win2008” and it is tied to the address “”.  This is the information Nagios must have to know where to point a request and how to record information for a specific host.

define host{
use                             windows-server
host_name                       win2008
alias                           Windows Server

Service Definition

The second part of the triangle is the service definition.  Nagios needs to know what service you want to check, so that service or plugin must be defined.  In this example the host “win2008”, which Nagios knows now is tied to the IP Address, is being checked with the ping plugin.  So you can see the host_name determines which host the plugin acts upon and then the service_description is really the text that shows up in the web interface.  The check_command, defines the parameters of the plugin.   Here you can see that “check_ping” is the plugin and it is followed by two different sections of options divided by “!”.  The first section, “60.0,5%”, provides a warning level if packets are take longer than 60 milliseconds or if there is greater than a 5% loss of packets when the ping command is performed.  The second section is the critical level where a CRITICAL state will b e created if packets take longer than 100 milliseconds or if there is more than 10% packet loss.

define service{
use                             generic-service
host_name                       win2008
service_description             Ping
check_command                   check_ping!60.0,5%!100.0,10%

Command Definition

The command definitions are located in the commands.cfg file which is created by default in the objects directory.  Many commands are already defined so you do not have to do anything.  The check_ping command is one example that has been defined.  The command_name, “check_ping”, is what is part of the service definition.  The command_line specifically defines where the plugin is located with the “$USER1$ macro.  This is equal to saying that the plugin check_ping is located in /usr/local/nagios/libexec (if you compiled).  The other 4 options include the host, using  the $HOSTADDRESS$ macro, a warning level (-w) using the $ARG1$ macro, the critical level (-c) using the $ARG2$ macro and the number of pings to use by default (-p 5).

# 'check_ping' command definition
define command{
command_name    check_ping
command_line    $USER1$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p 5

In each of the elements of the Nagios triangle you can see the importance of the term “definition” as each element must be clearly defined and each element is dependent upon the other definitions.