Tip

Using Nagios plugins for configuration and system testing

This is the third installation in a series of tips on using the open source network monitoring tool Nagios. Part one of the series covers Nagios installation

Requires Free Membership to View

and configuration, while part two detailed how to use Nagios for remote server monitoring. In this part of our series, you’ll learn about using Nagios plugins.

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:

define service{

     use                 local-service  ; Name of service template to use

     host_name           localhost

     service_description HTTP

     check_command       check_http

     notifications_enabled  0

 }

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:

Exit code

Status

Description

0

OK

Working correctly

1

WARNING

Working, but needs attention

2

CRITICAL

Not working correctly

3

UNKNOWN

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 <nagios@nagios.org>

Copyright (c) 2000-2007 Nagios Plugin Development Team

            <nagiosplug-devel@lists.sourceforge.net>

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 <crta>,<cpl>%
[-p packets] [-t timeout] [-4|-6]

Options:

-h, --help   
   Print detailed help screen
-V, --version
    Print version information
-4, --use-ipv4
    Use IPv4 connection
-6, --use-ipv6
    Use IPv6 connection 
-H, --hostname=HOST
    host to ping
-w, --warning=THRESHOLD
    warning threshold pair
-c, --critical=THRESHOLD
    critical threshold pair
-p, --packets=INTEGER
    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 is.

define command{

     command_name  check-host-alive

     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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.