From da02eccb2e7b322383d4712813cec1738e3233c9 Mon Sep 17 00:00:00 2001 From: Daniel Markstedt Date: Mon, 28 Feb 2022 09:49:48 -0800 Subject: [PATCH] Improve logic for the get_logs() method. Add rascsi-ctrlboard service. (#714) --- python/common/src/rascsi/sys_cmds.py | 25 ++++++++++++------------- python/web/src/templates/index.html | 13 ++++++++----- python/web/src/web.py | 4 ++-- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/python/common/src/rascsi/sys_cmds.py b/python/common/src/rascsi/sys_cmds.py index 7fd79e8d..4b6736f6 100644 --- a/python/common/src/rascsi/sys_cmds.py +++ b/python/common/src/rascsi/sys_cmds.py @@ -149,21 +149,20 @@ class SysCmds: def get_logs(lines, scope): """ Takes (int) lines and (str) scope. + If scope is a None equivalent, all syslogs are returned. Returns either the decoded log output, or the stderr output of journalctl. """ - if scope != "all": - process = run( - ["journalctl", "-n", lines, "-u", scope], - capture_output=True, - check=True, - ) - else: - process = run( - ["journalctl", "-n", lines], - capture_output=True, - check=True, - ) - + line_param = [] + scope_param = [] + if lines: + line_param = ["-n", lines] + if scope: + scope_param = ["-u", scope] + process = run( + ["journalctl"] + line_param + scope_param, + capture_output=True, + check=True, + ) if process.returncode == 0: return process.returncode, process.stdout.decode("utf-8") diff --git a/python/web/src/templates/index.html b/python/web/src/templates/index.html index 017c2dfa..269e1d58 100644 --- a/python/web/src/templates/index.html +++ b/python/web/src/templates/index.html @@ -604,17 +604,20 @@ diff --git a/python/web/src/web.py b/python/web/src/web.py index 27001f2c..15a4582f 100644 --- a/python/web/src/web.py +++ b/python/web/src/web.py @@ -435,8 +435,8 @@ def show_logs(): """ Displays system logs """ - lines = request.form.get("lines") or "200" - scope = request.form.get("scope") or "all" + lines = request.form.get("lines") + scope = request.form.get("scope") returncode, logs = sys_cmd.get_logs(lines, scope) if returncode == 0: