format message with labels

This commit is contained in:
Astro 2022-12-17 00:26:30 +01:00
parent b416009f7c
commit 3dc05fb224
1 changed files with 6 additions and 2 deletions

View File

@ -20,7 +20,7 @@ struct Alert {
generatorURL: String, generatorURL: String,
startsAt: String, startsAt: String,
annotations: AlertAnnotations, annotations: AlertAnnotations,
// labels: HashMap<String, String>, labels: HashMap<String, String>,
} }
#[derive(Deserialize, Clone, Debug)] #[derive(Deserialize, Clone, Debug)]
@ -51,7 +51,11 @@ async fn alerts(
if message != "" { if message != "" {
message += "\n"; message += "\n";
} }
message += &format!("{}: {}", alert.annotations.summary, alert.generatorURL); let title = match (alert.labels.get("alertname"), alert.labels.get("instance")) {
(Some(name), Some(instance)) => format!("{}@{}", name, instance),
_ => alert.annotations.summary.clone(),
};
message += &format!("{}: {}", title, alert.generatorURL);
alerts.insert(alert.generatorURL.clone(), alert); alerts.insert(alert.generatorURL.clone(), alert);
} }
} }