send-nagios-notification: Expand "\n" escape sequences that we get from Nagios

(imported from commit 3e8efbfe8bbd5a2f13a8e02d9f44442b035113ba)
This commit is contained in:
Keegan McAllister 2012-11-26 17:08:13 -05:00
parent faa2470ed5
commit 30f234d42d

View file

@ -35,7 +35,10 @@ else:
# e.g. **PROBLEM**: service is CRITICAL
msg['content'] = '**%s**: %s is %s' % (opts.type, thing, opts.state)
output = (opts.output + '\n' + opts.long_output).strip()
# The "long output" can contain newlines represented by "\n" escape sequences.
# The Nagios mail command uses /usr/bin/printf "%b" to expand these.
# We will be more conservative and handle just this one escape sequence.
output = (opts.output + '\n' + opts.long_output.replace(r'\n', '\n')).strip()
if output:
# Block-quote any command output.
msg['content'] += ('\n\n' + '\n'.join('> ' + ln for ln in output.splitlines()))