diff options
author | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-04-26 22:11:12 +0100 |
---|---|---|
committer | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-04-26 22:35:16 +0100 |
commit | 4e86c7aaa32570e8785a6caa3614c570bcd038a7 (patch) | |
tree | eff894fa987d33aaf05f224f105f2a7001151047 /python/vyos/util.py | |
parent | e768f52b45e3f0d354c788c38d7dfc9964c4d8aa (diff) | |
download | vyos-1x-4e86c7aaa32570e8785a6caa3614c570bcd038a7.tar.gz vyos-1x-4e86c7aaa32570e8785a6caa3614c570bcd038a7.zip |
util: T2226: a way to report noteworthy event
debug.noteworthy can be used to record noteworhy event during
the lifetime of the program. Should anything then cause the
program to fail and cause an airbag report to the user,
then this information will also be included.
Diffstat (limited to 'python/vyos/util.py')
-rw-r--r-- | python/vyos/util.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py index 8430799a1..504d36ef8 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -56,6 +56,7 @@ def popen(command, flag='', shell=None, input=None, timeout=None, env=None, to discard stdout and get stderr: popen('command', stdout=DEVNUL, stderr=PIPE) """ from vyos import debug + from vyos import airbag # log if the flag is set, otherwise log if command is set if not debug.enabled(flag): flag = 'command' @@ -93,14 +94,19 @@ def popen(command, flag='', shell=None, input=None, timeout=None, env=None, str_out = pipe_out.decode(decode).replace('\r\n', '\n').strip() str_err = pipe_err.decode(decode).replace('\r\n', '\n').strip() + out_msg = f"returned (out):\n{str_out}" if str_out: - ret_msg = f"returned (out):\n{str_out}" - debug.message(ret_msg, flag) + debug.message(out_msg, flag) if str_err: - ret_msg = f"returned (err):\n{str_err}" + err_msg = f"returned (err):\n{str_err}" # this message will also be send to syslog via airbag - debug.message(ret_msg, flag, destination=sys.stderr) + debug.message(err_msg, flag, destination=sys.stderr) + + # should something go wrong, report this too via airbag + airbag.noteworthy(cmd_msg) + airbag.noteworthy(out_msg) + airbag.noteworthy(err_msg) return str_out, p.returncode |