@@ -3,6 +3,8 @@ use super::{
33 CheckResultValue :: { Errored , Failed , Passed } ,
44} ;
55
6+ use log:: debug;
7+ use std:: path:: { Path , PathBuf } ;
68use std:: process:: Command ;
79
810const GROUP_IDENTIFIER : & str = "HardwareChecks" ;
@@ -12,7 +14,13 @@ pub struct HardwareChecks;
1214
1315impl 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
64116impl CheckGroup for HardwareChecks {
0 commit comments