refactor: Prometheus alert channel configuration for extensibility to respect OpenClosed, this makes adding new alert channel types easier, requiring only a new trait implementation without modifying core logic
This commit is contained in:
parent
b5c6e1c99d
commit
78aadadd22
@ -16,3 +16,5 @@ harmony_macros = { path = "../../harmony_macros" }
|
|||||||
log = { workspace = true }
|
log = { workspace = true }
|
||||||
env_logger = { workspace = true }
|
env_logger = { workspace = true }
|
||||||
url = { workspace = true }
|
url = { workspace = true }
|
||||||
|
typetag = "0.2.20"
|
||||||
|
serde = "1.0.219"
|
||||||
|
|||||||
@ -4,9 +4,7 @@ use harmony::{
|
|||||||
maestro::Maestro,
|
maestro::Maestro,
|
||||||
modules::{
|
modules::{
|
||||||
lamp::{LAMPConfig, LAMPScore},
|
lamp::{LAMPConfig, LAMPScore},
|
||||||
monitoring::monitoring_alerting::{
|
monitoring::{kube_prometheus::prometheus_alert_channel::{DiscordChannel, SlackChannel}, monitoring_alerting::MonitoringAlertingScore},
|
||||||
AlertChannel, MonitoringAlertingStackScore, WebhookServiceType,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
topology::{K8sAnywhereTopology, Url},
|
topology::{K8sAnywhereTopology, Url},
|
||||||
};
|
};
|
||||||
@ -34,28 +32,42 @@ async fn main() {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// You can choose the type of Topology you want, we suggest starting with the
|
// You can choose the type of Topology you want, we suggest starting with the
|
||||||
// K8sAnywhereTopology as it is the most automatic one that enables you to easily deploy
|
// K8sAnywhereTopology as it is the most automatic one that enables you to easily deploy
|
||||||
// locally, to development environment from a CI, to staging, and to production with settings
|
// locally, to development environment from a CI, to staging, and to production with settings
|
||||||
// that automatically adapt to each environment grade.
|
// that automatically adapt to each environment grade.
|
||||||
let mut maestro = Maestro::<K8sAnywhereTopology>::initialize(
|
let mut maestro = Maestro::<K8sAnywhereTopology>::initialize (
|
||||||
Inventory::autoload(),
|
Inventory::autoload(),
|
||||||
K8sAnywhereTopology::new(),
|
K8sAnywhereTopology::new(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let url = url::Url::parse("https://discord.com/api/webhooks/dummy_channel/dummy_token")
|
let url = url::Url::parse(
|
||||||
|
"https://hooks.slack.com/services/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",
|
||||||
|
)
|
||||||
.expect("invalid URL");
|
.expect("invalid URL");
|
||||||
|
|
||||||
let mut monitoring_stack_score = MonitoringAlertingStackScore::new();
|
let mut monitoring_stack_score = MonitoringAlertingScore::new();
|
||||||
monitoring_stack_score.namespace = Some(lamp_stack.config.namespace.clone());
|
monitoring_stack_score.namespace = Some(lamp_stack.config.namespace.clone());
|
||||||
monitoring_stack_score.alert_channel = Some(AlertChannel::WebHookUrl {
|
monitoring_stack_score.alert_channels = vec![(Box::new(SlackChannel {
|
||||||
url: url,
|
name: "alert-test".to_string(),
|
||||||
webhook_service_type: WebhookServiceType::Discord,
|
webhook_url: url,})),
|
||||||
});
|
(Box::new(DiscordChannel {
|
||||||
|
name: "discord".to_string(),
|
||||||
|
webhook_url: url::Url::parse("https://discord.com/api/webhooks/1372994201746276462/YRn4TA9pj8ve3lfmyj1j0Yx97i92gv4U_uavt4CV4_SSIVArYUqfDzMOmzSTic2d8XSL").expect("invalid URL"),}))];
|
||||||
|
|
||||||
maestro.register_all(vec![Box::new(lamp_stack), Box::new(monitoring_stack_score)]);
|
|
||||||
|
//TODO in process of testing
|
||||||
|
//webhook depricated in MSTeams August 2025
|
||||||
|
//(AlertChannel::MSTeams {
|
||||||
|
// connector: "alert-test".to_string(),
|
||||||
|
// webhook_url: url::Url::parse("").expect("invalid URL"),
|
||||||
|
//}),
|
||||||
|
|
||||||
|
|
||||||
|
maestro.register_all(vec![Box::new(monitoring_stack_score)]);
|
||||||
// Here we bootstrap the CLI, this gives some nice features if you need them
|
// Here we bootstrap the CLI, this gives some nice features if you need them
|
||||||
harmony_cli::init(maestro, None).await.unwrap();
|
harmony_cli::init(maestro, None).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,3 +49,5 @@ fqdn = { version = "0.4.6", features = [
|
|||||||
"serde",
|
"serde",
|
||||||
] }
|
] }
|
||||||
temp-dir = "0.1.14"
|
temp-dir = "0.1.14"
|
||||||
|
typetag = "0.2.20"
|
||||||
|
dyn-clone = "1.0.19"
|
||||||
|
|||||||
@ -1,14 +1,16 @@
|
|||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use super::AlertChannel;
|
use super::kube_prometheus::{prometheus_alert_channel::PrometheusAlertChannel, types::AlertManagerValues};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct KubePrometheusConfig {
|
pub struct KubePrometheusChartConfig {
|
||||||
pub namespace: String,
|
pub namespace: String,
|
||||||
pub default_rules: bool,
|
pub default_rules: bool,
|
||||||
pub windows_monitoring: bool,
|
pub windows_monitoring: bool,
|
||||||
pub alert_manager: bool,
|
pub alert_manager: bool,
|
||||||
|
pub alert_manager_values: AlertManagerValues,
|
||||||
pub node_exporter: bool,
|
pub node_exporter: bool,
|
||||||
pub prometheus: bool,
|
pub prometheus: bool,
|
||||||
pub grafana: bool,
|
pub grafana: bool,
|
||||||
@ -22,16 +24,17 @@ pub struct KubePrometheusConfig {
|
|||||||
pub kube_proxy: bool,
|
pub kube_proxy: bool,
|
||||||
pub kube_state_metrics: bool,
|
pub kube_state_metrics: bool,
|
||||||
pub prometheus_operator: bool,
|
pub prometheus_operator: bool,
|
||||||
pub alert_channel: Vec<AlertChannel>,
|
pub alert_channels: Vec<Box<dyn PrometheusAlertChannel>>,
|
||||||
}
|
}
|
||||||
impl KubePrometheusConfig {
|
impl KubePrometheusChartConfig {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
namespace: "monitoring".into(),
|
namespace: "monitoring".into(),
|
||||||
default_rules: true,
|
default_rules: true,
|
||||||
windows_monitoring: false,
|
windows_monitoring: false,
|
||||||
alert_manager: true,
|
alert_manager: true,
|
||||||
alert_channel: Vec::new(),
|
alert_manager_values: AlertManagerValues::default(),
|
||||||
|
alert_channels: Vec::new(),
|
||||||
grafana: true,
|
grafana: true,
|
||||||
node_exporter: false,
|
node_exporter: false,
|
||||||
prometheus: true,
|
prometheus: true,
|
||||||
|
|||||||
@ -1,33 +1,26 @@
|
|||||||
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;
|
||||||
|
|
||||||
use super::AlertChannel;
|
pub fn discord_alert_manager_score(name: String, webhook: Url, namespace: String) -> HelmChartScore {
|
||||||
use super::config::KubePrometheusConfig;
|
let url = webhook;
|
||||||
|
|
||||||
fn get_discord_alert_manager_score(config: &KubePrometheusConfig) -> Option<HelmChartScore> {
|
|
||||||
let (url, name) = config.alert_channel.iter().find_map(|channel| {
|
|
||||||
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: "{url}"
|
value: "{url}"
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
|
|
||||||
Some(HelmChartScore {
|
HelmChartScore {
|
||||||
namespace: Some(NonBlankString::from_str(&config.namespace).unwrap()),
|
namespace: Some(NonBlankString::from_str(&namespace).unwrap()),
|
||||||
release_name: NonBlankString::from_str(&name).unwrap(),
|
release_name: NonBlankString::from_str(&name).unwrap(),
|
||||||
chart_name: NonBlankString::from_str("oci://hub.nationtech.io/library/alertmanager-discord")
|
chart_name: NonBlankString::from_str(
|
||||||
|
"oci://hub.nationtech.io/library/alertmanager-discord",
|
||||||
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
chart_version: None,
|
chart_version: None,
|
||||||
values_overrides: None,
|
values_overrides: None,
|
||||||
@ -35,13 +28,5 @@ 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,17 +1,10 @@
|
|||||||
use crate::modules::monitoring::kube_prometheus::types::{
|
use crate::modules::{helm::chart::HelmChartScore, monitoring::config::KubePrometheusChartConfig};
|
||||||
AlertChannelReceiver, AlertChannelRoute, AlertManager, AlertManagerConfig,
|
|
||||||
AlertManagerRoute, AlertManagerValues,
|
|
||||||
};
|
|
||||||
use crate::modules::{
|
|
||||||
helm::chart::HelmChartScore,
|
|
||||||
monitoring::{config::KubePrometheusConfig, kube_prometheus::traits::AlertEndpoint},
|
|
||||||
};
|
|
||||||
use log::info;
|
use log::info;
|
||||||
use non_blank_string_rs::NonBlankString;
|
use non_blank_string_rs::NonBlankString;
|
||||||
use serde_yaml::{self};
|
use serde_yaml::{self};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
pub fn kube_prometheus_helm_chart_score(config: &KubePrometheusConfig) -> HelmChartScore {
|
pub fn kube_prometheus_helm_chart_score(config: &KubePrometheusChartConfig) -> HelmChartScore {
|
||||||
//TODO this should be make into a rule with default formatting that can be easily passed as a vec
|
//TODO this should be make into a rule with default formatting that can be easily passed as a vec
|
||||||
//to the overrides or something leaving the user to deal with formatting here seems bad
|
//to the overrides or something leaving the user to deal with formatting here seems bad
|
||||||
let default_rules = config.default_rules.to_string();
|
let default_rules = config.default_rules.to_string();
|
||||||
@ -29,6 +22,7 @@ pub fn kube_prometheus_helm_chart_score(config: &KubePrometheusConfig) -> HelmCh
|
|||||||
let node_exporter = config.node_exporter.to_string();
|
let node_exporter = config.node_exporter.to_string();
|
||||||
let prometheus_operator = config.prometheus_operator.to_string();
|
let prometheus_operator = config.prometheus_operator.to_string();
|
||||||
let prometheus = config.prometheus.to_string();
|
let prometheus = config.prometheus.to_string();
|
||||||
|
let alert_manager_values = config.alert_manager_values.clone();
|
||||||
let mut values = format!(
|
let mut values = format!(
|
||||||
r#"
|
r#"
|
||||||
additionalPrometheusRulesMap:
|
additionalPrometheusRulesMap:
|
||||||
@ -151,66 +145,12 @@ prometheus:
|
|||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
|
|
||||||
let alert_manager_config = build_alert_manager_config(&config);
|
let alert_manager_yaml = serde_yaml::to_string(&alert_manager_values).expect("Failed to serialize YAML");
|
||||||
|
values.push_str(&alert_manager_yaml);
|
||||||
|
|
||||||
fn build_alert_manager_config(config: &KubePrometheusConfig) -> AlertManagerValues {
|
|
||||||
let mut global_config = None;
|
|
||||||
|
|
||||||
let (mut receivers, mut routes): (Vec<_>, Vec<_>) = config
|
|
||||||
.alert_channel
|
|
||||||
.iter()
|
|
||||||
.map(|s| s.build_alert_receiver())
|
|
||||||
.map(|chan| {
|
|
||||||
if let Some(global) = chan.global_config {
|
|
||||||
global_config = Some(global);
|
|
||||||
}
|
|
||||||
(chan.receiver, chan.route)
|
|
||||||
})
|
|
||||||
.unzip();
|
|
||||||
|
|
||||||
receivers.push(AlertChannelReceiver {
|
|
||||||
name: "null".to_string(),
|
|
||||||
slack_configs: None,
|
|
||||||
webhook_configs: None,
|
|
||||||
});
|
|
||||||
|
|
||||||
routes.push(AlertChannelRoute {
|
|
||||||
receiver: "null".to_string(),
|
|
||||||
matchers: vec!["alertname=Watchdog".to_string()],
|
|
||||||
r#continue: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
info!("after alert receiver: {:#?}", receivers);
|
|
||||||
info!("after alert routes: {:#?}", routes);
|
|
||||||
|
|
||||||
let config = AlertManagerConfig {
|
|
||||||
global: global_config,
|
|
||||||
route: AlertManagerRoute {
|
|
||||||
group_by: vec!["job".to_string()],
|
|
||||||
group_wait: "30s".to_string(),
|
|
||||||
group_interval: "5m".to_string(),
|
|
||||||
repeat_interval: "12h".to_string(),
|
|
||||||
routes,
|
|
||||||
},
|
|
||||||
receivers,
|
|
||||||
};
|
|
||||||
|
|
||||||
info!("alert manager config: {:?}", config);
|
|
||||||
|
|
||||||
AlertManagerValues {
|
|
||||||
alertmanager: AlertManager {
|
|
||||||
enabled: true,
|
|
||||||
config,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let yaml_config =
|
|
||||||
serde_yaml::to_string(&alert_manager_config).expect("Failed to serialize YAML");
|
|
||||||
|
|
||||||
values.push_str(&yaml_config);
|
|
||||||
|
|
||||||
info!("{}", values);
|
info!("{}", values);
|
||||||
|
|
||||||
HelmChartScore {
|
HelmChartScore {
|
||||||
namespace: Some(NonBlankString::from_str(&config.namespace).unwrap()),
|
namespace: Some(NonBlankString::from_str(&config.namespace).unwrap()),
|
||||||
release_name: NonBlankString::from_str("kube-prometheus").unwrap(),
|
release_name: NonBlankString::from_str("kube-prometheus").unwrap(),
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
pub mod traits;
|
|
||||||
pub mod kube_prometheus;
|
pub mod kube_prometheus;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
pub mod prometheus_alert_channel;
|
||||||
|
|||||||
@ -0,0 +1,140 @@
|
|||||||
|
use crate::{
|
||||||
|
interpret::InterpretError,
|
||||||
|
modules::{
|
||||||
|
helm::chart::HelmChartScore,
|
||||||
|
monitoring::{
|
||||||
|
discord_alert_manager::discord_alert_manager_score,
|
||||||
|
kube_prometheus::types::{
|
||||||
|
AlertChannelConfig, AlertChannelGlobalConfig, AlertChannelReceiver,
|
||||||
|
AlertChannelRoute, SlackConfig, WebhookConfig,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
use dyn_clone::DynClone;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::fmt::Debug;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
|
#[typetag::serde(tag = "channel_type")]
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
pub trait PrometheusAlertChannel: DynClone + Debug + Send + Sync {
|
||||||
|
fn get_alert_manager_config_contribution(&self) -> Result<AlertChannelConfig, InterpretError>;
|
||||||
|
|
||||||
|
fn get_dependency_score(&self, namespace:String) -> Option<HelmChartScore>;
|
||||||
|
}
|
||||||
|
|
||||||
|
dyn_clone::clone_trait_object!(PrometheusAlertChannel);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct DiscordChannel {
|
||||||
|
pub name: String,
|
||||||
|
pub webhook_url: Url,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[typetag::serde]
|
||||||
|
impl PrometheusAlertChannel for DiscordChannel {
|
||||||
|
fn get_alert_manager_config_contribution(&self) -> Result<AlertChannelConfig, InterpretError> {
|
||||||
|
let service_url = format!("http://{}-alertmanager-discord:9094", &self.name);
|
||||||
|
Ok(AlertChannelConfig {
|
||||||
|
receiver: AlertChannelReceiver {
|
||||||
|
name: format!("Discord-{}", self.name),
|
||||||
|
slack_configs: None,
|
||||||
|
webhook_configs: Some(vec![WebhookConfig {
|
||||||
|
url: url::Url::parse(&service_url)
|
||||||
|
.expect("invalid url"),
|
||||||
|
send_resolved: true,
|
||||||
|
}]),
|
||||||
|
},
|
||||||
|
route: AlertChannelRoute {
|
||||||
|
receiver: format!("Discord-{}", self.name),
|
||||||
|
matchers: vec!["alertname!=Watchdog".to_string()],
|
||||||
|
r#continue: true,
|
||||||
|
},
|
||||||
|
global_config: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fn get_dependency_score(&self, namespace: String) -> Option<HelmChartScore> {
|
||||||
|
Some(discord_alert_manager_score(self.name.clone(), self.webhook_url.clone(), namespace.clone()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct SlackChannel {
|
||||||
|
pub name: String,
|
||||||
|
pub webhook_url: Url,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[typetag::serde]
|
||||||
|
impl PrometheusAlertChannel for SlackChannel {
|
||||||
|
fn get_alert_manager_config_contribution(&self) -> Result<AlertChannelConfig, InterpretError> {
|
||||||
|
Ok(AlertChannelConfig {
|
||||||
|
receiver: AlertChannelReceiver {
|
||||||
|
name: format!("Slack-{}", self.name),
|
||||||
|
slack_configs: Some(vec![SlackConfig {
|
||||||
|
channel: self.name.clone(),
|
||||||
|
send_resolved: true,
|
||||||
|
title: "{{ .CommonAnnotations.title }}".to_string(),
|
||||||
|
text: ">-
|
||||||
|
*Alert:* {{ .CommonLabels.alertname }}
|
||||||
|
*Severity:* {{ .CommonLabels.severity }}
|
||||||
|
*Namespace:* {{ .CommonLabels.namespace }}
|
||||||
|
*Pod:* {{ .CommonLabels.pod }}
|
||||||
|
*ExternalURL:* {{ .ExternalURL }}
|
||||||
|
|
||||||
|
{{ range .Alerts }}
|
||||||
|
*Instance:* {{ .Labels.instance }}
|
||||||
|
*Summary:* {{ .Annotations.summary }}
|
||||||
|
*Description:* {{ .Annotations.description }}
|
||||||
|
*Starts At:* {{ .StartsAt }}
|
||||||
|
*Status:* {{ .Status }}
|
||||||
|
{{ end }}"
|
||||||
|
.to_string(),
|
||||||
|
}]),
|
||||||
|
webhook_configs: None,
|
||||||
|
},
|
||||||
|
route: AlertChannelRoute {
|
||||||
|
receiver: format!("Slack-{}", self.name),
|
||||||
|
matchers: vec!["alertname!=Watchdog".to_string()],
|
||||||
|
r#continue: true,
|
||||||
|
},
|
||||||
|
global_config: Some(AlertChannelGlobalConfig {
|
||||||
|
slack_api_url: Some(self.webhook_url.clone()),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fn get_dependency_score(&self, _namespace: String) -> Option<HelmChartScore> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct NullReceiver {}
|
||||||
|
|
||||||
|
impl NullReceiver {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[typetag::serde]
|
||||||
|
impl PrometheusAlertChannel for NullReceiver {
|
||||||
|
fn get_alert_manager_config_contribution(&self) -> Result<AlertChannelConfig, InterpretError> {
|
||||||
|
Ok(AlertChannelConfig {
|
||||||
|
receiver: AlertChannelReceiver {
|
||||||
|
name: "null".to_string(),
|
||||||
|
slack_configs: None,
|
||||||
|
webhook_configs: None,
|
||||||
|
},
|
||||||
|
route: AlertChannelRoute {
|
||||||
|
receiver: "null".to_string(),
|
||||||
|
matchers: vec!["alertname=Watchdog".to_string()],
|
||||||
|
r#continue: false,
|
||||||
|
},
|
||||||
|
global_config: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fn get_dependency_score(&self, _namespace: String) -> Option<HelmChartScore> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,92 +0,0 @@
|
|||||||
use crate::modules::monitoring::AlertChannel;
|
|
||||||
|
|
||||||
use super::types::{AlertChannelConfig, AlertChannelGlobalConfig, AlertChannelReceiver, AlertChannelRoute, SlackConfig, WebhookConfig};
|
|
||||||
|
|
||||||
|
|
||||||
pub trait AlertEndpoint {
|
|
||||||
//fn register_webhook(&self, webhook_url: Url);
|
|
||||||
fn build_alert_receiver(&self) -> AlertChannelConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AlertEndpoint for AlertChannel {
|
|
||||||
fn build_alert_receiver(&self) -> AlertChannelConfig {
|
|
||||||
match self {
|
|
||||||
AlertChannel::Discord { name, .. } => AlertChannelConfig {
|
|
||||||
receiver: AlertChannelReceiver {
|
|
||||||
name: format!("Discord-{name}"),
|
|
||||||
slack_configs: None,
|
|
||||||
webhook_configs: Some(vec![WebhookConfig {
|
|
||||||
url: url::Url::parse("http://{name}-alertmanager-discord:9094")
|
|
||||||
.expect("invalid url"),
|
|
||||||
send_resolved: true,
|
|
||||||
}]),
|
|
||||||
},
|
|
||||||
route: AlertChannelRoute {
|
|
||||||
receiver: format!("Discord-{name}"),
|
|
||||||
matchers: vec!["alertname!=Watchdog".to_string()],
|
|
||||||
r#continue: true,
|
|
||||||
},
|
|
||||||
global_config: None,
|
|
||||||
},
|
|
||||||
AlertChannel::Slack {
|
|
||||||
slack_channel,
|
|
||||||
webhook_url,
|
|
||||||
} => AlertChannelConfig {
|
|
||||||
receiver: AlertChannelReceiver {
|
|
||||||
name: format!("Slack-{slack_channel}"),
|
|
||||||
slack_configs: Some(vec![SlackConfig {
|
|
||||||
channel: slack_channel.clone(),
|
|
||||||
send_resolved: true,
|
|
||||||
title: "{{ .CommonAnnotations.title }}".to_string(),
|
|
||||||
text: ">-
|
|
||||||
*Alert:* {{ .CommonLabels.alertname }}
|
|
||||||
*Severity:* {{ .CommonLabels.severity }}
|
|
||||||
*Namespace:* {{ .CommonLabels.namespace }}
|
|
||||||
*Pod:* {{ .CommonLabels.pod }}
|
|
||||||
*ExternalURL:* {{ .ExternalURL }}
|
|
||||||
|
|
||||||
{{ range .Alerts }}
|
|
||||||
*Instance:* {{ .Labels.instance }}
|
|
||||||
*Summary:* {{ .Annotations.summary }}
|
|
||||||
*Description:* {{ .Annotations.description }}
|
|
||||||
*Starts At:* {{ .StartsAt }}
|
|
||||||
*Status:* {{ .Status }}
|
|
||||||
{{ end }}".to_string()
|
|
||||||
}]),
|
|
||||||
webhook_configs: None,
|
|
||||||
},
|
|
||||||
route: AlertChannelRoute {
|
|
||||||
receiver: format!("Slack-{slack_channel}"),
|
|
||||||
matchers: vec!["alertname!=Watchdog".to_string()],
|
|
||||||
r#continue: true,
|
|
||||||
},
|
|
||||||
global_config: Some(AlertChannelGlobalConfig {
|
|
||||||
slack_api_url: Some(webhook_url.clone()),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
AlertChannel::MSTeams {
|
|
||||||
connector, ..
|
|
||||||
} => AlertChannelConfig{
|
|
||||||
receiver: AlertChannelReceiver{
|
|
||||||
name: format!("MSTeams-{connector}"),
|
|
||||||
slack_configs: None,
|
|
||||||
webhook_configs: Some(vec![WebhookConfig{
|
|
||||||
url: url::Url::parse("http://prometheus-msteams-prometheus-msteams.monitoring.svc.cluster.local:2000/alertmanager").expect("invalid url"),
|
|
||||||
send_resolved: true,}])
|
|
||||||
},
|
|
||||||
route: AlertChannelRoute{
|
|
||||||
receiver: format!("MSTeams-{connector}"),
|
|
||||||
matchers: vec!["alertname!=Watchdog".to_string()],
|
|
||||||
r#continue: true,
|
|
||||||
},
|
|
||||||
global_config: None, },
|
|
||||||
|
|
||||||
AlertChannel::Smpt {
|
|
||||||
email_address,
|
|
||||||
service_name,
|
|
||||||
} => todo!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,25 +1,25 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct AlertManagerValues {
|
pub struct AlertManagerValues {
|
||||||
pub alertmanager: AlertManager,
|
pub alertmanager: AlertManager,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct AlertManager {
|
pub struct AlertManager {
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub config: AlertManagerConfig,
|
pub config: AlertManagerConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct AlertChannelConfig {
|
pub struct AlertChannelConfig {
|
||||||
pub receiver: AlertChannelReceiver,
|
pub receiver: AlertChannelReceiver,
|
||||||
pub route: AlertChannelRoute,
|
pub route: AlertChannelRoute,
|
||||||
pub global_config: Option<AlertChannelGlobalConfig>,
|
pub global_config: Option<AlertChannelGlobalConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct AlertChannelReceiver {
|
pub struct AlertChannelReceiver {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
@ -28,7 +28,7 @@ pub struct AlertChannelReceiver {
|
|||||||
pub webhook_configs: Option<Vec<WebhookConfig>>,
|
pub webhook_configs: Option<Vec<WebhookConfig>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct AlertManagerRoute {
|
pub struct AlertManagerRoute {
|
||||||
pub group_by: Vec<String>,
|
pub group_by: Vec<String>,
|
||||||
pub group_wait: String,
|
pub group_wait: String,
|
||||||
@ -37,13 +37,13 @@ pub struct AlertManagerRoute {
|
|||||||
pub routes: Vec<AlertChannelRoute>,
|
pub routes: Vec<AlertChannelRoute>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct AlertChannelGlobalConfig {
|
pub struct AlertChannelGlobalConfig {
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub slack_api_url: Option<Url>,
|
pub slack_api_url: Option<Url>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct SlackConfig {
|
pub struct SlackConfig {
|
||||||
pub channel: String,
|
pub channel: String,
|
||||||
pub send_resolved: bool,
|
pub send_resolved: bool,
|
||||||
@ -51,13 +51,13 @@ pub struct SlackConfig {
|
|||||||
pub text: String,
|
pub text: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct WebhookConfig {
|
pub struct WebhookConfig {
|
||||||
pub url: Url,
|
pub url: Url,
|
||||||
pub send_resolved: bool,
|
pub send_resolved: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct AlertChannelRoute {
|
pub struct AlertChannelRoute {
|
||||||
pub receiver: String,
|
pub receiver: String,
|
||||||
pub matchers: Vec<String>,
|
pub matchers: Vec<String>,
|
||||||
@ -65,9 +65,30 @@ pub struct AlertChannelRoute {
|
|||||||
pub r#continue: bool,
|
pub r#continue: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct AlertManagerConfig {
|
pub struct AlertManagerConfig {
|
||||||
pub global: Option<AlertChannelGlobalConfig>,
|
pub global: Option<AlertChannelGlobalConfig>,
|
||||||
pub route: AlertManagerRoute,
|
pub route: AlertManagerRoute,
|
||||||
pub receivers: Vec<AlertChannelReceiver>,
|
pub receivers: Vec<AlertChannelReceiver>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 }],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
5003
harmony/src/modules/monitoring/kube_prometheus/values.yaml
Normal file
5003
harmony/src/modules/monitoring/kube_prometheus/values.yaml
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,32 +1,5 @@
|
|||||||
use email_address::EmailAddress;
|
|
||||||
use serde::Serialize;
|
|
||||||
use url::Url;
|
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
mod discord_alert_manager;
|
mod discord_alert_manager;
|
||||||
pub mod kube_prometheus;
|
pub mod kube_prometheus;
|
||||||
pub mod monitoring_alerting;
|
pub mod monitoring_alerting;
|
||||||
mod prometheus_msteams;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub enum AlertChannel {
|
|
||||||
Discord {
|
|
||||||
name: String,
|
|
||||||
webhook_url: Url,
|
|
||||||
},
|
|
||||||
Slack {
|
|
||||||
slack_channel: String,
|
|
||||||
webhook_url: Url,
|
|
||||||
},
|
|
||||||
MSTeams {
|
|
||||||
connector: String,
|
|
||||||
webhook_url: Url,
|
|
||||||
},
|
|
||||||
//TODO test and implement in helm chart
|
|
||||||
//currently does not work
|
|
||||||
Smpt {
|
|
||||||
email_address: EmailAddress,
|
|
||||||
service_name: String,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@ -1,41 +1,46 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use email_address::EmailAddress;
|
|
||||||
|
|
||||||
use log::info;
|
use log::info;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use url::Url;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
data::{Id, Version},
|
data::{Id, Version},
|
||||||
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
|
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
|
||||||
inventory::Inventory,
|
inventory::Inventory,
|
||||||
|
modules::monitoring::kube_prometheus::types::{
|
||||||
|
AlertManager, AlertManagerConfig, AlertManagerRoute,
|
||||||
|
},
|
||||||
score::Score,
|
score::Score,
|
||||||
topology::{HelmCommand, Topology},
|
topology::{HelmCommand, Topology},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
config::KubePrometheusConfig, discord_alert_manager::discord_alert_manager_score, kube_prometheus::kube_prometheus::kube_prometheus_helm_chart_score, prometheus_msteams::prometheus_msteams_score, AlertChannel
|
config::KubePrometheusChartConfig,
|
||||||
|
kube_prometheus::{
|
||||||
|
kube_prometheus::kube_prometheus_helm_chart_score,
|
||||||
|
prometheus_alert_channel::{NullReceiver, PrometheusAlertChannel},
|
||||||
|
types::AlertManagerValues,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct MonitoringAlertingStackScore {
|
pub struct MonitoringAlertingScore {
|
||||||
pub alert_channel: Vec<AlertChannel>,
|
pub alert_channels: Vec<Box<dyn PrometheusAlertChannel>>,
|
||||||
pub namespace: Option<String>,
|
pub namespace: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MonitoringAlertingStackScore {
|
impl MonitoringAlertingScore {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
alert_channel: Vec::new(),
|
alert_channels: Vec::new(),
|
||||||
namespace: None,
|
namespace: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Topology + HelmCommand> Score<T> for MonitoringAlertingStackScore {
|
impl<T: Topology + HelmCommand> Score<T> for MonitoringAlertingScore {
|
||||||
fn create_interpret(&self) -> Box<dyn Interpret<T>> {
|
fn create_interpret(&self) -> Box<dyn Interpret<T>> {
|
||||||
Box::new(MonitoringAlertingStackInterpret {
|
Box::new(MonitoringAlertingInterpret {
|
||||||
score: self.clone(),
|
score: self.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -45,17 +50,61 @@ impl<T: Topology + HelmCommand> Score<T> for MonitoringAlertingStackScore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
struct MonitoringAlertingStackInterpret {
|
struct MonitoringAlertingInterpret {
|
||||||
score: MonitoringAlertingStackScore,
|
score: MonitoringAlertingScore,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MonitoringAlertingStackInterpret {
|
impl MonitoringAlertingInterpret {
|
||||||
async fn build_kube_prometheus_helm_chart_config(&self) -> KubePrometheusConfig {
|
async fn build_kube_prometheus_helm_chart_config(&self) -> KubePrometheusChartConfig {
|
||||||
let mut config = KubePrometheusConfig::new();
|
let mut config = KubePrometheusChartConfig::new();
|
||||||
|
let mut receivers = Vec::new();
|
||||||
|
let mut routes = Vec::new();
|
||||||
|
let mut global_config = None;
|
||||||
|
|
||||||
if let Some(ns) = &self.score.namespace {
|
if let Some(ns) = &self.score.namespace {
|
||||||
config.namespace = ns.clone();
|
config.namespace = ns.clone();
|
||||||
|
};
|
||||||
|
|
||||||
|
let null_channel = NullReceiver::new();
|
||||||
|
let null_channel = null_channel
|
||||||
|
.get_alert_manager_config_contribution()
|
||||||
|
.unwrap();
|
||||||
|
receivers.push(null_channel.receiver);
|
||||||
|
routes.push(null_channel.route);
|
||||||
|
|
||||||
|
for channel in self.score.alert_channels.clone() {
|
||||||
|
let alert_manager_config_contribution =
|
||||||
|
channel.get_alert_manager_config_contribution().unwrap();
|
||||||
|
receivers.push(alert_manager_config_contribution.receiver);
|
||||||
|
routes.push(alert_manager_config_contribution.route);
|
||||||
|
if let Some(global) = alert_manager_config_contribution.global_config {
|
||||||
|
global_config = Some(global);
|
||||||
}
|
}
|
||||||
config.alert_channel = self.score.alert_channel.clone();
|
}
|
||||||
|
|
||||||
|
info!("after alert receiver: {:#?}", receivers);
|
||||||
|
info!("after alert routes: {:#?}", routes);
|
||||||
|
|
||||||
|
let alert_manager_config = AlertManagerConfig {
|
||||||
|
global: global_config,
|
||||||
|
route: AlertManagerRoute {
|
||||||
|
group_by: vec!["job".to_string()],
|
||||||
|
group_wait: "30s".to_string(),
|
||||||
|
group_interval: "5m".to_string(),
|
||||||
|
repeat_interval: "12h".to_string(),
|
||||||
|
routes,
|
||||||
|
},
|
||||||
|
receivers,
|
||||||
|
};
|
||||||
|
|
||||||
|
info!("alert manager config: {:?}", config);
|
||||||
|
|
||||||
|
config.alert_manager_values = AlertManagerValues {
|
||||||
|
alertmanager: AlertManager {
|
||||||
|
enabled: true,
|
||||||
|
config: alert_manager_config,
|
||||||
|
},
|
||||||
|
};
|
||||||
config
|
config
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +112,7 @@ impl MonitoringAlertingStackInterpret {
|
|||||||
&self,
|
&self,
|
||||||
inventory: &Inventory,
|
inventory: &Inventory,
|
||||||
topology: &T,
|
topology: &T,
|
||||||
config: &KubePrometheusConfig,
|
config: &KubePrometheusChartConfig,
|
||||||
) -> Result<Outcome, InterpretError> {
|
) -> Result<Outcome, InterpretError> {
|
||||||
let helm_chart = kube_prometheus_helm_chart_score(config);
|
let helm_chart = kube_prometheus_helm_chart_score(config);
|
||||||
helm_chart
|
helm_chart
|
||||||
@ -72,39 +121,29 @@ impl MonitoringAlertingStackInterpret {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn deploy_alert_channel_service<T: Topology + HelmCommand>(
|
async fn deploy_alert_channel_dependencies<T: Topology + HelmCommand>(
|
||||||
&self,
|
&self,
|
||||||
inventory: &Inventory,
|
inventory: &Inventory,
|
||||||
topology: &T,
|
topology: &T,
|
||||||
config: &KubePrometheusConfig,
|
config: &KubePrometheusChartConfig,
|
||||||
) -> Result<Outcome, InterpretError> {
|
) -> Result<Outcome, InterpretError> {
|
||||||
let mut outcomes = vec![];
|
let mut outcomes = Vec::new();
|
||||||
|
|
||||||
for channel in &self.score.alert_channel {
|
for channel in &self.score.alert_channels {
|
||||||
let outcome = match channel {
|
let ns = config.namespace.clone();
|
||||||
AlertChannel::Discord { .. } => {
|
if let Some(dependency_score) = channel.get_dependency_score(ns) {
|
||||||
discord_alert_manager_score(config)
|
match dependency_score
|
||||||
.create_interpret()
|
.create_interpret()
|
||||||
.execute(inventory, topology)
|
.execute(inventory, topology)
|
||||||
.await
|
.await
|
||||||
|
{
|
||||||
|
Ok(outcome) => outcomes.push(outcome),
|
||||||
|
Err(e) => {
|
||||||
|
info!("failed to deploy dependency: {}", { &e });
|
||||||
|
return Err(e);
|
||||||
}
|
}
|
||||||
AlertChannel::Slack { .. } => Ok(Outcome::success(
|
|
||||||
"No extra configs for slack alerting".to_string(),
|
|
||||||
)),
|
|
||||||
AlertChannel::MSTeams { .. } => {
|
|
||||||
prometheus_msteams_score(config)
|
|
||||||
.create_interpret()
|
|
||||||
.execute(inventory, topology)
|
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
AlertChannel::Smpt { .. } => {
|
|
||||||
todo!()
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
outcomes.push(outcome);
|
|
||||||
}
|
|
||||||
for result in outcomes {
|
|
||||||
result?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Outcome::success("All alert channels deployed".to_string()))
|
Ok(Outcome::success("All alert channels deployed".to_string()))
|
||||||
@ -112,22 +151,22 @@ impl MonitoringAlertingStackInterpret {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<T: Topology + HelmCommand> Interpret<T> for MonitoringAlertingStackInterpret {
|
impl<T: Topology + HelmCommand> Interpret<T> for MonitoringAlertingInterpret {
|
||||||
async fn execute(
|
async fn execute(
|
||||||
&self,
|
&self,
|
||||||
inventory: &Inventory,
|
inventory: &Inventory,
|
||||||
topology: &T,
|
topology: &T,
|
||||||
) -> Result<Outcome, InterpretError> {
|
) -> Result<Outcome, InterpretError> {
|
||||||
let config = self.build_kube_prometheus_helm_chart_config().await;
|
let config = self.build_kube_prometheus_helm_chart_config().await;
|
||||||
info!("Built kube prometheus config");
|
info!("Built kube prometheus config{:?}", config);
|
||||||
info!("Installing kube prometheus chart");
|
info!("Installing kube prometheus chart");
|
||||||
self.deploy_kube_prometheus_helm_chart_score(inventory, topology, &config)
|
self.deploy_kube_prometheus_helm_chart_score(inventory, topology, &config)
|
||||||
.await?;
|
.await?;
|
||||||
info!("Installing alert channel service");
|
info!("Installing alert channel service");
|
||||||
self.deploy_alert_channel_service(inventory, topology, &config)
|
self.deploy_alert_channel_dependencies(inventory, topology, &config)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(Outcome::success(format!(
|
Ok(Outcome::success(format!(
|
||||||
"succesfully deployed monitoring and alerting stack"
|
"succesfully deployed monitoring and alerting score"
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,46 +0,0 @@
|
|||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
use non_blank_string_rs::NonBlankString;
|
|
||||||
|
|
||||||
use crate::modules::helm::chart::HelmChartScore;
|
|
||||||
|
|
||||||
use super::{config::KubePrometheusConfig, AlertChannel};
|
|
||||||
|
|
||||||
fn build_prometheus_msteams_score(config: &KubePrometheusConfig) -> Option<HelmChartScore> {
|
|
||||||
let (url, name) = config.alert_channel.iter().find_map(|channel| {
|
|
||||||
if let AlertChannel::MSTeams { webhook_url, connector } = channel {
|
|
||||||
Some((webhook_url, connector))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let values = format!(
|
|
||||||
r#"
|
|
||||||
connectors:
|
|
||||||
- default: "{url}"
|
|
||||||
"#,
|
|
||||||
);
|
|
||||||
|
|
||||||
Some(HelmChartScore {
|
|
||||||
namespace: Some(NonBlankString::from_str(&config.namespace).unwrap()),
|
|
||||||
release_name: NonBlankString::from_str(&name).unwrap(),
|
|
||||||
chart_name: NonBlankString::from_str("oci://hub.nationtech.io/library/prometheus-msteams")
|
|
||||||
.unwrap(),
|
|
||||||
chart_version: None,
|
|
||||||
values_overrides: None,
|
|
||||||
values_yaml: Some(values.to_string()),
|
|
||||||
create_namespace: true,
|
|
||||||
install_only: true,
|
|
||||||
repository: None,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn prometheus_msteams_score(config: &KubePrometheusConfig) -> HelmChartScore {
|
|
||||||
if let Some(chart) = build_prometheus_msteams_score(config) {
|
|
||||||
chart
|
|
||||||
} else {
|
|
||||||
panic!("Expected discord alert manager helm chart");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user