parse output of smartctl
This commit is contained in:
parent
7c3a80522f
commit
6c3ee2fbe8
@ -1,2 +1,3 @@
|
||||
pub mod mdstat_parser;
|
||||
pub mod lsblk_parser;
|
||||
pub mod lsblk_parser;
|
||||
mod smart_parser;
|
||||
|
39
lib/src/parser/smart_parser.rs
Normal file
39
lib/src/parser/smart_parser.rs
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user