parse output of smartctl

This commit is contained in:
lukas-heiligenbrunner 2022-12-16 16:06:50 +01:00
parent 7c3a80522f
commit 6c3ee2fbe8
2 changed files with 41 additions and 1 deletions

View File

@ -1,2 +1,3 @@
pub mod mdstat_parser;
pub mod lsblk_parser;
pub mod lsblk_parser;
mod smart_parser;

View File

@ -0,0 +1,39 @@
use std::process::Command;
use rocket::serde::json::serde_json;
use rocket::serde::{Deserialize};
#[derive(Deserialize)]
#[serde(crate = "rocket::serde")]
struct DiskInfo {
model_family: String,
model_name: String,
serial_number: String,
rotation_rate: u32,
}
fn get_disk_info(diskpath: &str) -> Option<DiskInfo> {
let mut cmd = Command::new("smartctl");
cmd.arg("-i")
.arg("-json")
.arg(diskpath);
let output = match cmd.output() {
Ok(output) => output,
Err(err) => {
println!("error while getting smart info: {}", err);
return None;
}
};
let rawsmart = output.stdout;
let info: DiskInfo = match serde_json::from_slice(&rawsmart) {
Ok(info) => info,
Err(err) => {
println!("{}", err);
return None;
}
};
Some(info)
}