From eeab38558a766c538a8e035943876e7365272702 Mon Sep 17 00:00:00 2001 From: Jochen Maes Date: Fri, 3 Nov 2023 17:13:11 +0100 Subject: [PATCH] Adds dmi info + mouse matrix room --- README.md | 2 +- src/gatherers/system.rs | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e0e2ca0..a16d6f3 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,6 @@ Aww, too bad, well you can always submit an issue or fix it yourself. It's open ## I have more questions: -matrix: @sejo:matrix.sejo-it.be +matrix: #mouse-dev:matrix.sejo-it.be discord: sejoit (legacy: sejo#5402) email: jochen@sejo-it.be diff --git a/src/gatherers/system.rs b/src/gatherers/system.rs index d6a4c58..d57570d 100644 --- a/src/gatherers/system.rs +++ b/src/gatherers/system.rs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use std::{fs, str, usize}; +use std::{fs, io::ErrorKind, str, usize}; use sysinfo::{System, SystemExt}; @@ -38,11 +38,38 @@ impl Fact for DMIData { fn gather(&self) -> String { json!({ "form_factor": get_form_factor("/sys/devices/virtual/dmi/id/chassis_type"), + "bios_date": get_string("/sys/devices/virtual/dmi/id/bios_date"), + "bios_vendor": get_string("/sys/devices/virtual/dmi/id/bios_vendor"), + "bios_version": get_string("/sys/devices/virtual/dmi/id/bios_version"), + "board_asset_tag": get_string("/sys/devices/virtual/dmi/id/board_asset_tag"), + "board_name": get_string("/sys/devices/virtual/dmi/id/board_name"), + "board_serial": get_string("/sys/devices/virtual/dmi/id/board_serial"), + "board_vendor": get_string("/sys/devices/virtual/dmi/id/board_vendor"), + "board_version": get_string("/sys/devices/virtual/dmi/id/board_version"), + "chassis_asset_tag": get_string("/sys/devices/virtual/dmi/id/chassis_asset_tag"), + "chassis_serial": get_string("/sys/devices/virtual/dmi/id/chassis_vendor"), + "chassis_vendor": get_string("/sys/devices/virtual/dmi/id/chassis_vendor"), + "chassis_version": get_string("/sys/devices/virtual/dmi/id/chassis_version"), + "product_name": get_string("/sys/devices/virtual/dmi/id/product_name"), + "product_serial": get_string("/sys/devices/virtual/dmi/id/product_serial"), + "product_uuid": get_string("/sys/devices/virtual/dmi/id/product_uuid"), + "product_version": get_string("/sys/devices/virtual/dmi/id/product_version"), + "system_vendor": get_string("/sys/devices/virtual/dmi/id/sys_vendor"), }) .to_string() } } +fn get_string(path: &str) -> String { + match fs::read(path) { + Ok(x) => String::from_utf8(x).unwrap().trim().to_string(), + Err(y) => match y.kind() { + ErrorKind::PermissionDenied => "This data needs sudo or root permissions".to_string(), + other_error => format!("Could not retrieve {other_error}"), + }, + } +} + fn get_form_factor(path: &str) -> &str { // Get form factor info // as learned from Ansible, we need to have the list in a specific order,