Compare commits

...

3 Commits

Author SHA1 Message Date
eeab38558a Adds dmi info + mouse matrix room
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2023-11-03 17:13:11 +01:00
b93ecb13b6 Adds first dmi parameter: form_factor
All checks were successful
continuous-integration/drone/push Build is passing
2023-11-03 06:49:44 +01:00
f186860a45 improved readme
All checks were successful
continuous-integration/drone/push Build is passing
2023-11-01 18:05:38 +01:00
3 changed files with 134 additions and 4 deletions

View File

@ -8,19 +8,38 @@ Hence mouse :D.
## Whut?
Mouse is a rust based facts gatherer that returns a list of facts of the host, it can be completely ran as user at this time and it's intended to stay that way.
Mouse does not alter the system, just gathers information and returns it in a key/value way (with extra epoch timestamp).
Mouse does not alter the system, just gathers information and returns it in json or yaml (default). At this time I can only test on x86_64 and aarch64, so those are the only supported platforms for now.
## Why?
Yes we have ohai, facter, osquery,...
But those won't let me learn Rust.
## How?
Download the release or build locally and execute. Use --help for information.
example: `mouse -g system -o json` will output system information in json.
At this time with the latest release (v0.1.4) there are 4 gatherers:
* env
* ipaddr
* iproute
* system
## Contribute?
Why not, but don't feel obligated.
If you want to contribute, feel free to send your patches to mouse-patch@sejo-it dot be.
## It doesn't work!
Aww, too bad, well you can always submit an issue or fix it yourself. It's open source afterall, isn't it?
## 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
email: jochen@sejo-it.be

View File

@ -2,6 +2,8 @@
// 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, io::ErrorKind, str, usize};
use sysinfo::{System, SystemExt};
use crate::types::fact::Fact;
@ -28,3 +30,105 @@ impl Fact for SystemData {
}
}
}
pub struct DMIData {}
impl DMIData {}
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,
// see https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.2.0.pdf
let ff: Vec<&str> = vec![
"Unknown",
"Other",
"Unknown",
"Desktop",
"Low Profile Desktop",
"Pizza Box",
"Mini Tower",
"Tower",
"Portable",
"Laptop",
"Notebook",
"Hand Held",
"Docking Station",
"All In One",
"Sub Notebook",
"Space-saving",
"Lunch Box",
"Main Server Chassis",
"Expansion Chassis",
"Sub Chassis",
"Bus Expansion Chassis",
"Peripheral Chassis",
"RAID Chassis",
"Rack Mount Chassis",
"Sealed-case PC",
"Multi-system",
"CompactPCI",
"AdvancedTCA",
"Blade",
"Blade Enclosure",
"Tablet",
"Convertible",
"Detachable",
"IoT Gateway",
"Embedded PC",
"Mini PC",
"Stick PC",
];
let filecontent: &str = match fs::read(path) {
Err(_) => ff[0],
Ok(x) => {
let ind: i32 = match str::from_utf8(&x) {
Ok(x) => x.trim().parse::<i32>().unwrap(),
Err(_) => 0,
};
let out: &str = if ff.len() <= ind as usize {
ff[0]
} else {
ff[ind as usize]
};
out
}
};
filecontent
}

View File

@ -13,7 +13,7 @@ use crate::gatherers::environment::EnvironmentData;
use crate::gatherers::ip::{IPData, IPRouteData};
use crate::types::fact::Fact;
use clap::Parser;
use gatherers::system::SystemData;
use gatherers::system::{DMIData, SystemData};
use serde_json::Value;
use std::collections::{HashMap, HashSet};
use yaml_rust::{YamlEmitter, YamlLoader};
@ -33,6 +33,12 @@ fn gather_list(gatherers: HashSet<String>, output: &str) -> String {
let mut outmap: HashMap<String, Value> = HashMap::new();
for g in gatherers {
match g.as_str() {
"dmi" => {
outmap.insert(
"dmi".to_string(),
serde_json::from_str(&DMIData {}.gather()).unwrap(),
);
}
"env" => {
outmap.insert(
"environment".to_string(),
@ -84,6 +90,7 @@ fn main() {
_ => "yaml",
};
let all: HashSet<String> = HashSet::from([
"dmi".to_string(),
"env".to_string(),
"ipaddr".to_string(),
"iproute".to_string(),