Helper Classes for plugin development and nagios management.
Project description
python-nagios-helpers A.K.A naghelp is a collections of classes for building nagios Active plugins. It is higly recommended to use python-textops to manipulate collected data.
Here is an exemple of an active python plugin, create a file linux_fsfull.py:
from naghelp import * from textops import * class LinuxFsFull(ActivePlugin): """ Basic plugin to monitor full filesystems on Linux systems""" cmd_params = 'user,passwd' tcp_ports = '22' def collect_data(self,data): data.df = Ssh(self.host.ip,self.host.user,self.host.passwd).run('df -h') def parse_data(self,data): df = data.df.skip(1) data.fs_critical = df.greaterequal(98,key=cuts(r'(\d+)%')).cut(col='5,4').renderitems() data.fs_warning = df.inrange(95,98,key=cuts(r'(\d+)%')).cut(col='5,4').renderitems() data.fs_ok = df.lessthan(95,key=cuts(r'(\d+)%')).cut(col='5,4').renderitems() def build_response(self,data): self.response.add_list(CRITICAL,data.fs_critical) self.response.add_list(WARNING,data.fs_warning) self.response.add_list(OK,data.fs_ok) if __name__ == '__main__': LinuxFsFull().run()
To excute manually:
python linux_fsfull.py --ip=127.0.0.1 --user=naghelp --passwd=lgpl
On error, it may return something liek this:
STATUS : CRITICAL:2, WARNING:1, OK:3 ==================================[ STATUS ]================================== ----( CRITICAL )---------------------------------------------------------------- / : 98% /home : 99% ----( WARNING )----------------------------------------------------------------- /run/shm : 95% ----( OK )---------------------------------------------------------------------- /dev : 1% /run : 1% /run/lock : 0% ============================[ Plugin Informations ]============================= Plugin name : __main__.LinuxFsFull Description : Basic plugin to monitor full filesystems on Linux systems Ports used : tcp = 22, udp = none Execution time : 0:00:00.673851 Exit code : 2 (CRITICAL), __sublevel__=0
Or if no error:
OK ============================[ Plugin Informations ]============================= Plugin name : __main__.LinuxFsFull Description : Basic plugin to monitor full filesystems on Linux systems Ports used : tcp = 22, udp = none Execution time : 0:00:00.845603 Exit code : 0 (OK), __sublevel__=0
Naghelp will automatically manage some options:
$ python linux_fsfull.py -h Usage: linux_fsfull.py [options] Options: -h, --help show this help message and exit -v Verbose : display informational messages -d Debug : display debug messages -l FILE Redirect logs into a file -i Display plugin description -n Must be used when the plugin is started by nagios -s Save collected data in a temporary file -r Use saved collected data (option -s) -a Collect data only and print them -b Collect and parse data only and print them Host attributes: To be used to force host attributes values --passwd=PASSWD Passwd --ip=IP Host IP address --user=USER User --name=NAME Hostname
For more information, Read The Fabulous Manual !
News
0.2.3 (2018-06-20)
fix priv_protocol argument for collect.Snmp
0.2.2 (2018-02-28)
Add object_identity_to_string option in Snmp class Add ignore_errors option in Snmp.*walk methods Add SnmpWalkError exception to get truncated result
0.2.1 (2018-02-01)
Update Winrm collect class
0.2.0 (2018-02-01)
Add Winrm collect class
0.1.23 (2017-09-08)
Move save_host_data() in plugin run() method
0.1.22 (2017-07-07)
Add Ssh run_script(), get() and put() methods
0.1.21 (2017-04-26)
Add textops.logger as managed logger
0.1.20 (2017-04-26)
moving host debug traces into load_host_data()
0.1.19 (2017-04-22)
Cache discovered plugins in find_plugins()
0.1.18 (2017-04-07)
add post and session handling in Http() class
0.1.17 (2017-04-05)
do not add logger handler more than once
0.1.16 (2017-03-27)
Now possible to instanciate a plugin with extra options
0.1.15 (2017-03-20)
Fix case where there is no docstring for a plugin
0.1.14 (2017-01-31)
Remove version limitation over sphinx package in setup.py
0.1.12 (2017-01-26)
remove unusefull code
0.1.11 (2017-01-26)
runsh* now return extended type for textops operations
0.1.10 (2016-09-05)
add collect_* options add timeout for collect_data()
0.1.9 (2016-08-26)
Map all options in host object (not only host__*)
0.1.8 (2016-08-04)
Perf data in plugin output are now space separated
0.1.7 (2016-04-14)
Add Execution date for active plugins in plugin informations section Add Update date in plugin informations for Managed hosts
0.1.6 (2016-04-12)
Add HostsManager Mixin Add collect.Http class Create Lockfile utility move Timeout utility in tools.py
0.1.5 (2016-03-23)
Add Gauges Mixin Add docs Many other improvements
0.1.4 (2016-03-08)
Better error management
0.1.3 (2016-01-13)
Add docs
0.1.1 (2016-01-08)
Add a launcher
0.1.0 (2015-12-17)
Add some docs, tests Tune some functions
0.0.7 (2015-11-19)
First working version
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for python-nagios-helpers-0.2.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1567cefa2a16528215c994756df4902aa3a4eb95481f341c39d1e1e227d4b0d3 |
|
MD5 | 56805524fd0ac4df8a9183a833b9463b |
|
BLAKE2b-256 | e1cdf972b97a2cdeb8f042fad40fdac3b815889cb93135d816e08a56438d7b61 |
Hashes for python_nagios_helpers-0.2.3-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf0d3c5c0b0aceab353efb8b1cdb0e52f5c00a8b43969e992419ccaa6e772743 |
|
MD5 | 1e6982f5a64a5c7de8a64555d78702c7 |
|
BLAKE2b-256 | ced1585798eace087431489e8c6cb22e8b2900897ed77c6c9461a376993e9412 |