Commit 07145bc8 authored by Sylvain Kanschine's avatar Sylvain Kanschine

Add HexackCheckCommand

parent 181160c3
......@@ -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)
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