Working With Nagios Plugins

From Zenoss Wiki
This is the approved revision of this page, as well as being the most recent.
Jump to: navigation, search

In this HowTo we will use the Nagios check_http plugin to check for specific content of a web page (implicitly checking for server/page 200 status as well).

Test the Plugin without Zenoss

The first thing you want to do is make sure that the plugin works from the command line. If it does, you're ready to work with the plugin in Zenoss. For example:

[root@zenoss ~]# /usr/lib64/nagios/plugins/check_http -H -u / -s "Zenoss, Inc."
HTTP OK: HTTP/1.1 200 OK - 43792 bytes in 0.314 second response time |time=0.314421s;;;0.000000 size=43792B;;;0

For details on the parameters passed to various Nagios plugins, be sure to consult the plugin documentation and usage examples.

We see that this works and are ready for the next step.

Determining the Device Scope

Next we need to think about where this plugin will run. Will it run for all devices? For all Linux boxen? For all web pages? Depending on the answer to these questions, you will configure your Nagios template in a different location of the Zenoss device tree. Obviously, this particular check will only pertain to a web server or a cluster of web servers serving the same content.

Creating a Template on a single device

  1. Navigate to wherever your web servers are in your device tree, lets say /server/linux/
  2. Select the blue "Details" button
  3. click on an existing Monitoring Template in the tree on the left.
  4. Select the "Gear" button at lower left and "Add Local Template"
  5. Name it something like Nagios-Webserver
  6. click on the template
  7. click "Add a Data Source" and select "COMMAND" from the drop-down

Before we make changes, let's go through the fields that became available to us once we selected the COMMAND source type:

  • Name - what we named the data source when we created it
  • Type - the means by which this data source will be obtaining data; support for Nagios and Cacti plugins is bundled in the "COMMAND" source type
  • Enabled - whether or not this data source will be used when regular checks are performed
  • Severity - the severity for the failure of this check
  • Cycle Time - the interval (in seconds) between checks of this data source
  • Parser - Zenoss 4 can handle many new types of command notifications, you'll be wanting NAGIOS
  • Event Class - the type of event; this will annotate the event and show up in the "eventClass" column when viewing /zport/dmd/Events/viewEvents
  • Use SSH - whether or not SSH is required to run this check
  • Component - the Zenoss component with which we want to annotate any events generated from the check of this data source; see the "component" column when viewing /zport/dmd/Events/viewEvents
  • Event Key - this is used by Zenoss to prevent the duplication of events; Component, Event Class and Event Key are used to determine uniqueness of source for alerts
  • Command Template - what to run (more details below)

Thus informed, we can now edit the data source, entering our Nagios-specific information. We've already got our data source's name and source type, so let's continue from there:

  • Type - COMMAND (this can't be changed)
  • Enabled - Checked
  • Severity - Set this low enough that you won't melt your SMS gateway and e-mail server while you're testing "Warning" or less probably.
  • Event Class - /status/web (or as appropriate)
  • Parser - Nagios
  • Use SSH - Unchecked
  • Component - "pagechecks" or as appropriate
  • Event Key - default page test
  • Command Template - /usr/lib64/nagios/plugins/check_http -H $devname -u / -s "Zenoss"

Adding Your Template Elsewhere

You can add your template to an entire device class or anywhere else in the Device tree it's needed by navigating to that spot, and clicking "Details". From there click an existing monitoring template, click the "Gear" menu at lower-left, and "Bind Template".


To test your new command, at the command line, use the zencommand tool:

[root@zenoss ~]# zencommand run -d -v10 --showfullcommand

In the output, you should see zencommand find the new command, execute it, and store the results. This completes the setup and configuration of a Nagios style plugin.

this article based on an article produced by Noel Brockett, and edited by Andrew Kirch for 4.x