Skip to content

Commit 1b1fc56

Browse files
committed
iso
1 parent c0f1e9a commit 1b1fc56

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

nodescraper/connection/inband/inbandlocal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def run_command(
5454

5555
res = subprocess.run(
5656
command,
57-
encoding="utf-8",
57+
encoding=None,
5858
shell=True,
5959
timeout=timeout,
6060
capture_output=True,

nodescraper/plugins/inband/journal/journal_collector.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ def _read_with_journalctl(self):
4545
Returns:
4646
str|None: system journal read
4747
"""
48-
cmd = "journalctl --no-pager --system --all --output=json"
48+
cmd = "journalctl --no-pager --system --all --output=short-iso"
4949
res = self._run_sut_cmd(cmd, sudo=True, log_artifact=False, strip=False)
5050

51+
5152
if res.exit_code != 0:
5253
self._log_event(
5354
category=EventCategory.OS,
@@ -60,21 +61,22 @@ def _read_with_journalctl(self):
6061
self.result.status = ExecutionStatus.ERROR
6162
return None
6263

63-
raw = res.stdout
64-
text = (
65-
raw.decode("utf-8", errors="surrogateescape")
66-
if isinstance(raw, (bytes, bytearray))
67-
else raw
68-
)
64+
out = res.stdout
65+
66+
if isinstance(out, (bytes, bytearray)):
67+
try:
68+
text = out.decode("utf-8")
69+
except UnicodeDecodeError:
70+
text = out.decode("utf-8", errors="replace")
71+
else:
72+
text = out
6973

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

74-
return entries
7577

7678
def collect_data(self, args=None) -> tuple[TaskResult, JournalData | None]:
77-
"""Collect journal lofs
79+
"""Collect journal logs
7880
7981
Args:
8082
args (_type_, optional): Collection args. Defaults to None.

nodescraper/plugins/inband/journal/journaldata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
class JournalData(DataModel):
3333
"""Data model for journal logs"""
3434

35-
journal_log: list[dict]
35+
journal_log: str
3636

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

0 commit comments

Comments
 (0)