diff --git a/examples/monitoring/src/main.rs b/examples/monitoring/src/main.rs index 3890c11..cccc999 100644 --- a/examples/monitoring/src/main.rs +++ b/examples/monitoring/src/main.rs @@ -1,11 +1,11 @@ use harmony::{ inventory::Inventory, maestro::Maestro, - modules::monitoring::alert_score::PrometheusAlertingScore, topology::K8sAnywhereTopology, + modules::monitoring::alert_score::HelmPrometheusAlertingScore, topology::K8sAnywhereTopology, }; #[tokio::main] async fn main() { - let alerting_score = PrometheusAlertingScore { receivers: vec![] }; + let alerting_score = HelmPrometheusAlertingScore { receivers: vec![] }; let mut maestro = Maestro::::initialize( Inventory::autoload(), K8sAnywhereTopology::from_env(), diff --git a/harmony/src/modules/monitoring/alert_score.rs b/harmony/src/modules/monitoring/alert_score.rs index 1971e55..6197128 100644 --- a/harmony/src/modules/monitoring/alert_score.rs +++ b/harmony/src/modules/monitoring/alert_score.rs @@ -1,8 +1,12 @@ use async_trait::async_trait; -use serde::Serialize; +use serde::{Serializer, Serialize}; use crate::{ - data::{Id, Version}, interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, inventory::Inventory, score::Score, topology::{HelmCommand, Topology} + data::{Id, Version}, + interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, + inventory::Inventory, + score::Score, + topology::{HelmCommand, Topology, Url}, }; #[async_trait] @@ -12,12 +16,29 @@ pub trait Installable { pub trait AlertSender: Send + Sync + std::fmt::Debug + Installable {} +#[async_trait] pub trait AlertReceiver: std::fmt::Debug + Send + Sync { - fn install(&self, sender: &S) -> Result<(), InterpretError>; + async fn install(&self, sender: &S) -> Result<(), InterpretError>; +} + +#[derive(Debug)] +pub struct DiscordWebhook { + name: String, + url: Url, +} + +#[async_trait] +impl AlertReceiver for DiscordWebhook { + async fn install(&self, sender: &Prometheus) -> Result<(), InterpretError> { + sender + .install_receiver(PrometheusReceiver { + }) + .await + } } #[derive(Clone, Debug, Serialize)] -pub struct PrometheusAlertingScore { +pub struct HelmPrometheusAlertingScore { pub receivers: Vec>>, } @@ -35,18 +56,60 @@ impl Clone for Box> { } } -impl Score for PrometheusAlertingScore { +impl Score for HelmPrometheusAlertingScore { fn create_interpret(&self) -> Box> { - Box::new(AlertingInterpret { sender: Prometheus {}, receivers: todo!() }) + Box::new(AlertingInterpret { + sender: Prometheus {}, + receivers: vec![Box::new(DiscordWebhook {url:todo!(), name: todo!() })], + }) } fn name(&self) -> String { - "PrometheusAlertingScore".to_string() + "HelmPrometheusAlertingScore".to_string() } } +#[derive(Debug)] pub struct Prometheus; +impl Prometheus { + async fn install_receiver( + &self, + prometheus_receiver: PrometheusReceiver, + ) -> Result<(), InterpretError> { + todo!() + } +} + +pub struct PrometheusReceiver { +} + +impl PrometheusReceiver { + fn get_prometheus_receiver_config(&self) {} +} + +pub struct AlertChannelGlobalConfig {} + +#[derive(Serialize)] +pub struct AlertReceiverRoute { + pub receiver: String, + pub matchers: Vec, + #[serde(default)] + pub r#continue: bool, +} +pub struct AlertChannelReceiver { + pub name: String, +} + +impl AlertSender for Prometheus {} + +#[async_trait] +impl Installable for Prometheus { + async fn ensure_installed(&self) -> Result<(), InterpretError> { + todo!() + } +} + #[derive(Debug)] pub struct AlertingInterpret { pub sender: S, @@ -61,11 +124,10 @@ impl Interpret for AlertingInterpret { inventory: &Inventory, topology: &T, ) -> Result { - - self.receivers.iter().try_for_each(|r| { - r.install(&self.sender) - })?; - todo!(); + for receiver in self.receivers.iter() { + receiver.install(&self.sender).await?; + } + todo!() } fn get_name(&self) -> InterpretName {