Platforms: Unix

NagAconda – Python Nagios Integration

Nagios has been around for quite some time, but producing output it can consume is something of a black art. Only the plugin documentation actually explains what all the extra semicolons or extended formatting even means.

This is especially onerous when performance consuming add-ons expect a specific structure before operating properly. This package strives to greatly simplify the process of actually generating Nagios output.

Plugin – Nagios Plugin Wrapper

Platforms: Unix

The Plugin module provides all the parts necessary to create a simple Nagios report for a service or host check by removing all that pesky inside knowledge necessary. All the classes and methods provided here reduce plugin creation to a few lines of python unless the plugin is especially complex.

All specifications for this module are obtained from the Nagios developer documentation.

Usage

from NagAconda import Plugin
from Person import Dude

feet = Plugin("Plugin to quantify current foot odor.", "1.0")
feet.add_option('t', 'target', 'Person to check for odor.',
    required=True)

feet.enable_status('warning')
feet.enable_status('critical')
feet.start()

roommate = Dude(feet.options.target)
feet.set_value('stench', rommmate.gym_socks())

feet.finish()

API Specification

class NagAconda.Plugin(description, version)

This is the primary control class for NagAconda.

The attributes available here are direct-access to parsed options and arguments, not class-level variables.

options
This contains all of the options obtained from the command line for this plugin. This includes any options registered by the master class.
arguments
After start is called, all command-line options are read, and anything left over is placed into this object for further use. Most Nagios parsers use explicit option setting, so you might never use this.
add_option(flag, name, helptext, **kwargs)

Adds a Nagios-style help option to this plugin.

Parameters:
  • flag – A one-letter shortcut for this option.
  • name – The full name for this option.
  • helptext – Instructions for usage of this option.
  • required (True or False) – Force option for plugin execution. Default False.
  • action (Setting string. Default ‘store’) – What type of storage action should take place for this parameter? This is the same as the OptionParser ‘action’ setting. Default is ‘store’.
  • callback (function reference or None) – When action is callback, use specified function.
enable_status(status_type, required=False)

Enable warning or critical exit statuses.

Nagios requires error levels to be returned by the running application to evaluate exit status since the text is indeterminate. For Nagios:

  • 0 - Status OK
  • 1 - Plugin is notifying a warning state.
  • 2 - Plugin is notifying of a critical error or state.
  • 3 - Some unknown or unhandled error occurred.
  • other - Nagios will report this as a plugin failure.

By default, warnings and critical errors are not enabled, in case the plugin is just tracking values. This method will turn them on and add the proper command-line elements so the user can set them.

Note

If warning or critical is enabled, failing to provide them to the plugin will result in an automatic exit and presentation of the usage documentation.

When plugins make use of multiple performance metrics, they may also have different scales, and hence warning/critical ranges involved. In this case, ranges must be passed by the command-line in comma-delimited format.

Parameters:
  • status_type – Should be either warning or critical.
  • required (True or False. Default False.) – Should this threshold be a required option?
finish()

Checks the proper warning/errors and prints out all results.

Once all values have been set through ordinary means, it remains to check them against our warning/critical status ranges if necessary and output all our wonderful results so Nagios can consume them.

set_value(name, val, **kwargs)

Set a performance measurement for output to Nagios.

There is theoretically no limit on the number of metrics being tracked in Nagios performance output. That said, we strongly recommend reading the Nagios developer docs to understand how warning and critical test ranges are handled.

Should a minimum or maximum value be provided here, they will only be used to build percentage ranges, and will not otherwise affect operation of Nagios.

This should always be called after the start method.

Note

Any value parameter that is not submitted as an numeric type will be converted to one so tests work properly.

Parameters:
  • name – Name of the performance setting.
  • val (float or None) – Value observed for this iteration.
  • lowest (float or None) – Minimum possible value for this setting. Optional.
  • highest (float or None) – Maximum possible value for this setting. Optional.
  • scale (string or None) – The unit of measurement to apply to this value. should be a byte measurement (B, KB, MB, GB, TB) or a unit of time (s, ms, us, ns), or a percentage (%).
  • threshold (integer, default 1) – Which warning/critical range to target for this value? Default 1, since most never use more.
Raises ValueError:
 

When an invalid scale is passed.

Returns string:

One of ‘ok’, ‘warning’ or ‘critical’, as to how this value compared to the enabled and supplied thresholds.

start()

Invokes all preparation steps to retrieve host/service status.

Starts the actual plugin’s work. The Plugin class will start by parsing any options so the whole process can short-circuit before we do anything important.

Note

This method may exit directly to the console.

Table Of Contents

Previous topic

Welcome to NagAconda’s documentation!

This Page