Compare commits

...

2 Commits

Author SHA1 Message Date
75c0a61bf9 fix panic if invalid url 2022-12-21 19:00:54 +01:00
6c3ee2fbe8 parse output of smartctl 2022-12-16 16:06:50 +01:00
3 changed files with 50 additions and 7 deletions

View File

@ -1,7 +1,7 @@
use std::io::Cursor;
use rust_embed::RustEmbed;
use rust_embed::{EmbeddedFile, RustEmbed};
use rocket::{Data, Request, Response, Route};
use rocket::http::{ContentType, Method};
use rocket::http::{ContentType, Method, Status};
use rocket::http::uri::{Segments};
use rocket::http::uri::fmt::Path;
use rocket::route::{Handler, Outcome};
@ -13,8 +13,7 @@ struct Asset;
#[cfg(feature = "static")]
#[derive(Clone)]
pub struct CustomHandler {
}
pub struct CustomHandler {}
#[cfg(feature = "static")]
impl Into<Vec<Route>> for CustomHandler {
@ -38,8 +37,12 @@ impl Handler for CustomHandler {
path
};
let file_content =
<Asset as RustEmbed>::get(path.to_string_lossy().as_ref()).unwrap();
let file_content = <Asset as RustEmbed>::get(path.to_string_lossy().as_ref());
let file_content = match file_content {
None => return Outcome::Failure(Status::NotFound),
Some(c) => c
};
let content_type: ContentType = path
.extension()
.map(|x| x.to_string_lossy())

View File

@ -1,2 +1,3 @@
pub mod mdstat_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)
}