Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nodescraper/connection/inband/inbandlocal.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def run_command(

res = subprocess.run(
command,
encoding="utf-8",
encoding=None,
shell=True,
timeout=timeout,
capture_output=True,
Expand Down
26 changes: 14 additions & 12 deletions nodescraper/plugins/inband/journal/journal_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ def _read_with_journalctl(self):
Returns:
str|None: system journal read
"""
cmd = "journalctl --no-pager --system --all --output=json"
cmd = "journalctl --no-pager --system --all --output=short-iso"
res = self._run_sut_cmd(cmd, sudo=True, log_artifact=False, strip=False)


if res.exit_code != 0:
self._log_event(
category=EventCategory.OS,
Expand All @@ -60,21 +61,22 @@ def _read_with_journalctl(self):
self.result.status = ExecutionStatus.ERROR
return None

raw = res.stdout
text = (
raw.decode("utf-8", errors="surrogateescape")
if isinstance(raw, (bytes, bytearray))
else raw
)
out = res.stdout

if isinstance(out, (bytes, bytearray)):
try:
text = out.decode("utf-8")
except UnicodeDecodeError:
text = out.decode("utf-8", errors="replace")
else:
text = out

lines = [ln for ln in (line.strip() for line in text.splitlines()) if ln.startswith("{")]
array_like = "[" + ",".join(lines) + "]"
entries: list[dict] = json.load(io.StringIO(array_like))
text = text.replace("\r\n", "\n").replace("\r", "\n").replace("\x00", "")
return text

return entries

def collect_data(self, args=None) -> tuple[TaskResult, JournalData | None]:
"""Collect journal lofs
"""Collect journal logs

Args:
args (_type_, optional): Collection args. Defaults to None.
Expand Down
2 changes: 1 addition & 1 deletion nodescraper/plugins/inband/journal/journaldata.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
class JournalData(DataModel):
"""Data model for journal logs"""

journal_log: list[dict]
journal_log: str

def log_model(self, log_path: str):
"""Log data model to a file
Expand Down