mirror of
https://github.com/csehviktor/status-monitor.git
synced 2025-08-08 18:06:14 +02:00
add config for agent
This commit is contained in:
6
agent/config.toml
Normal file
6
agent/config.toml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
send_interval_seconds = 5
|
||||||
|
|
||||||
|
[mqtt]
|
||||||
|
agent = "agent-1"
|
||||||
|
host = "0.0.0.0"
|
||||||
|
port = 1883
|
||||||
27
agent/src/config.rs
Normal file
27
agent/src/config.rs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
const CONFIG_PATH: &str = if cfg!(debug_assertions) {
|
||||||
|
"agent/config.toml"
|
||||||
|
} else {
|
||||||
|
"config.toml"
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct MqttConfig {
|
||||||
|
pub agent: String,
|
||||||
|
pub host: String,
|
||||||
|
pub port: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct Config {
|
||||||
|
pub send_interval_seconds: u64,
|
||||||
|
pub mqtt: MqttConfig,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load_config() -> anyhow::Result<Config> {
|
||||||
|
let file = std::fs::read_to_string(CONFIG_PATH)?;
|
||||||
|
let config: Config = toml::from_str(&file)?;
|
||||||
|
|
||||||
|
Ok(config)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user