2026-01-21 15:36:27 -05:00
|
|
|
use config::{Config, ConfigError, File};
|
|
|
|
|
use lazy_static::lazy_static;
|
|
|
|
|
use log::error;
|
|
|
|
|
use serde::Deserialize;
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------
|
|
|
|
|
// Configuration structure
|
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
|
|
|
pub struct Log {
|
|
|
|
|
pub level: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
|
|
|
pub struct Timings {
|
|
|
|
|
pub arp_sender_timeout: u64,
|
|
|
|
|
pub arp_scan_duration: u64,
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-23 10:25:45 -05:00
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
|
|
|
pub struct Pushover {
|
|
|
|
|
pub token: String,
|
|
|
|
|
pub user_key: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
|
|
|
pub struct Notifications {
|
|
|
|
|
pub method: String,
|
|
|
|
|
pub pushover: Pushover,
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-21 15:36:27 -05:00
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
|
|
|
pub struct Settings {
|
|
|
|
|
pub log: Log,
|
|
|
|
|
pub timings: Timings,
|
2026-01-23 10:25:45 -05:00
|
|
|
pub notifications: Notifications,
|
2026-01-21 15:36:27 -05:00
|
|
|
}
|
|
|
|
|
// End configuration structure
|
|
|
|
|
// -----------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
const CONFIG_FILE_PATH: &str = "./oott.toml";
|
|
|
|
|
|
|
|
|
|
impl Settings {
|
|
|
|
|
pub fn new() -> Result<Self, ConfigError> {
|
|
|
|
|
let local_settings = Config::builder()
|
|
|
|
|
.add_source(File::with_name(CONFIG_FILE_PATH))
|
|
|
|
|
.build()?;
|
|
|
|
|
|
|
|
|
|
local_settings.try_deserialize()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
|
pub static ref CONFIG: Settings = match Settings::new() {
|
|
|
|
|
Ok(value) => value,
|
|
|
|
|
Err(error) => {
|
|
|
|
|
error!("Error reading configuration file ({CONFIG_FILE_PATH}): {error}");
|
|
|
|
|
panic!("Error reading configuration file ({CONFIG_FILE_PATH}): {error}");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|