Helper Classes for plugin development and nagios management.
Project description
=====================
python-nagios-helpers
=====================
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 <http://python-textops.readthedocs.org>`_
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<http://python-nagios-helpers.readthedocs.org>`_!
News
====
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
python-nagios-helpers
=====================
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 <http://python-textops.readthedocs.org>`_
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<http://python-nagios-helpers.readthedocs.org>`_!
News
====
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
Close
Hashes for python-nagios-helpers-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 583c9a8791c98acaf4eee4d368a7f09496f95faa25b47a31dd0679a922880da5 |
|
MD5 | 2b7d4870eec804ba460613bd2d6fe0f3 |
|
BLAKE2b-256 | 3af56b99f86b8302612a80c5c0073173006aeebeea48860fcc594836d83bfaa1 |