Commit 7cf52e8c authored by Sylvain K's avatar Sylvain K

Merged in 1698/check-command (pull request #1)

HexackCheckCommand
parents 181160c3 5de49770
......@@ -51,3 +51,35 @@ class HexACKBaseCommand(BaseCommand):
def get_command_name(self):
return os.path.splitext(sys.argv[1])[0]
class HexackCheckCommand(BaseCommand):
"""
Extend Django's BaseCommand to be used as a Nagios/Shinken plugin
"""
# Nagios/Shinken plugin return codes
OK = 0
WARNING = 1
CRITICAL = 2
UNKNOWN = 3
def _exit(self, code, message, **perf_data):
if perf_data:
# See: https://nagios-plugins.org/doc/guidelines.html#AEN200
perf_data_string = ' '.join('%s=%s' % (label, value) for label, value in perf_data.items())
message = ' | '.join((message, perf_data_string))
self.stdout.write(message)
sys.exit(code)
def unknown(self, message, **perf_data):
self._exit(self.UNKNOWN, 'UNKNOWN: ' + message, **perf_data)
def ok(self, message, **perf_data):
self._exit(self.OK, 'OK: ' + message, **perf_data)
def warning(self, message, **perf_data):
self._exit(self.WARNING, 'WARNING: ' + message, **perf_data)
def critical(self, message, **perf_data):
self._exit(self.CRITICAL, 'CRITICAL: ' + message, **perf_data)
......@@ -6,7 +6,7 @@ from setuptools import setup, find_packages
setup(
name='hexack-utils',
version="0.1.0",
version="0.2.0",
packages=find_packages(exclude=['tests']),
namespace_packages=['hexack'],
install_requires=[
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment