38 lines
1012 B
Rust
38 lines
1012 B
Rust
// src/main.rs
|
|
use actix_web::{App, HttpServer, Responder, get};
|
|
use hwinfo::PhysicalHost;
|
|
use std::env;
|
|
|
|
mod hwinfo;
|
|
|
|
#[get("/inventory")]
|
|
async fn inventory() -> impl Responder {
|
|
log::info!("Received inventory request");
|
|
let host = PhysicalHost::gather();
|
|
match host {
|
|
Ok(host) => {
|
|
log::info!("Inventory data gathered successfully");
|
|
actix_web::HttpResponse::Ok().json(host)
|
|
}
|
|
Err(error) => {
|
|
log::error!("Inventory data gathering FAILED");
|
|
actix_web::HttpResponse::InternalServerError().json(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
#[actix_web::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
env_logger::init();
|
|
|
|
let port = env::var("HARMONY_INVENTORY_AGENT_PORT").unwrap_or_else(|_| "8080".to_string());
|
|
let bind_addr = format!("0.0.0.0:{}", port);
|
|
|
|
log::info!("Starting inventory agent on {}", bind_addr);
|
|
|
|
HttpServer::new(|| App::new().service(inventory))
|
|
.bind(&bind_addr)?
|
|
.run()
|
|
.await
|
|
}
|