Browse Source

[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

pull/1280/head
sebalix 9 years ago
committed by Enric Tobella
parent
commit
86e7a3fffe
No known key found for this signature in database GPG Key ID: 1A2546A1B7BA2451
  1. 12
      nsca_client/models/nsca_check.py
  2. 1
      nsca_client/views/nsca_check.xml

12
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)

1
nsca_client/views/nsca_check.xml

@ -27,6 +27,7 @@
<field name="nsca_model"/>
<field name="nsca_function"/>
<field name="nsca_args"/>
<field name="allow_void_result"/>
<div colspan="2">
<p>The method must return a tuple (RC, MESSAGE) where RC is an integer:</p>
<newline/>

Loading…
Cancel
Save