Plugin API reference¶
Reference for all classes.
Base class¶
This is the base class for all plugin classes.
NagiosPlugin — Base class for all class plugin¶
- class monitoring.nagios.plugin.NagiosPlugin(name=None, version='', description='')¶
Initialize a new Nagios Plugin.
Please avoid to override __init__ in derived classes. See initialize() to do this.
Parameters: - name – the name of the plugin. This is set to the name of the file by default.
- version (str, unicode) – the version of the plugin. Set it to anything you want.
- description (str, unicode) – a description of what is doing the plugin.
- critical(msg)¶
Raise a NagiosCritical exception.
- define_plugin_arguments()¶
Define arguments for the plugin.
Override this method to include yours.
- initialize()¶
Plugin level initialization.
Overrides this method if you need to init some attributes after __init__. This avoid to ovverrides __init__ in base class and also provide a way to init things before arguments sanity checks are run by verify_plugin_arguments().
- load_data()¶
Load pickled data.
Returns: list Raises IOError: raise IOError if pickle file is not found / readable.
- ok(msg)¶
Raise a NagiosOk exception.
- output(substitute=None, long_output_limit=20)¶
Construct and format the full string that should be returned to Nagios. Includes short output, long output and perf data (if any).
Parameters: - substitute (dict) – dict wih key/value pair that should be replaced in string (see str.format()).
- long_output_limit (int, None) – limit the number of lines of long output, default to 20. Set it to None for no limit.
Returns: str, unicode
- save_data(data, limit=0)¶
Save data into a pickle file.
Parameters: data (list) – A list of objects to save in the pickle file.
- unknown(msg)¶
Raise a NagiosUnknown exception.
- verify_plugin_arguments()¶
Check syntax of all arguments.
Override this method to include yours.
- warning(msg)¶
Raise a NagiosWarning exception.
Network protocols¶
Plugins that interact with SNMP or SSH protocols.
NagiosPluginSNMP — Plugin SNMP based¶
NagiosPluginSSH — Plugin SSH based¶
NagiosPluginWMI — Plugin WMI based¶
- class monitoring.nagios.plugin.NagiosPluginWMI(*args, **kwargs)¶
Base for a standard WMI Nagios plugin
- define_plugin_arguments()¶
Define arguments for the plugin
- execute(query)¶
Wrapper arround monitoring.nagios.probes.ProbeWMI.execute() method. Handles exceptions and parse CSV results.
Returns: A dict with keys as WMI columns and their values. Return type: dict
- verify_plugin_arguments()¶
Check syntax of all arguments
NagiosPluginHTTP — Plugin HTTP based¶
- class monitoring.nagios.plugin.NagiosPluginHTTP(*args, **kwargs)¶
Base plugin that makes HTTP requests.
Make HTTP requests using attribute http which is an instance of monitoring.nagios.probes.http.ProbeHTTP.
Example:
plugin = NagiosPluginHTTP() response = plugin.http.get("/test.html") print response.content, response.status_code
The following arguments are pre-defined and accessible with attribute options:
- -H: options.hostname
- -p, --port: options.port
- -S, --ssl: options.ssl
- -a, --auth: options.auth
- define_plugin_arguments()¶
Define arguments for the plugin
Databases¶
Plugins that interact with a database.
NagiosPluginMSSQL — Plugin Microsoft SQL Server¶
- class monitoring.nagios.plugin.NagiosPluginMSSQL(*args, **kwargs)¶
Base for a standard SSH Nagios plugin
- close()¶
Close the database connection.
- define_plugin_arguments()¶
Define arguments for the plugin
- get_all_db_status()¶
Query the status of all databases on the connected SQL Server.
Return a list of tuples [(db_name, db_state), ...].
Returns: list(tuple)
- get_db_size()¶
Get the size of the database connected on. Also return the used percent. This returns a dict with a key per filename (eg. db.Data / db.Log) that is also a dict with keys ‘size’, ‘maxsize’ and ‘used’ (sizes are in bytes and used in percent).
Returns: dict
- get_server_time()¶
Return the local time of the SQL server.
Returns: local time of SQL server Return type: datetime
- query(sql_query)¶
Execute a SQL query and fetch all data.
Parameters: sql_query (str, unicode) – SQL query. Returns: Results of the SQL query Return type: list