Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kenny/serial number as filename #5

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified build/release/hardware_report-linux-x86_64
Binary file not shown.
33 changes: 29 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,9 @@ fn main() -> Result<(), Box<dyn Error>> {
println!("System Summary:");
println!("==============");

// Print the system Hostname
println!("Hostname: {}", server_info.hostname);

println!("CPU: {}", server_info.summary.cpu_summary);
println!(
"Total: {} Cores, {} Threads",
Expand Down Expand Up @@ -1291,7 +1294,7 @@ fn main() -> Result<(), Box<dyn Error>> {
.map(|device| device.size.clone())
.collect::<Vec<String>>()
.join(" + ");
println!("Storage: {}", total_storage);
println!("Available Disks: {}", total_storage);

// Get BIOS information from dmidecode
let output = Command::new("dmidecode").args(["-t", "bios"]).output()?;
Expand Down Expand Up @@ -1388,15 +1391,37 @@ fn main() -> Result<(), Box<dyn Error>> {
}
}

println!("\nFull configuration being written to server_config.toml...");
// Get chassis serial number ans sanitize it for use as the file_name
let chassis_serial = server_info.summary.chassis.serial.clone();
let safe_filename = sanitize_filename(&chassis_serial);

fn sanitize_filename(filename: &str) -> String {
filename
.chars()
.map(|c| {
if c.is_alphanumeric() || c == '-' {
c
} else {
'_'
}
})
.collect::<String>()
}

println!(
"\nCreating TOML output for system serial number: {}",
safe_filename
);

let output_filename = format!("{}_hardware_report.toml", safe_filename);

// Convert to TOML
let toml_string = toml::to_string_pretty(&server_info)?;

// Write to file
std::fs::write("server_config.toml", toml_string)?;
std::fs::write(&output_filename, toml_string)?;

println!("Configuration has been written to server_config.toml");
println!("Configuration has been written to {}", output_filename);

Ok(())
}
Loading