Nagios plugins play a key role in Nagios configuration and help perform specific tests, such as checking available disk space. For a Nagios system to perform certain tasks, you can use plugins from the service configuration files in /etc/nagios/objects.
To better understand how to use Nagios plugins, it’s best to look at a configuration file that uses one, such as localhost.cfg. By default, this file is available with all Nagios installations, and allows you to easily monitor the availability of services. The example below (Listing 1) shows how the file is used to monitor the httpd service:
local-service ; Name
of service template to use
Listing 1: Example of a service definition
In this service definition, five lines are used to define what has to be done. First, there is the inclusion of a template -- in this case, local-service. The local-service template is just another service file that contains several generic settings. Next, the definition describes which host should be monitored -- the localhost. After that, there is a short description of the specific service you want to monitor (HTTP), and on the fourth line, you’ll find the check_command. This command refers to a plugin, and in this case, it is check_http.
As previously mentioned, every Nagios installation comes with default plugins that perform
specific tests. Aside from the plugins that are installed by default, you can add custom
plugins to Nagios. Each is a command that is written to work with specific exit codes that
indicate the status of the monitored object. Based on the exit code, Nagios knows exactly what is
happening. When using a specific plugin, make sure to use the right options to define when a
specific exit code should be generated. The following exit codes are available:
Working, but needs attention
Not working correctly
Status of the host or service could not be determined
When working with plugins, using plugin command-line options is essential. Normally, every plugin uses common options: -t allows you to specify a timeout, -w allows you to specify limits before a warning status is reached and -c allows you to specify when the critical state is reached. By using these options in the service definition file, you have control over tuning the plugin. You can request a list of options that are supported by the plugin by running it with the --help command (Listing 2).
ittoqqortoormiit:/usr/lib/nagios/plugins # ./check_ping --help
check_ping v1991 (nagios-plugins 1.4.13)
Copyright (c) 1999 Ethan Galstad <email@example.com>
Copyright (c) 2000-2007 Nagios Plugin Development Team
Listing 2: Use the --help option with a plugin to find out which options are supported by the plugin.
Use ping to check connection statistics for a remote host (Listing 3):
Usage:check_ping -H <host_address> -w <wrta>,<wpl>% -c
[-p packets] [-t timeout] [-4|-6]
Print detailed help screen
Print version information
Use IPv4 connection
Use IPv6 connection
host to ping
warning threshold pair
critical threshold pair
number of ICMP ECHO packets to send (Default: 5)
Listing 3: This list of options is the result of the –help option with the check_ping command. This is how the command gives its output. Use -h as the short option and --help as the long option.
If using an option from the service definition is not appropriate for what you want to do, you
can define your own commands based on the use of plugins with specific parameters. Some commands
are available by default in the commands.cfg file, but nothing prevents you from adding your own.
In the following sample code (Listing 4), you can see how the check-host-alive command and the
check_ping plugin are used with specific parameters to find out what the current status of a host
command_line $USER1$/check_ping -H $HOSTADDRESS$
-w 3000.0,80% -c 5000.0,100% -p 5
Listing 4: By using plugins, you can build your own Nagios commands.
As you can see, Nagios uses a highly modular approach to determine what should be monitored. Plugins are key in specifying how to monitor an environment, and defining your own Nagios commands in the commands.cfg file is a convenient way to use the plugins. Make sure to look at the various available Nagios plugins, run them from /usr/lib/nagios with the --help option, and learn how they should be used. Understanding the available options will help you define your own commands and will help use them correctly in service definitions when customizing your Nagios environment. Now that you have learned about using Nagios plugins for configuration and testing, keep an eye out for a future tip on sending alerts with Nagios.
This was first published in November 2010