|
|
@ -1,20 +1,39 @@ |
|
|
|
use subbeat::types::{DatasourceConfig, InfluxConfig, PrometheusConfig}; |
|
|
|
use subbeat::types::{DatasourceConfig, InfluxConfig, PrometheusConfig}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)] |
|
|
|
|
|
|
|
pub struct WebhookAlertingConfig { |
|
|
|
|
|
|
|
endpoint: String |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)] |
|
|
|
|
|
|
|
pub enum AlertingType { |
|
|
|
|
|
|
|
Webhook(WebhookAlertingConfig) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)] |
|
|
|
|
|
|
|
pub struct AlertingConfig { |
|
|
|
|
|
|
|
alerting_type: AlertingType, |
|
|
|
|
|
|
|
interval: u64 // interval in seconds
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)] |
|
|
|
pub struct Config { |
|
|
|
pub struct Config { |
|
|
|
pub port: u16, |
|
|
|
pub port: u16, |
|
|
|
pub datasource_config: DatasourceConfig, |
|
|
|
pub datasource_config: DatasourceConfig, |
|
|
|
pub endpoint: Option<String>, |
|
|
|
pub alerting: Option<AlertingConfig>, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl Clone for Config { |
|
|
|
// impl Clone for Config {
|
|
|
|
fn clone(&self) -> Self { |
|
|
|
// fn clone(&self) -> Self {
|
|
|
|
return Config { |
|
|
|
// return Config {
|
|
|
|
port: self.port, |
|
|
|
// port: self.port,
|
|
|
|
datasource_config: self.datasource_config.clone(), |
|
|
|
// datasource_config: self.datasource_config.clone(),
|
|
|
|
endpoint: self.endpoint.clone(), |
|
|
|
// alerting: self.alerting.clone()
|
|
|
|
}; |
|
|
|
// };
|
|
|
|
} |
|
|
|
// }
|
|
|
|
} |
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
fn resolve_datasource(config: &mut config::Config) -> anyhow::Result<DatasourceConfig> { |
|
|
|
fn resolve_datasource(config: &mut config::Config) -> anyhow::Result<DatasourceConfig> { |
|
|
|
if config.get::<String>("prometheus.url").is_ok() { |
|
|
|
if config.get::<String>("prometheus.url").is_ok() { |
|
|
@ -39,6 +58,10 @@ fn resolve_datasource(config: &mut config::Config) -> anyhow::Result<DatasourceC |
|
|
|
// TODO: use actual config and env variables
|
|
|
|
// TODO: use actual config and env variables
|
|
|
|
impl Config { |
|
|
|
impl Config { |
|
|
|
pub fn new() -> anyhow::Result<Config> { |
|
|
|
pub fn new() -> anyhow::Result<Config> { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: parse alerting config
|
|
|
|
|
|
|
|
// TODO: throw error on bad config
|
|
|
|
|
|
|
|
|
|
|
|
let mut config = config::Config::default(); |
|
|
|
let mut config = config::Config::default(); |
|
|
|
|
|
|
|
|
|
|
|
if std::path::Path::new("config.toml").exists() { |
|
|
|
if std::path::Path::new("config.toml").exists() { |
|
|
@ -52,15 +75,15 @@ impl Config { |
|
|
|
config.set("port", "8000").unwrap(); |
|
|
|
config.set("port", "8000").unwrap(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let mut endpoint = None; |
|
|
|
// let mut endpoint = None;
|
|
|
|
if config.get::<String>("webhook.endpoint").is_ok() { |
|
|
|
// if config.get::<String>("webhook.endpoint").is_ok() {
|
|
|
|
endpoint = Some(config.get("webhook.endpoint").unwrap()); |
|
|
|
// endpoint = Some(config.get("webhook.endpoint").unwrap());
|
|
|
|
} |
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
Ok(Config { |
|
|
|
Ok(Config { |
|
|
|
port: config.get::<u16>("port").unwrap(), |
|
|
|
port: config.get::<u16>("port").unwrap(), |
|
|
|
datasource_config: resolve_datasource(&mut config)?, |
|
|
|
datasource_config: resolve_datasource(&mut config)?, |
|
|
|
endpoint, |
|
|
|
alerting: None, |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|