From 0634845f5ebb1ea4e7209e0cace8fafe596ea61c Mon Sep 17 00:00:00 2001 From: Yann Mahe Date: Fri, 24 Apr 2015 11:19:34 -0400 Subject: [PATCH] [dogwrap] auto select priority based on output --- datadog/dogshell/wrap.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/datadog/dogshell/wrap.py b/datadog/dogshell/wrap.py index 21eb24ca6..99abc61a9 100644 --- a/datadog/dogshell/wrap.py +++ b/datadog/dogshell/wrap.py @@ -93,7 +93,7 @@ def main(): default='errors', choices=['errors', 'all']) parser.add_option('-t', '--timeout', action='store', type='int', default=60 * 60 * 24) parser.add_option('-p', '--priority', action='store', type='choice', choices=['normal', 'low'], - default='normal', help="The priority of the event (default: 'normal')") + help="The priority of the event (default: 'normal')") parser.add_option('--sigterm_timeout', action='store', type='int', default=60 * 2) parser.add_option('--sigkill_timeout', action='store', type='int', default=60) parser.add_option('--proc_poll_interval', action='store', type='float', default=0.5) @@ -115,17 +115,19 @@ def main(): if returncode == 0: alert_type = SUCCESS + event_priority = 'low' event_title = u'[%s] %s succeeded in %.2fs' % (host, options.name, duration) - elif returncode is Timeout: - alert_type = ERROR - event_title = u'[%s] %s timed out after %.2fs' % (host, options.name, - duration) - returncode = -1 else: alert_type = ERROR - event_title = u'[%s] %s failed in %.2fs' % (host, options.name, - duration) + event_priority = 'normal' + + if returncode is Timeout: + event_title = u'[%s] %s timed out after %.2fs' % (host, options.name, duration) + returncode = -1 + else: + event_title = u'[%s] %s failed in %.2fs' % (host, options.name, duration) + event_body = [u'%%%\n', u'commmand:\n```\n', u' '.join(cmd), u'\n```\n', u'exit code: %s\n\n' % returncode, @@ -152,9 +154,8 @@ def main(): 'alert_type': alert_type, 'aggregation_key': options.name, 'host': host, - 'priority': options.priority, + 'priority': options.priority or event_priority, } - print >> sys.stderr, stderr.strip() print >> sys.stdout, stdout.strip()