Show returned JSON in OK Status when performance data is requested

This commit is contained in:
Markus Opolka 2020-03-17 13:30:37 +01:00
parent 1ac160e8c2
commit c90b0323f5
2 changed files with 12 additions and 9 deletions

View File

@ -41,20 +41,23 @@ class NagiosHelper:
critical_message = '' critical_message = ''
unknown_message = '' unknown_message = ''
def getMessage(self): def getMessage(self, message=''):
""" """
Build a status-prefixed message with optional performance data Build a status-prefixed message with optional performance data
generated externally generated externally
""" """
text = "%s: Status %s." % (self.message_prefixes[self.getCode()], message += self.warning_message
self.message_prefixes[self.getCode()]) message += self.critical_message
text += self.warning_message message += self.unknown_message
text += self.critical_message code = self.message_prefixes[self.getCode()]
text += self.unknown_message output = "{code}: Status {code}. {message}".format(code=code, message=message.strip())
if self.performance_data: if self.performance_data:
text += "|%s" % self.performance_data output = "{code}: {perf_data} Status {code}. {message}|{perf_data}".format(
return text code=code,
message=message.strip(),
perf_data=self.performance_data)
return output.strip()
def getCode(self): def getCode(self):
code = OK_CODE code = OK_CODE

View File

@ -48,4 +48,4 @@ class NagiosHelperTest(unittest.TestCase):
helper = NagiosHelper() helper = NagiosHelper()
helper.performance_data = 'foobar' helper.performance_data = 'foobar'
self.assertEqual('OK: Status OK.|foobar', helper.getMessage()) self.assertEqual('OK: foobar Status OK. |foobar', helper.getMessage())