feat: automatically discover inventory (#127)
All checks were successful
Run Check Script / check (pull_request) Successful in 1m15s
All checks were successful
Run Check Script / check (pull_request) Successful in 1m15s
## Fully automated inventory gathering now works! Boot up harmony_inventory_agent with `cargo run -p harmony_inventory_agent` Launch the DiscoverInventoryAgentScore , currently available this way : `RUST_LOG=info cargo run -p example-cli -- -f Discover -y` And you will have automatically all hosts saved to the database. Run `cargo sqlx setup` if you have not done it yet. Co-authored-by: Ian Letourneau <ian@noma.to> Reviewed-on: #127 Co-authored-by: Jean-Gabriel Gill-Couture <jg@nationtech.io> Co-committed-by: Jean-Gabriel Gill-Couture <jg@nationtech.io>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use harmony_types::net::MacAddress;
|
||||
use log::{debug, warn};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
@@ -18,7 +19,7 @@ pub struct PhysicalHost {
|
||||
pub host_uuid: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct StorageDrive {
|
||||
pub name: String,
|
||||
pub model: String,
|
||||
@@ -32,13 +33,30 @@ pub struct StorageDrive {
|
||||
pub smart_status: Option<String>,
|
||||
}
|
||||
|
||||
impl StorageDrive {
|
||||
pub fn dummy() -> Self {
|
||||
Self {
|
||||
name: String::new(),
|
||||
model: String::new(),
|
||||
serial: String::new(),
|
||||
size_bytes: 0,
|
||||
logical_block_size: 0,
|
||||
physical_block_size: 0,
|
||||
rotational: false,
|
||||
wwn: None,
|
||||
interface_type: String::new(),
|
||||
smart_status: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct StorageController {
|
||||
pub name: String,
|
||||
pub driver: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct MemoryModule {
|
||||
pub size_bytes: u64,
|
||||
pub speed_mhz: Option<u32>,
|
||||
@@ -48,7 +66,7 @@ pub struct MemoryModule {
|
||||
pub rank: Option<u8>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct CPU {
|
||||
pub model: String,
|
||||
pub vendor: String,
|
||||
@@ -63,10 +81,10 @@ pub struct Chipset {
|
||||
pub vendor: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct NetworkInterface {
|
||||
pub name: String,
|
||||
pub mac_address: String,
|
||||
pub mac_address: MacAddress,
|
||||
pub speed_mbps: Option<u32>,
|
||||
pub is_up: bool,
|
||||
pub mtu: u32,
|
||||
@@ -76,6 +94,24 @@ pub struct NetworkInterface {
|
||||
pub firmware_version: Option<String>,
|
||||
}
|
||||
|
||||
impl NetworkInterface {
|
||||
pub fn dummy() -> Self {
|
||||
use harmony_macros::mac_address;
|
||||
|
||||
Self {
|
||||
name: String::new(),
|
||||
mac_address: mac_address!("00:00:00:00:00:00"),
|
||||
speed_mbps: Some(0),
|
||||
is_up: false,
|
||||
mtu: 0,
|
||||
ipv4_addresses: vec![],
|
||||
ipv6_addresses: vec![],
|
||||
driver: String::new(),
|
||||
firmware_version: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct ManagementInterface {
|
||||
pub kind: String,
|
||||
@@ -509,6 +545,7 @@ impl PhysicalHost {
|
||||
|
||||
let mac_address = Self::read_sysfs_string(&iface_path.join("address"))
|
||||
.map_err(|e| format!("Failed to read MAC address for {}: {}", iface_name, e))?;
|
||||
let mac_address = MacAddress::try_from(mac_address).map_err(|e| e.to_string())?;
|
||||
|
||||
let speed_mbps = if iface_path.join("speed").exists() {
|
||||
match Self::read_sysfs_u32(&iface_path.join("speed")) {
|
||||
|
||||
Reference in New Issue
Block a user