Commit 037db59a authored by Jonathan Michalon's avatar Jonathan Michalon

Provide last exec'd command in a check failure's email as debug info

parent 97eefd7b
...@@ -38,6 +38,7 @@ class Check(object): ...@@ -38,6 +38,7 @@ class Check(object):
self.error_every = self.every self.error_every = self.every
self.run_count = 0 self.run_count = 0
self.errmsg = '' self.errmsg = ''
self.last_exec = ''
self.ok = True self.ok = True
self.target_name = options.get('target_name', 'Unknown') self.target_name = options.get('target_name', 'Unknown')
self.timeout = options.get('timeout', 2) self.timeout = options.get('timeout', 2)
...@@ -86,7 +87,10 @@ class Check(object): ...@@ -86,7 +87,10 @@ class Check(object):
def exec_with_timeout(self, command, timeout=None, pattern=''): def exec_with_timeout(self, command, timeout=None, pattern=''):
timeout = self.timeout if timeout is None else timeout timeout = self.timeout if timeout is None else timeout
self.errmsg = '' self.errmsg = ''
self.last_exec = ' '.join(map(
lambda s: "'" + s.replace("'", "'\"'\"'") + "'",
command))
try: try:
p = Popen(command, stdout=PIPE, stderr=PIPE) p = Popen(command, stdout=PIPE, stderr=PIPE)
except OSError as e: except OSError as e:
......
...@@ -123,7 +123,8 @@ def send_email_for_check(check): ...@@ -123,7 +123,8 @@ def send_email_for_check(check):
msg_text += ("recovered after %s (%d %s)." % msg_text += ("recovered after %s (%d %s)." %
(delta, n, "retry" if n == 1 else "retries")) (delta, n, "retry" if n == 1 else "retries"))
else: else:
msg_text += ("failure:\n%s" % check.errmsg.strip()) msg_text += ("failure:\n%s\n" % check.errmsg.strip())
msg_text += ("\nFYI, last exec was:\n%s\n" % check.last_exec.strip())
extra_headers = {} extra_headers = {}
extra_headers['Message-ID'] = make_msgid(type(check).__name__) extra_headers['Message-ID'] = make_msgid(type(check).__name__)
......
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