Skip to content

Commit da96e49

Browse files
committed
feat: collect more hardware info
Signed-off-by: James Petersen <jpetersenames@gmail.com>
1 parent fb3e5d1 commit da96e49

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ cli.md
3232

3333
# example outputs
3434
/image-cache
35+
protect-preflight-bundle*

src/hardware.rs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use super::{
33
CheckResultValue::{Errored, Failed, Passed},
44
};
55

6+
use log::debug;
7+
use std::path::{Path, PathBuf};
68
use std::process::Command;
79

810
const GROUP_IDENTIFIER: &str = "HardwareChecks";
@@ -12,7 +14,13 @@ pub struct HardwareChecks;
1214

1315
impl HardwareChecks {
1416
pub fn run_all(&self) -> CheckGroupResult {
15-
let results = vec![self.record_lspci(), self.record_dmidecode()];
17+
let results = vec![
18+
self.record_lspci(),
19+
self.record_dmidecode(),
20+
self.record_cpuinfo(),
21+
self.record_cmdline(),
22+
self.record_grub_cfg(),
23+
];
1624

1725
let mut group_result = Passed;
1826
for res in results.iter() {
@@ -36,7 +44,16 @@ impl HardwareChecks {
3644
fn run_tool(&self, tool: &str) -> CheckResult {
3745
let name = format!("Record {tool}");
3846

39-
let output = Command::new(tool).output();
47+
let mut tool_args: Vec<&str> = tool.split(" ").collect();
48+
debug!("{:#?}", tool_args);
49+
let cmd = tool_args.pop();
50+
if cmd.is_none() {
51+
return CheckResult::new(&name, Errored(format!("failed to parse command {tool}")));
52+
}
53+
let cmd = cmd.unwrap();
54+
55+
let output = Command::new(cmd).args(tool_args).output();
56+
debug!("{:#?}", output);
4057
if let Err(e) = output {
4158
return CheckResult::new(&name, Errored(e.to_string()));
4259
}
@@ -59,6 +76,41 @@ impl HardwareChecks {
5976
fn record_dmidecode(&self) -> CheckResult {
6077
self.run_tool("dmidecode")
6178
}
79+
80+
fn record_file(&self, file: &Path) -> CheckResult {
81+
let name = format!("Record {}", file.display());
82+
let output = std::fs::read_to_string(file);
83+
if let Err(e) = output {
84+
return CheckResult::new(
85+
&name,
86+
Errored(format!("failed to read {}: {e}", file.display())),
87+
);
88+
}
89+
let output = output.unwrap();
90+
CheckResult::new_with_output(&name, Passed, Some(output))
91+
}
92+
93+
fn record_cpuinfo(&self) -> CheckResult {
94+
self.record_file(PathBuf::from("/proc/cpuinfo").as_ref())
95+
}
96+
97+
fn record_cmdline(&self) -> CheckResult {
98+
self.record_file(PathBuf::from("/proc/cmdline").as_ref())
99+
}
100+
101+
fn record_grub_cfg(&self) -> CheckResult {
102+
let files = vec!["/boot/grub2/grub.cfg", "/boot/grub/grub.cfg"];
103+
for file in files.iter() {
104+
let file = PathBuf::from(file);
105+
if file.exists() {
106+
return self.record_file(&file);
107+
}
108+
}
109+
CheckResult::new(
110+
"Record grub config",
111+
Errored(format!("failed to find any {:?}", files)),
112+
)
113+
}
62114
}
63115

64116
impl CheckGroup for HardwareChecks {

0 commit comments

Comments
 (0)