plugin – Plugin Class¶
This module provides the Plugin class, which is the basic class which encapsulates a single plugin. This is the class which should be subclassed when creating new plugins.
-
class
pycinga.plugin.Plugin([argv=sys.argv])[source]¶ Instantiates a plugin, setting up the options and arguments state. Initialization by itself shouldn’t do much, since the plugin should run when
check()is called.This init method will parse the arguments given in
argsand will set the results on theoptionsattribute. If noargsare given, the command line arguments given to the whole Python application will be used.All plugins parse standard command line arguments that are required by the Icinga developer guidelines:
hostname- Set via-Hor--hostname, this should be the host that this check targets, if applicable.warning- Set via-wor--warning, this should be a valid range in which the value of the plugin is considered to be a warning.critical- Set via-cor--critical, this should be a valid range in which the value is considered to be critical.timeout- Set via-tor--timeout, this is an int value for the timeout of this check.verbosity- Set via-v, where additionalvmeans more verbosity. Example:-vvvwill setoptions.verbosityto 3.
Subclasses can define additional options by creating
Actioninstances and assigning them to class attributes. The easiest way to make anActionis to use Python’s built-inargparsemethods. The following is an example plugin which adds a simple string argument::class MyPlugin(Plugin): parser = ArgumentParser() parser.add_argument("--your-name", dest="your_name", type="string")
Instantiating the above plugin will result in the value of the new argument being available in
options.your_name.-
options¶ Dictionary of parsed command line options and their values. As an example, to get the
hostnamepassed in via the command line::options.hostname
-
args¶ Array of additional positional arguments passed in via the command line. For example, if you call the plugin with
./plugin 1 2 3, thenoptions.argswill return[1,2,3].
-
check()[source]¶ This method is what should be called to run this plugin and return a proper
Responseobject. Subclasses are expected to implement this.
-
response_for_value(value, message=None)[source]¶ This method is meant to be used by plugin implementers to return a valid
Responseobject for the given value. The status of this response is determined based on the warning and critical ranges given via the command line, which the plugin automatically parses.An optional
messageargument may be provided to set the message for the Response object. Note that this can easily be added later as well by simply setting the message attribute on the response object returned.Creating a response using this method from
check()makes it trivial to calculate the value, grab a response, set some performance metrics, and return it.