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,6 +1,6 @@
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize)]
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub struct MacAddress(pub [u8; 6]);
|
||||
|
||||
impl MacAddress {
|
||||
@@ -25,6 +25,30 @@ impl std::fmt::Display for MacAddress {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<String> for MacAddress {
|
||||
type Error = std::io::Error;
|
||||
|
||||
fn try_from(value: String) -> Result<Self, Self::Error> {
|
||||
let parts: Vec<&str> = value.split(':').collect();
|
||||
if parts.len() != 6 {
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::InvalidInput,
|
||||
"Invalid MAC address format: expected 6 colon-separated hex pairs",
|
||||
));
|
||||
}
|
||||
let mut bytes = [0u8; 6];
|
||||
for (i, part) in parts.iter().enumerate() {
|
||||
bytes[i] = u8::from_str_radix(part, 16).map_err(|_| {
|
||||
std::io::Error::new(
|
||||
std::io::ErrorKind::InvalidInput,
|
||||
format!("Invalid hex value in part {}: '{}'", i, part),
|
||||
)
|
||||
})?;
|
||||
}
|
||||
Ok(MacAddress(bytes))
|
||||
}
|
||||
}
|
||||
|
||||
pub type IpAddress = std::net::IpAddr;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
Reference in New Issue
Block a user