Compare commits
No commits in common. "e17ac1af8375b965193a781b67ce78a09dc486f9" and "045954f8d363d42757bcd3409ca2eedf513ede45" have entirely different histories.
e17ac1af83
...
045954f8d3
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1409,7 +1409,6 @@ dependencies = [
|
|||||||
"derive-new",
|
"derive-new",
|
||||||
"directories",
|
"directories",
|
||||||
"dockerfile_builder",
|
"dockerfile_builder",
|
||||||
"dyn-clone",
|
|
||||||
"email_address",
|
"email_address",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"fqdn",
|
"fqdn",
|
||||||
|
|||||||
@ -49,4 +49,3 @@ fqdn = { version = "0.4.6", features = [
|
|||||||
"serde",
|
"serde",
|
||||||
] }
|
] }
|
||||||
temp-dir = "0.1.14"
|
temp-dir = "0.1.14"
|
||||||
dyn-clone = "1.0.19"
|
|
||||||
|
|||||||
@ -10,9 +10,3 @@ impl Id {
|
|||||||
Self { value }
|
Self { value }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for Id {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
f.write_str(&self.value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -20,7 +20,6 @@ pub enum InterpretName {
|
|||||||
Panic,
|
Panic,
|
||||||
OPNSense,
|
OPNSense,
|
||||||
K3dInstallation,
|
K3dInstallation,
|
||||||
TenantInterpret,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for InterpretName {
|
impl std::fmt::Display for InterpretName {
|
||||||
@ -36,7 +35,6 @@ impl std::fmt::Display for InterpretName {
|
|||||||
InterpretName::Panic => f.write_str("Panic"),
|
InterpretName::Panic => f.write_str("Panic"),
|
||||||
InterpretName::OPNSense => f.write_str("OPNSense"),
|
InterpretName::OPNSense => f.write_str("OPNSense"),
|
||||||
InterpretName::K3dInstallation => f.write_str("K3dInstallation"),
|
InterpretName::K3dInstallation => f.write_str("K3dInstallation"),
|
||||||
InterpretName::TenantInterpret => f.write_str("Tenant"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,6 @@ mod host_binding;
|
|||||||
mod http;
|
mod http;
|
||||||
mod k8s_anywhere;
|
mod k8s_anywhere;
|
||||||
mod localhost;
|
mod localhost;
|
||||||
pub mod oberservability;
|
|
||||||
pub mod tenant;
|
pub mod tenant;
|
||||||
pub use k8s_anywhere::*;
|
pub use k8s_anywhere::*;
|
||||||
pub use localhost::*;
|
pub use localhost::*;
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
pub mod monitoring;
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
use async_trait::async_trait;
|
|
||||||
|
|
||||||
use std::fmt::Debug;
|
|
||||||
use url::Url;
|
|
||||||
|
|
||||||
use crate::interpret::InterpretError;
|
|
||||||
|
|
||||||
use crate::{interpret::Outcome, topology::Topology};
|
|
||||||
|
|
||||||
/// Represents an entity responsible for collecting and organizing observability data
|
|
||||||
/// from various telemetry sources
|
|
||||||
/// A `Monitor` abstracts the logic required to scrape, aggregate, and structure
|
|
||||||
/// monitoring data, enabling consistent processing regardless of the underlying data source.
|
|
||||||
#[async_trait]
|
|
||||||
pub trait Monitor<T: Topology>: Debug + Send + Sync {
|
|
||||||
async fn deploy_monitor(
|
|
||||||
&self,
|
|
||||||
topology: &T,
|
|
||||||
alert_receivers: Vec<AlertReceiver>,
|
|
||||||
) -> Result<Outcome, InterpretError>;
|
|
||||||
|
|
||||||
async fn delete_monitor(
|
|
||||||
&self,
|
|
||||||
topolgy: &T,
|
|
||||||
alert_receivers: Vec<AlertReceiver>,
|
|
||||||
) -> Result<Outcome, InterpretError>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct AlertReceiver {
|
|
||||||
pub receiver_id: String,
|
|
||||||
}
|
|
||||||
@ -12,5 +12,4 @@ pub mod load_balancer;
|
|||||||
pub mod monitoring;
|
pub mod monitoring;
|
||||||
pub mod okd;
|
pub mod okd;
|
||||||
pub mod opnsense;
|
pub mod opnsense;
|
||||||
pub mod tenant;
|
|
||||||
pub mod tftp;
|
pub mod tftp;
|
||||||
|
|||||||
@ -1,25 +1,30 @@
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use non_blank_string_rs::NonBlankString;
|
use non_blank_string_rs::NonBlankString;
|
||||||
use url::Url;
|
|
||||||
|
|
||||||
use crate::modules::helm::chart::HelmChartScore;
|
use crate::modules::helm::chart::HelmChartScore;
|
||||||
|
|
||||||
pub fn discord_alert_manager_score(
|
use super::{config::KubePrometheusConfig, monitoring_alerting::AlertChannel};
|
||||||
webhook_url: Url,
|
|
||||||
namespace: String,
|
fn get_discord_alert_manager_score(config: &KubePrometheusConfig) -> Option<HelmChartScore> {
|
||||||
name: String,
|
let (url, name) = config.alert_channel.iter().find_map(|channel| {
|
||||||
) -> HelmChartScore {
|
if let AlertChannel::Discord { webhook_url, name } = channel {
|
||||||
|
Some((webhook_url, name))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})?;
|
||||||
|
|
||||||
let values = format!(
|
let values = format!(
|
||||||
r#"
|
r#"
|
||||||
environment:
|
environment:
|
||||||
- name: "DISCORD_WEBHOOK"
|
- name: "DISCORD_WEBHOOK"
|
||||||
value: "{webhook_url}"
|
value: "{url}"
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
|
|
||||||
HelmChartScore {
|
Some(HelmChartScore {
|
||||||
namespace: Some(NonBlankString::from_str(&namespace).unwrap()),
|
namespace: Some(NonBlankString::from_str(&config.namespace).unwrap()),
|
||||||
release_name: NonBlankString::from_str(&name).unwrap(),
|
release_name: NonBlankString::from_str(&name).unwrap(),
|
||||||
chart_name: NonBlankString::from_str(
|
chart_name: NonBlankString::from_str(
|
||||||
"oci://hub.nationtech.io/library/alertmanager-discord",
|
"oci://hub.nationtech.io/library/alertmanager-discord",
|
||||||
@ -31,5 +36,13 @@ environment:
|
|||||||
create_namespace: true,
|
create_namespace: true,
|
||||||
install_only: true,
|
install_only: true,
|
||||||
repository: None,
|
repository: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn discord_alert_manager_score(config: &KubePrometheusConfig) -> HelmChartScore {
|
||||||
|
if let Some(chart) = get_discord_alert_manager_score(config) {
|
||||||
|
chart
|
||||||
|
} else {
|
||||||
|
panic!("Expected discord alert manager helm chart");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,55 +0,0 @@
|
|||||||
use async_trait::async_trait;
|
|
||||||
use serde_json::Value;
|
|
||||||
use url::Url;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
interpret::{InterpretError, Outcome},
|
|
||||||
topology::K8sAnywhereTopology,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct DiscordWebhookConfig {
|
|
||||||
pub webhook_url: Url,
|
|
||||||
pub name: String,
|
|
||||||
pub send_resolved_notifications: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait DiscordWebhookReceiver {
|
|
||||||
fn deploy_discord_webhook_receiver(
|
|
||||||
&self,
|
|
||||||
_notification_adapter_id: &str,
|
|
||||||
) -> Result<Outcome, InterpretError>;
|
|
||||||
|
|
||||||
fn delete_discord_webhook_receiver(
|
|
||||||
&self,
|
|
||||||
_notification_adapter_id: &str,
|
|
||||||
) -> Result<Outcome, InterpretError>;
|
|
||||||
}
|
|
||||||
|
|
||||||
// trait used to generate alert manager config values impl<T: Topology + AlertManagerConfig> Monitor for KubePrometheus
|
|
||||||
pub trait AlertManagerConfig<T> {
|
|
||||||
fn get_alert_manager_config(&self) -> Result<Value, InterpretError>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl<T: DiscordWebhookReceiver> AlertManagerConfig<T> for DiscordWebhookConfig {
|
|
||||||
fn get_alert_manager_config(&self) -> Result<Value, InterpretError> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl DiscordWebhookReceiver for K8sAnywhereTopology {
|
|
||||||
fn deploy_discord_webhook_receiver(
|
|
||||||
&self,
|
|
||||||
_notification_adapter_id: &str,
|
|
||||||
) -> Result<Outcome, InterpretError> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
fn delete_discord_webhook_receiver(
|
|
||||||
&self,
|
|
||||||
_notification_adapter_id: &str,
|
|
||||||
) -> Result<Outcome, InterpretError> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,5 +1,4 @@
|
|||||||
mod config;
|
mod config;
|
||||||
mod discord_alert_manager;
|
mod discord_alert_manager;
|
||||||
pub mod discord_webhook_sender;
|
|
||||||
mod kube_prometheus;
|
mod kube_prometheus;
|
||||||
pub mod monitoring_alerting;
|
pub mod monitoring_alerting;
|
||||||
|
|||||||
@ -96,28 +96,28 @@ impl MonitoringAlertingStackInterpret {
|
|||||||
topology: &T,
|
topology: &T,
|
||||||
config: &KubePrometheusConfig,
|
config: &KubePrometheusConfig,
|
||||||
) -> Result<Outcome, InterpretError> {
|
) -> Result<Outcome, InterpretError> {
|
||||||
//let mut outcomes = vec![];
|
let mut outcomes = vec![];
|
||||||
|
|
||||||
//for channel in &self.score.alert_channel {
|
for channel in &self.score.alert_channel {
|
||||||
// let outcome = match channel {
|
let outcome = match channel {
|
||||||
// AlertChannel::Discord { .. } => {
|
AlertChannel::Discord { .. } => {
|
||||||
// discord_alert_manager_score(config)
|
discord_alert_manager_score(config)
|
||||||
// .create_interpret()
|
.create_interpret()
|
||||||
// .execute(inventory, topology)
|
.execute(inventory, topology)
|
||||||
// .await
|
.await
|
||||||
// }
|
}
|
||||||
// AlertChannel::Slack { .. } => Ok(Outcome::success(
|
AlertChannel::Slack { .. } => Ok(Outcome::success(
|
||||||
// "No extra configs for slack alerting".to_string(),
|
"No extra configs for slack alerting".to_string(),
|
||||||
// )),
|
)),
|
||||||
// AlertChannel::Smpt { .. } => {
|
AlertChannel::Smpt { .. } => {
|
||||||
// todo!()
|
todo!()
|
||||||
// }
|
}
|
||||||
// };
|
};
|
||||||
// outcomes.push(outcome);
|
outcomes.push(outcome);
|
||||||
//}
|
}
|
||||||
//for result in outcomes {
|
for result in outcomes {
|
||||||
// result?;
|
result?;
|
||||||
//}
|
}
|
||||||
|
|
||||||
Ok(Outcome::success("All alert channels deployed".to_string()))
|
Ok(Outcome::success("All alert channels deployed".to_string()))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,67 +0,0 @@
|
|||||||
use async_trait::async_trait;
|
|
||||||
use serde::Serialize;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
data::{Id, Version},
|
|
||||||
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
|
|
||||||
inventory::Inventory,
|
|
||||||
score::Score,
|
|
||||||
topology::{
|
|
||||||
Topology,
|
|
||||||
tenant::{TenantConfig, TenantManager},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Clone)]
|
|
||||||
pub struct TenantScore {
|
|
||||||
config: TenantConfig,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Topology + TenantManager> Score<T> for TenantScore {
|
|
||||||
fn create_interpret(&self) -> Box<dyn crate::interpret::Interpret<T>> {
|
|
||||||
Box::new(TenantInterpret {
|
|
||||||
tenant_config: self.config.clone(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn name(&self) -> String {
|
|
||||||
format!("{} TenantScore", self.config.name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct TenantInterpret {
|
|
||||||
tenant_config: TenantConfig,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl<T: Topology + TenantManager> Interpret<T> for TenantInterpret {
|
|
||||||
async fn execute(
|
|
||||||
&self,
|
|
||||||
_inventory: &Inventory,
|
|
||||||
topology: &T,
|
|
||||||
) -> Result<Outcome, InterpretError> {
|
|
||||||
topology.provision_tenant(&self.tenant_config).await?;
|
|
||||||
|
|
||||||
Ok(Outcome::success(format!(
|
|
||||||
"Successfully provisioned tenant {} with id {}",
|
|
||||||
self.tenant_config.name, self.tenant_config.id
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_name(&self) -> InterpretName {
|
|
||||||
InterpretName::TenantInterpret
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_version(&self) -> Version {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_status(&self) -> InterpretStatus {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_children(&self) -> Vec<Id> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user