-
Notifications
You must be signed in to change notification settings - Fork 2
New plugin: journal logs #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
def _shell_quote(self, s: str) -> str: | ||
"""single-quote fix. | ||
|
||
Args: | ||
s (str): path | ||
|
||
Returns: | ||
str: escaped path | ||
""" | ||
return "'" + s.replace("'", "'\"'\"'") + "'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be moved into utils since it is now being used in multiple places
list_res = self._run_sut_cmd(self.CMD, sudo=True) | ||
paths = [p.strip() for p in (list_res.stdout or "").splitlines() if p.strip()] | ||
|
||
if not paths: | ||
self._log_event( | ||
category=EventCategory.OS, | ||
description="No /var/log/journal files found (including rotations).", | ||
data={"list_exit_code": list_res.exit_code}, | ||
priority=EventPriority.WARNING, | ||
) | ||
return [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be necessary for journalctl logs. The journalctl command will automatically merge and display available logs, including rotated ones. We do not want to read log files individually and should instead rely on journalctls management of these files.
str|None: name of local journal log filed, or None if log was not read | ||
""" | ||
qp = self._shell_quote(path) | ||
cmd = f"journalctl --no-pager --system --all --file={qp} --output=json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not need to read from a file. Please also add '-o short-iso' for iso timestamps.
Reading journal logs. Sample run: