Platforms: Unix
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.
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.
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()
This is the primary control class for NagAconda.
The attributes available here are direct-access to parsed options and arguments, not class-level variables.
Adds a Nagios-style help option to this plugin.
Parameters: |
|
---|
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: |
|
---|
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 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: |
|
---|---|
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. |
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.