//! dns alert/recovery messages. Domain half of the Alerter split; //! shared dispatch/cooldown plumbing lives in the parent module. use tracing::instrument; use super::{AlertCategory, AlertMeta, Alerter}; impl Alerter { #[instrument(skip_all)] pub async fn send_dns_mismatch_alert( &self, target: &str, label: &str, mismatches: &[crate::types::DnsCheckResult], ) { let alert_key = format!("dns:{target}"); let n = mismatches.len(); let subject = format!("[PoM] {label}: {n} DNS record(s) mismatched"); let details: Vec = mismatches .iter() .map(|m| { if let Some(ref err) = m.error { format!(" - {} {}: {err}", m.name, m.record_type) } else { format!( " - {} {}: expected {:?}, got {:?}", m.name, m.record_type, m.expected, m.actual ) } }) .collect(); let body = format!( "Target: {label} ({target})\n\ DNS mismatches:\n{}\n\ Instance: {}\n\ Time: {}\n\n\ - PoM", details.join("\n"), self.instance_name, chrono::Utc::now().to_rfc3339(), ); self.fire_failure( &subject, &body, "high", "pom-dns", Some(target), AlertMeta { key: &alert_key, category: AlertCategory::DnsMismatch, from: None, to: None, error: None, }, ) .await; } #[instrument(skip_all)] pub async fn send_dns_recovery_alert(&self, target: &str, label: &str) { let alert_key = format!("dns:{target}"); let subject = format!("[PoM] {label}: DNS records recovered"); let body = format!( "Target: {label} ({target})\n\ All DNS records now match expected values.\n\ Instance: {}\n\ Time: {}\n\n\ - PoM", self.instance_name, chrono::Utc::now().to_rfc3339(), ); self.fire_recovery( &subject, &body, AlertMeta { key: &alert_key, category: AlertCategory::DnsRecovery, from: None, to: None, error: None, }, ) .await; } }