Compare commits
No commits in common. "master" and "v0.1.4" have entirely different histories.
23
README.md
23
README.md
@ -8,38 +8,19 @@ Hence mouse :D.
|
|||||||
## Whut?
|
## 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 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 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.
|
Mouse does not alter the system, just gathers information and returns it in a key/value way (with extra epoch timestamp).
|
||||||
|
|
||||||
## Why?
|
## Why?
|
||||||
|
|
||||||
Yes we have ohai, facter, osquery,...
|
Yes we have ohai, facter, osquery,...
|
||||||
But those won't let me learn Rust.
|
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?
|
## Contribute?
|
||||||
|
|
||||||
Why not, but don't feel obligated.
|
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:
|
## I have more questions:
|
||||||
|
|
||||||
matrix: #mouse-dev:matrix.sejo-it.be
|
matrix: @sejo:matrix.sejo-it.be
|
||||||
discord: sejoit (legacy: sejo#5402)
|
discord: sejoit (legacy: sejo#5402)
|
||||||
email: jochen@sejo-it.be
|
email: jochen@sejo-it.be
|
@ -2,8 +2,6 @@
|
|||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// 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/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
use std::{fs, io::ErrorKind, str, usize};
|
|
||||||
|
|
||||||
use sysinfo::{System, SystemExt};
|
use sysinfo::{System, SystemExt};
|
||||||
|
|
||||||
use crate::types::fact::Fact;
|
use crate::types::fact::Fact;
|
||||||
@ -30,105 +28,3 @@ 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
|
|
||||||
}
|
|
||||||
|
@ -13,7 +13,7 @@ use crate::gatherers::environment::EnvironmentData;
|
|||||||
use crate::gatherers::ip::{IPData, IPRouteData};
|
use crate::gatherers::ip::{IPData, IPRouteData};
|
||||||
use crate::types::fact::Fact;
|
use crate::types::fact::Fact;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use gatherers::system::{DMIData, SystemData};
|
use gatherers::system::SystemData;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use yaml_rust::{YamlEmitter, YamlLoader};
|
use yaml_rust::{YamlEmitter, YamlLoader};
|
||||||
@ -33,12 +33,6 @@ fn gather_list(gatherers: HashSet<String>, output: &str) -> String {
|
|||||||
let mut outmap: HashMap<String, Value> = HashMap::new();
|
let mut outmap: HashMap<String, Value> = HashMap::new();
|
||||||
for g in gatherers {
|
for g in gatherers {
|
||||||
match g.as_str() {
|
match g.as_str() {
|
||||||
"dmi" => {
|
|
||||||
outmap.insert(
|
|
||||||
"dmi".to_string(),
|
|
||||||
serde_json::from_str(&DMIData {}.gather()).unwrap(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
"env" => {
|
"env" => {
|
||||||
outmap.insert(
|
outmap.insert(
|
||||||
"environment".to_string(),
|
"environment".to_string(),
|
||||||
@ -90,7 +84,6 @@ fn main() {
|
|||||||
_ => "yaml",
|
_ => "yaml",
|
||||||
};
|
};
|
||||||
let all: HashSet<String> = HashSet::from([
|
let all: HashSet<String> = HashSet::from([
|
||||||
"dmi".to_string(),
|
|
||||||
"env".to_string(),
|
"env".to_string(),
|
||||||
"ipaddr".to_string(),
|
"ipaddr".to_string(),
|
||||||
"iproute".to_string(),
|
"iproute".to_string(),
|
||||||
|
Loading…
Reference in New Issue
Block a user