A framework for writing Python sensu plugins.
Project description
![sensu](https://raw.github.com/sensu/sensu/master/sensu-logo.png)
# Python Sensu Plugin
This is a framework for writing your own [Sensu](https://github.com/sensu/sensu) plugins in Python.
It's not required to write a plugin (most Nagios plugins will work
without modification); it just makes it easier.
[![Build Status](https://travis-ci.org/sensu/sensu-plugin-python.png?branch=master)](https://travis-ci.org/sensu/sensu-plugin-python)
## Checks
To implement your own check, subclass SensuPluginCheck, like
this:
from sensu_plugin import SensuPluginCheck
class MyCheck(SensuPluginCheck):
def setup(self):
# Setup is called with self.parser set and is responsible for setting up
# self.options before the run method is called
self.parser.add_argument(
'-w',
'--warning',
required=True,
type=int,
help='Integer warning level to output'
)
self.parser.add_argument(
'-m',
'--message',
default=None,
help='Message to print'
)
def run(self):
# this method is called to perform the actual check
self.check_name('my_awesome_check') # defaults to class name
if self.options.warning == 0:
self.ok(self.options.message)
elif self.options.warning == 1:
self.warning(self.options.message)
elif self.options.warning == 2:
self.critical(self.options.message)
else:
self.unknown(self.options.message)
if __name__ == "__main__":
f = MyCheck()
## Metrics
### JSON
from sensu_plugin import SensuPluginMetricJSON
class FooBarBazMetricJSON(SensuPluginMetricJSON):
def run(self):
self.ok({'foo': 1, 'bar': { 'baz': 'stuff' } })
if __name__ == "__main__":
f = FooBarBazMetricJSON()
### Graphite
from sensu_plugin import SensuPluginMetricGraphite
class FooBarBazMetricGraphite(SensuPluginMetricGraphite):
def run(self):
self.output('a', 1)
self.output('b', 2)
self.ok()
if __name__ == "__main__":
f = FooBarBazMetricGraphite()
### StatsD
from sensu_plugin import SensuPluginMetricStatsd
class FooBarBazMetricStatsd(SensuPluginMetricStatsd):
def run(self):
self.output('a', 1, 'ms')
self.output('b.c.d', 15)
self.ok()
if __name__ == "__main__":
f = FooBarBazMetricStatsd()
## License
* Based heavily on [sensu-plugin](https://github.com/sensu/sensu-plugin) Copyright 2011 Decklin Foster
* Python port Copyright 2014 S. Zachariah Sprackett
Released under the same terms as Sensu (the MIT license); see LICENSE
for details
# Python Sensu Plugin
This is a framework for writing your own [Sensu](https://github.com/sensu/sensu) plugins in Python.
It's not required to write a plugin (most Nagios plugins will work
without modification); it just makes it easier.
[![Build Status](https://travis-ci.org/sensu/sensu-plugin-python.png?branch=master)](https://travis-ci.org/sensu/sensu-plugin-python)
## Checks
To implement your own check, subclass SensuPluginCheck, like
this:
from sensu_plugin import SensuPluginCheck
class MyCheck(SensuPluginCheck):
def setup(self):
# Setup is called with self.parser set and is responsible for setting up
# self.options before the run method is called
self.parser.add_argument(
'-w',
'--warning',
required=True,
type=int,
help='Integer warning level to output'
)
self.parser.add_argument(
'-m',
'--message',
default=None,
help='Message to print'
)
def run(self):
# this method is called to perform the actual check
self.check_name('my_awesome_check') # defaults to class name
if self.options.warning == 0:
self.ok(self.options.message)
elif self.options.warning == 1:
self.warning(self.options.message)
elif self.options.warning == 2:
self.critical(self.options.message)
else:
self.unknown(self.options.message)
if __name__ == "__main__":
f = MyCheck()
## Metrics
### JSON
from sensu_plugin import SensuPluginMetricJSON
class FooBarBazMetricJSON(SensuPluginMetricJSON):
def run(self):
self.ok({'foo': 1, 'bar': { 'baz': 'stuff' } })
if __name__ == "__main__":
f = FooBarBazMetricJSON()
### Graphite
from sensu_plugin import SensuPluginMetricGraphite
class FooBarBazMetricGraphite(SensuPluginMetricGraphite):
def run(self):
self.output('a', 1)
self.output('b', 2)
self.ok()
if __name__ == "__main__":
f = FooBarBazMetricGraphite()
### StatsD
from sensu_plugin import SensuPluginMetricStatsd
class FooBarBazMetricStatsd(SensuPluginMetricStatsd):
def run(self):
self.output('a', 1, 'ms')
self.output('b.c.d', 15)
self.ok()
if __name__ == "__main__":
f = FooBarBazMetricStatsd()
## License
* Based heavily on [sensu-plugin](https://github.com/sensu/sensu-plugin) Copyright 2011 Decklin Foster
* Python port Copyright 2014 S. Zachariah Sprackett
Released under the same terms as Sensu (the MIT license); see LICENSE
for details
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 Distributions
sensu_plugin26-0.2.0.zip
(8.5 kB
view details)
sensu_plugin26-0.2.0.tar.gz
(4.2 kB
view details)
File details
Details for the file sensu_plugin26-0.2.0.zip
.
File metadata
- Download URL: sensu_plugin26-0.2.0.zip
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 152ef7fd6a4cc41f8e2610bf9603bf7a6338649935fb67a9c9247b66d09d2284 |
|
MD5 | 82e6193cdcb01988cdd6dbe290e7f054 |
|
BLAKE2b-256 | 1f2dcaafa9192a3cc024f11b2a88f0f1921384d00d8b8819ded196e04c5bbfeb |
File details
Details for the file sensu_plugin26-0.2.0.tar.gz
.
File metadata
- Download URL: sensu_plugin26-0.2.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a68eac3555b69ada282178028d4a577b4bd90712d98e661a4a209a3834d731d |
|
MD5 | 8937e81a1df6769b5d3888c1a0ee3df1 |
|
BLAKE2b-256 | 4e53dd2a3cf271ac3971846fcce05de1bb74bf2c8be0bb25dd57533048b6d4bb |