From 86e7a3fffe92bafa465cf3e3bcc6dbb458b7038a Mon Sep 17 00:00:00 2001 From: sebalix Date: Thu, 7 Apr 2016 09:08:09 +0200 Subject: [PATCH] [IMP] nsca_client - A check method could not return, and as such no message will be sent to the NSCA server instead of a CRITICAL one --- nsca_client/models/nsca_check.py | 12 +++++++++++- nsca_client/views/nsca_check.xml | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/nsca_client/models/nsca_check.py b/nsca_client/models/nsca_check.py index 71734cbd2..079d9df8a 100644 --- a/nsca_client/models/nsca_check.py +++ b/nsca_client/models/nsca_check.py @@ -35,6 +35,10 @@ class NscaCheck(models.Model): nsca_model = fields.Char(u"Model") nsca_function = fields.Char(u"Method") nsca_args = fields.Char(u"Arguments") + allow_void_result = fields.Boolean( + u"Allow void result", default=False, + help=u"By default, a CRITICAL message is sent if the method does not " + u"return.\nIf checked, no message will be sent in such a case.") @api.model def default_get(self, fields_list): @@ -87,7 +91,13 @@ class NscaCheck(models.Model): try: args = str2tuple(check.nsca_args) NscaModel = self.env[check.nsca_model] - rc, message = getattr(NscaModel, check.nsca_function)(*args) + result = getattr(NscaModel, check.nsca_function)(*args) + if not result: + if check.allow_void_result: + return False + raise ValueError( + "'%s' method does not return" % check.nsca_function) + rc, message = result except Exception, exc: rc, message = 2, "%s" % exc _logger.error("%s - %s", check.service, message) diff --git a/nsca_client/views/nsca_check.xml b/nsca_client/views/nsca_check.xml index 87ed38238..ce2f29cf9 100644 --- a/nsca_client/views/nsca_check.xml +++ b/nsca_client/views/nsca_check.xml @@ -27,6 +27,7 @@ +

The method must return a tuple (RC, MESSAGE) where RC is an integer: