Skip to content

Commit efb9e78

Browse files
committed
moved the CMDs into class vars for doc extraction
1 parent ef30519 commit efb9e78

File tree

19 files changed

+86
-57
lines changed

19 files changed

+86
-57
lines changed

nodescraper/plugins/inband/bios/bios_collector.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class BiosCollector(InBandDataCollector[BiosDataModel, None]):
3535
"""Collect BIOS details"""
3636

3737
DATA_MODEL = BiosDataModel
38+
CMD_WINDOWS = "wmic bios get SMBIOSBIOSVersion /Value"
39+
CMD = "sh -c 'cat /sys/devices/virtual/dmi/id/bios_version'"
3840

3941
def collect_data(
4042
self,
@@ -49,13 +51,13 @@ def collect_data(
4951
bios = None
5052

5153
if self.system_info.os_family == OSFamily.WINDOWS:
52-
res = self._run_sut_cmd("wmic bios get SMBIOSBIOSVersion /Value")
54+
res = self._run_sut_cmd(self.CMD_WINDOWS)
5355
if res.exit_code == 0:
5456
bios = [line for line in res.stdout.splitlines() if "SMBIOSBIOSVersion=" in line][
5557
0
5658
].split("=")[1]
5759
else:
58-
res = self._run_sut_cmd("sh -c 'cat /sys/devices/virtual/dmi/id/bios_version'")
60+
res = self._run_sut_cmd(self.CMD)
5961
if res.exit_code == 0:
6062
bios = res.stdout
6163

nodescraper/plugins/inband/cmdline/cmdline_collector.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class CmdlineCollector(InBandDataCollector[CmdlineDataModel, None]):
3737

3838
DATA_MODEL = CmdlineDataModel
3939

40+
CMD = "cat /proc/cmdline"
41+
4042
def collect_data(
4143
self,
4244
args=None,
@@ -47,7 +49,7 @@ def collect_data(
4749
Returns:
4850
tuple[TaskResult, CmdlineDataModel | None]: tuple containing the task result and the cmdline data model if successful, otherwise None.
4951
"""
50-
res = self._run_sut_cmd("cat /proc/cmdline")
52+
res = self._run_sut_cmd(self.CMD)
5153
cmdline_data = None
5254
if res.exit_code == 0:
5355
cmdline_data = CmdlineDataModel(cmdline=res.stdout)

nodescraper/plugins/inband/dimm/dimm_collector.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class DimmCollector(InBandDataCollector[DimmDataModel, DimmCollectorArgs]):
3838

3939
DATA_MODEL = DimmDataModel
4040

41+
CMD_WINDOWS = "wmic memorychip get Capacity"
42+
CMD = """sh -c 'dmidecode -t 17 | tr -s " " | grep -v "Volatile\\|None\\|Module" | grep Size' 2>/dev/null"""
43+
4144
def collect_data(
4245
self,
4346
args: Optional[DimmCollectorArgs] = None,
@@ -48,7 +51,7 @@ def collect_data(
4851

4952
dimm_str = None
5053
if self.system_info.os_family == OSFamily.WINDOWS:
51-
res = self._run_sut_cmd("wmic memorychip get Capacity")
54+
res = self._run_sut_cmd(self.CMD_WINDOWS)
5255
if res.exit_code == 0:
5356
capacities = {}
5457
total = 0
@@ -69,10 +72,7 @@ def collect_data(
6972
self.result.message = "Skipping sudo plugin"
7073
self.result.status = ExecutionStatus.NOT_RAN
7174
return self.result, None
72-
res = self._run_sut_cmd(
73-
"""sh -c 'dmidecode -t 17 | tr -s " " | grep -v "Volatile\\|None\\|Module" | grep Size' 2>/dev/null""",
74-
sudo=True,
75-
)
75+
res = self._run_sut_cmd(self.CMD, sudo=True)
7676
if res.exit_code == 0:
7777
total = 0
7878
topology = {}

nodescraper/plugins/inband/dkms/dkms_collector.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class DkmsCollector(InBandDataCollector[DkmsDataModel, None]):
3737

3838
DATA_MODEL = DkmsDataModel
3939

40+
CMD_STATUS = "dkms status"
41+
CMD_VERSION = "dkms --version"
42+
4043
def collect_data(
4144
self,
4245
args=None,
@@ -49,8 +52,8 @@ def collect_data(
4952
"""
5053

5154
dkms_data = DkmsDataModel()
52-
dkms_status = self._run_sut_cmd("dkms status")
53-
dkms_version = self._run_sut_cmd("dkms --version")
55+
dkms_status = self._run_sut_cmd(self.CMD_STATUS)
56+
dkms_version = self._run_sut_cmd(self.CMD_VERSION)
5457

5558
if dkms_status.exit_code == 0:
5659
dkms_data.status = dkms_status.stdout

nodescraper/plugins/inband/dmesg/dmesg_collector.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ class DmesgCollector(InBandDataCollector[DmesgData, DmesgCollectorArgs]):
4242

4343
DATA_MODEL = DmesgData
4444

45-
DMESG_CMD = "dmesg --time-format iso -x"
45+
CMD = "dmesg --time-format iso -x"
4646

47-
DMESG_LOGS_CMD = (
47+
CMD_LOGS = (
4848
r"ls -1 /var/log/dmesg* 2>/dev/null | grep -E '^/var/log/dmesg(\.[0-9]+(\.gz)?)?$' || true"
4949
)
5050

5151
def _collect_dmesg_rotations(self):
5252
"""Collect dmesg logs"""
53-
list_res = self._run_sut_cmd(self.DMESG_LOGS_CMD, sudo=True)
53+
list_res = self._run_sut_cmd(self.CMD_LOGS, sudo=True)
5454
paths = [p.strip() for p in (list_res.stdout or "").splitlines() if p.strip()]
5555
if not paths:
5656
self._log_event(
@@ -122,7 +122,7 @@ def _get_dmesg_content(self) -> str:
122122
"""
123123

124124
self.logger.info("Running dmesg command on system")
125-
res = self._run_sut_cmd(self.DMESG_CMD, sudo=True, log_artifact=False)
125+
res = self._run_sut_cmd(self.CMD, sudo=True, log_artifact=False)
126126
if res.exit_code != 0:
127127
self._log_event(
128128
category=EventCategory.OS,

nodescraper/plugins/inband/journal/journal_collector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ class JournalCollector(InBandDataCollector[JournalData, None]):
3636

3737
SUPPORTED_OS_FAMILY = {OSFamily.LINUX}
3838
DATA_MODEL = JournalData
39+
CMD = "journalctl --no-pager --system --output=short-iso"
3940

4041
def _read_with_journalctl(self):
4142
"""Read journal logs using journalctl
4243
4344
Returns:
4445
str|None: system journal read
4546
"""
46-
cmd = "journalctl --no-pager --system --output=short-iso"
47-
res = self._run_sut_cmd(cmd, sudo=True, log_artifact=False, strip=False)
47+
res = self._run_sut_cmd(self.CMD, sudo=True, log_artifact=False, strip=False)
4848

4949
if res.exit_code != 0:
5050
self._log_event(

nodescraper/plugins/inband/kernel/kernel_collector.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class KernelCollector(InBandDataCollector[KernelDataModel, None]):
3434
"""Read kernel version"""
3535

3636
DATA_MODEL = KernelDataModel
37+
CMD_WINDOWS = "wmic os get Version /Value"
38+
CMD = "sh -c 'uname -r'"
3739

3840
def collect_data(
3941
self,
@@ -45,15 +47,16 @@ def collect_data(
4547
Returns:
4648
tuple[TaskResult, KernelDataModel | None]: tuple containing the task result and kernel data model or None if not found.
4749
"""
50+
4851
kernel = None
4952
if self.system_info.os_family == OSFamily.WINDOWS:
50-
res = self._run_sut_cmd("wmic os get Version /Value")
53+
res = self._run_sut_cmd(self.CMD_WINDOWS)
5154
if res.exit_code == 0:
5255
kernel = [line for line in res.stdout.splitlines() if "Version=" in line][0].split(
5356
"="
5457
)[1]
5558
else:
56-
res = self._run_sut_cmd("sh -c 'uname -r'")
59+
res = self._run_sut_cmd(self.CMD)
5760
if res.exit_code == 0:
5861
kernel = res.stdout
5962

nodescraper/plugins/inband/kernel_module/kernel_module_collector.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class KernelModuleCollector(InBandDataCollector[KernelModuleDataModel, None]):
3535
"""Read kernel modules and associated parameters"""
3636

3737
DATA_MODEL = KernelModuleDataModel
38+
CMD_WINDOWS = "wmic os get Version /Value"
39+
CMD = "cat /proc/modules"
3840

3941
def parse_proc_modules(self, output: dict) -> dict:
4042
"""Parse command output and return dict of modules
@@ -91,7 +93,7 @@ def collect_all_module_info(self) -> tuple[dict, CommandArtifact]:
9193
tuple[dict, CommandArtifact]: modules found and exit code
9294
"""
9395
modules = {}
94-
res = self._run_sut_cmd("cat /proc/modules")
96+
res = self._run_sut_cmd(self.CMD)
9597
if res.exit_code != 0:
9698
self._log_event(
9799
category=EventCategory.OS,
@@ -128,7 +130,7 @@ def collect_data(self, args=None) -> tuple[TaskResult, KernelModuleDataModel | N
128130
kernel_modules = {}
129131
km_data: KernelModuleDataModel | None = None
130132
if self.system_info.os_family == OSFamily.WINDOWS:
131-
res = self._run_sut_cmd("wmic os get Version /Value")
133+
res = self._run_sut_cmd(self.CMD_WINDOWS)
132134
if res.exit_code == 0:
133135
for line in res.stdout.splitlines():
134136
if line.startswith("Version="):

nodescraper/plugins/inband/memory/memory_collector.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class MemoryCollector(InBandDataCollector[MemoryDataModel, None]):
3737

3838
DATA_MODEL = MemoryDataModel
3939

40+
CMD_WINDOWS = (
41+
"wmic OS get FreePhysicalMemory /Value; wmic ComputerSystem get TotalPhysicalMemory /Value"
42+
)
43+
CMD = "free -b"
44+
4045
def collect_data(self, args=None) -> tuple[TaskResult, MemoryDataModel | None]:
4146
"""
4247
Collects memory usage details from the system.
@@ -46,16 +51,14 @@ def collect_data(self, args=None) -> tuple[TaskResult, MemoryDataModel | None]:
4651
"""
4752
mem_free, mem_total = None, None
4853
if self.system_info.os_family == OSFamily.WINDOWS:
49-
os_memory_cmd = self._run_sut_cmd(
50-
"wmic OS get FreePhysicalMemory /Value; wmic ComputerSystem get TotalPhysicalMemory /Value"
51-
)
54+
os_memory_cmd = self._run_sut_cmd(self.CMD_WINDOWS)
5255
if os_memory_cmd.exit_code == 0:
5356
mem_free = re.search(r"FreePhysicalMemory=(\d+)", os_memory_cmd.stdout).group(
5457
1
5558
) # bytes
5659
mem_total = re.search(r"TotalPhysicalMemory=(\d+)", os_memory_cmd.stdout).group(1)
5760
else:
58-
os_memory_cmd = self._run_sut_cmd("free -b")
61+
os_memory_cmd = self._run_sut_cmd(self.CMD)
5962
if os_memory_cmd.exit_code == 0:
6063
pattern = r"Mem:\s+(\d\.?\d*\w+)\s+\d\.?\d*\w+\s+(\d\.?\d*\w+)"
6164
mem_free = re.search(pattern, os_memory_cmd.stdout).group(2)

nodescraper/plugins/inband/nvme/nvme_collector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def collect_data(
7575

7676
for dev in nvme_devices:
7777
device_data = {}
78-
commands = {
78+
CMD = {
7979
"smart_log": f"nvme smart-log {dev}",
8080
"error_log": f"nvme error-log {dev} --log-entries=256",
8181
"id_ctrl": f"nvme id-ctrl {dev}",
@@ -86,7 +86,7 @@ def collect_data(
8686
"telemetry_log": f"nvme telemetry-log {dev} --output-file={dev}_{f_name}",
8787
}
8888

89-
for key, cmd in commands.items():
89+
for key, cmd in CMD.items():
9090
res = self._run_sut_cmd(cmd, sudo=True)
9191
if "--output-file" in cmd:
9292
_ = self._read_sut_file(filename=f"{dev}_{f_name}", encoding=None)

0 commit comments

Comments
 (0)