2323# SOFTWARE.
2424#
2525###############################################################################
26+ from typing import Optional
2627
2728from nodescraper .base import InBandDataCollector
2829from nodescraper .enums import EventCategory , EventPriority , ExecutionStatus , OSFamily
2930from nodescraper .models import TaskResult
3031
32+ from .collector_args import JournalCollectorArgs
3133from .journaldata import JournalData
3234
3335
34- class JournalCollector (InBandDataCollector [JournalData , None ]):
36+ class JournalCollector (InBandDataCollector [JournalData , JournalCollectorArgs ]):
3537 """Read journal log via journalctl."""
3638
3739 SUPPORTED_OS_FAMILY = {OSFamily .LINUX }
3840 DATA_MODEL = JournalData
3941
40- def _read_with_journalctl (self ):
42+ def _read_with_journalctl (self , args : Optional [ JournalCollectorArgs ] = None ):
4143 """Read journal logs using journalctl
4244
4345 Returns:
4446 str|None: system journal read
4547 """
46- cmd = "journalctl --no-pager --system --output=short-iso"
48+ boot_arg = ""
49+
50+ if args is not None :
51+ try :
52+ # Accept ints or numeric strings
53+ boot_arg = f" -b { args .boot } "
54+ except (TypeError , ValueError ):
55+ pass
56+
57+ cmd = f"journalctl --no-pager{ boot_arg } --system --output=short-iso"
4758 res = self ._run_sut_cmd (cmd , sudo = True , log_artifact = False , strip = False )
59+ self .result .message = cmd
4860
4961 if res .exit_code != 0 :
5062 self ._log_event (
@@ -60,7 +72,10 @@ def _read_with_journalctl(self):
6072
6173 return res .stdout
6274
63- def collect_data (self , args = None ) -> tuple [TaskResult , JournalData | None ]:
75+ def collect_data (
76+ self ,
77+ args : Optional [JournalCollectorArgs ] = None ,
78+ ) -> tuple [TaskResult , JournalData | None ]:
6479 """Collect journal logs
6580
6681 Args:
@@ -69,7 +84,10 @@ def collect_data(self, args=None) -> tuple[TaskResult, JournalData | None]:
6984 Returns:
7085 tuple[TaskResult, JournalData | None]: Tuple of results and data model or none.
7186 """
72- journal_log = self ._read_with_journalctl ()
87+ if args is None :
88+ args = JournalCollectorArgs ()
89+
90+ journal_log = self ._read_with_journalctl (args )
7391 if journal_log :
7492 data = JournalData (journal_log = journal_log )
7593 self .result .message = self .result .message or "Journal data collected"
0 commit comments