diff --git a/harmony/src/modules/monitoring/alertmanager_types.rs b/harmony/src/modules/monitoring/alertmanager_types.rs new file mode 100644 index 0000000..48a8f9e --- /dev/null +++ b/harmony/src/modules/monitoring/alertmanager_types.rs @@ -0,0 +1,102 @@ +use serde::{Deserialize, Serialize}; +use url::Url; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct AlertManagerValues { + pub alertmanager: AlertManager, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct AlertManager { + pub enabled: bool, + pub config: AlertManagerConfig, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct AlertChannelConfig { + pub receiver: AlertChannelReceiver, + pub route: AlertChannelRoute, + pub global_config: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct AlertChannelReceiver { + pub name: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub slack_configs: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + pub webhook_configs: Option>, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct AlertManagerRoute { + pub group_by: Vec, + pub group_wait: String, + pub group_interval: String, + pub repeat_interval: String, + pub routes: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct AlertChannelGlobalConfig { + #[serde(skip_serializing_if = "Option::is_none")] + pub slack_api_url: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct SlackConfig { + pub channel: String, + pub send_resolved: bool, + pub title: String, + pub text: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct WebhookConfig { + pub url: Url, + pub send_resolved: bool, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct AlertChannelRoute { + pub receiver: String, + pub matchers: Vec, + #[serde(default)] + pub r#continue: bool, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct AlertManagerConfig { + pub global: Option, + pub route: AlertManagerRoute, + pub receivers: Vec, +} + +impl AlertManagerValues { + pub fn default() -> Self { + Self { + alertmanager: AlertManager { + enabled: true, + config: AlertManagerConfig { + global: None, + route: AlertManagerRoute { + group_by: vec!["job".to_string()], + group_wait: "30s".to_string(), + group_interval: "5m".to_string(), + repeat_interval: "12h".to_string(), + routes: vec![AlertChannelRoute { + receiver: "null".to_string(), + matchers: vec!["alertname=Watchdog".to_string()], + r#continue: false, + }], + }, + receivers: vec![AlertChannelReceiver { + name: "null".to_string(), + slack_configs: None, + webhook_configs: None, + }], + }, + }, + } + } +} diff --git a/harmony/src/modules/monitoring/discord_webhook_sender.rs b/harmony/src/modules/monitoring/discord_webhook_sender.rs index f87ba0c..881ee09 100644 --- a/harmony/src/modules/monitoring/discord_webhook_sender.rs +++ b/harmony/src/modules/monitoring/discord_webhook_sender.rs @@ -1,5 +1,3 @@ -use std::sync::Arc; - use super::discord_alert_manager::discord_alert_manager_score; use async_trait::async_trait; use serde::Serialize; diff --git a/harmony/src/modules/monitoring/mod.rs b/harmony/src/modules/monitoring/mod.rs index d3eb288..1d89eeb 100644 --- a/harmony/src/modules/monitoring/mod.rs +++ b/harmony/src/modules/monitoring/mod.rs @@ -1,3 +1,4 @@ +pub mod alertmanager_types; mod config; mod discord_alert_manager; pub mod discord_webhook_sender;