Skip to main content

max / makenotwork

2.5 KB · 88 lines History Blame Raw
1 //! dns alert/recovery messages. Domain half of the Alerter split;
2 //! shared dispatch/cooldown plumbing lives in the parent module.
3
4 use tracing::instrument;
5
6 use super::{AlertCategory, AlertMeta, Alerter};
7
8 impl Alerter {
9 #[instrument(skip_all)]
10 pub async fn send_dns_mismatch_alert(
11 &self,
12 target: &str,
13 label: &str,
14 mismatches: &[crate::types::DnsCheckResult],
15 ) {
16 let alert_key = format!("dns:{target}");
17 let n = mismatches.len();
18 let subject = format!("[PoM] {label}: {n} DNS record(s) mismatched");
19 let details: Vec<String> = mismatches
20 .iter()
21 .map(|m| {
22 if let Some(ref err) = m.error {
23 format!(" - {} {}: {err}", m.name, m.record_type)
24 } else {
25 format!(
26 " - {} {}: expected {:?}, got {:?}",
27 m.name, m.record_type, m.expected, m.actual
28 )
29 }
30 })
31 .collect();
32 let body = format!(
33 "Target: {label} ({target})\n\
34 DNS mismatches:\n{}\n\
35 Instance: {}\n\
36 Time: {}\n\n\
37 - PoM",
38 details.join("\n"),
39 self.instance_name,
40 chrono::Utc::now().to_rfc3339(),
41 );
42
43 self.fire_failure(
44 &subject,
45 &body,
46 "high",
47 "pom-dns",
48 Some(target),
49 AlertMeta {
50 key: &alert_key,
51 category: AlertCategory::DnsMismatch,
52 from: None,
53 to: None,
54 error: None,
55 },
56 )
57 .await;
58 }
59
60 #[instrument(skip_all)]
61 pub async fn send_dns_recovery_alert(&self, target: &str, label: &str) {
62 let alert_key = format!("dns:{target}");
63 let subject = format!("[PoM] {label}: DNS records recovered");
64 let body = format!(
65 "Target: {label} ({target})\n\
66 All DNS records now match expected values.\n\
67 Instance: {}\n\
68 Time: {}\n\n\
69 - PoM",
70 self.instance_name,
71 chrono::Utc::now().to_rfc3339(),
72 );
73
74 self.fire_recovery(
75 &subject,
76 &body,
77 AlertMeta {
78 key: &alert_key,
79 category: AlertCategory::DnsRecovery,
80 from: None,
81 to: None,
82 error: None,
83 },
84 )
85 .await;
86 }
87 }
88