endstat/src/config.rs

48 lines
1.4 KiB
Rust

use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Debug, Clone, Default)]
pub struct Config {
pub refresh_time: u64,
pub bind_address: String,
pub websites: Vec<WebsiteConfig>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct WebsiteConfig {
pub label: String,
pub base: Option<String>,
pub endpoints: Vec<EndpointConfig>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct EndpointConfig {
pub label: Option<String>,
pub endpoint: Option<String>,
pub port: Option<u16>,
pub code: Option<u16>,
pub body: Option<String>,
pub body_hash: Option<String>,
pub follow_redirects: Option<bool>,
pub max_rtt: Option<i64>,
pub should_err: Option<bool>,
pub webhooks: Option<Webhooks>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Webhooks {
pub on_change: Option<String>,
pub on_ok: Option<String>,
pub on_warn: Option<String>,
pub on_error: Option<String>,
pub on_not_ok: Option<String>,
}
pub fn get_endpoint_info(endpoint: EndpointConfig) -> (String, String, Option<u16>, u16, String) {
let path = endpoint.endpoint.unwrap_or_default();
let label = endpoint.label.unwrap_or_else(|| path.clone());
let code = endpoint.code.unwrap_or_else(|| 200);
let body = endpoint.body.unwrap_or_default();
(label, path, endpoint.port, code, body)
}