@@ -40,12 +40,36 @@ class JournalCollector(InBandDataCollector[JournalData, None]):
4040 CMD = "ls -1 /var/log/journal/*/system* 2>/dev/null || true"
4141
4242 def _shell_quote (self , s : str ) -> str :
43+ """single-quote fix.
44+
45+ Args:
46+ s (str): path
47+
48+ Returns:
49+ str: escaped path
50+ """
4351 return "'" + s .replace ("'" , "'\" '\" '" ) + "'"
4452
4553 def _flat_name (self , path : str ) -> str :
54+ """Flatten path name
55+
56+ Args:
57+ path (str): path
58+
59+ Returns:
60+ str: flattened path name
61+ """
4662 return "journalctl__" + path .lstrip ("/" ).replace ("/" , "__" ) + ".json"
4763
4864 def _read_with_journalctl (self , path : str ):
65+ """Read journal logs using journalctl
66+
67+ Args:
68+ path (str): path for log to read
69+
70+ Returns:
71+ str|None: name of local journal log filed, or None if log was not read
72+ """
4973 qp = self ._shell_quote (path )
5074 cmd = f"journalctl --no-pager --system --all --file={ qp } --output=json"
5175 res = self ._run_sut_cmd (cmd , sudo = True , log_artifact = False , strip = False )
@@ -63,7 +87,12 @@ def _read_with_journalctl(self, path: str):
6387
6488 return None
6589
66- def _get_journals (self ):
90+ def _get_journals (self ) -> list [str ]:
91+ """Read journal log files on remote system
92+
93+ Returns:
94+ list[str]: List of names of read logs
95+ """
6796 list_res = self ._run_sut_cmd (self .CMD , sudo = True )
6897 paths = [p .strip () for p in (list_res .stdout or "" ).splitlines () if p .strip ()]
6998
@@ -105,6 +134,14 @@ def _get_journals(self):
105134 return collected
106135
107136 def collect_data (self , args = None ) -> tuple [TaskResult , JournalData | None ]:
137+ """Collect journal lofs
138+
139+ Args:
140+ args (_type_, optional): Collection args. Defaults to None.
141+
142+ Returns:
143+ tuple[TaskResult, JournalData | None]: Tuple of results and data model or none.
144+ """
108145 collected = self ._get_journals ()
109146 if collected :
110147 data = JournalData (journal_logs = collected )
0 commit comments