pyother is a set of small, reusable code snippets which I could not find in other python modules.
In order to use pyother following dependencies have to be installed:
- yaml bindings for python (http://pyyaml.org/)
- python 2.7 or python >=3.2
In order to send event to Riemann, few more libraries are needed:
- Bernhard - Riemann client library (https://github.com/banjiewen/bernhard)
- Google's protobuf library
- dnspython library (http://www.dnspython.org/)
You can also use debian packaging rules from debian/ directory to build a deb package.
The script module contains four classes:
- the RecoverableException and FatalException exceptions are used to differentiate local exections, generated by the script.
- the ScriptConfiguration class is a simple configuration file handler. Based on yaml it allows to handle complex structures and translate them directly to Python objects. It does not do any config params verification.
- ScriptLock is a simple locking facility using fcntl call.
The monitoring module ATM contains only ScriptStatus class. Its meant to provide easy interface to sending events to NRPE/Riemann monitoring agents. It performs event aggregation, Riemman connection handling and logging. Four methods are available:
- initialize
- update - push event into the class's internal storage but do not sent it now. When all the events are submitted - send them all in an aggregated form.
- notify_agregated - send all the events submitted via update method, in an aggregated role
- _notify\immediate - discard all the events currently stored and send immediatelly an event provided via method call.
It should be noted that there are differences betwean Riemann and NRPE event sending - by design, _notify\immediate and _notify\agregated terminates the script when NRPE functionality is enabled whereas Riemann-only setup enables sending more than one event.
An event is a status-message pair. Status is one of ("ok","crit", "warning', "unknown") levels of the event and the message is a free-form text describing the event.
By event aggregation it is understood that the status is only raised up (ok->crit->warning->unknown), and the message is concatenated.
For more detailed information please check pydoc documentation - all classes/methods and their arguments are well documented. By convention all private methods/fields are prefixed with "_" and should not be accessed/used directly.
All patches are welcome ! Please use Github issue tracking and/or create a pull request. Also, please try to adhere to Google coding standards:
http://google-styleguide.googlecode.com/svn/trunk/pyguide.html#Default_Argument_Values
Currenlty the unittest python library is used to perform all the testing. In test/ directory you can find:
- modules/ - modules used by unittests
- moduletests/ - the unittests themselves
- fabric/ - sample input files
- output_coverage_html/ - coverage tests results in a form of an html webpage
Unittests can be started either by using nosetest command:
pyother/ (master✗) # nosetests
[20:33:02]
......
----------------------------------------------------------------------
Ran 6 tests in 0.449s
OK
or by issuing the run_tests.py command:
pyother/ (master✗) # run_tests.py
[20:33:04]
......
----------------------------------------------------------------------
Ran 6 tests in 0.362s
OK
The difference is that the run_tests.py takes care of generating coverage reports for you.
All the dependencies required for performing the unittests are decribed in debian packaging scripts and are as follows:
- unittests2 (in case of python2)
- coverage
- python-mock , plus all the dependencies mentioned in 'Project Setup' section.