Skip to main content

max / makenotwork

2.6 KB · 89 lines History Blame Raw
1 //! cors 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_cors_failure_alert(
11 &self,
12 target: &str,
13 label: &str,
14 failures: &[crate::types::CorsCheckResult],
15 ) {
16 let alert_key = format!("cors:{target}");
17 let n = failures.len();
18 let subject = format!("[PoM] {label}: {n} CORS preflight(s) failing");
19 let details: Vec<String> = failures
20 .iter()
21 .map(|f| {
22 if let Some(ref err) = f.error {
23 format!(" - {} {} from {}: {err}", f.method, f.url, f.origin)
24 } else {
25 format!(
26 " - {} {} from {}: no CORS headers",
27 f.method, f.url, f.origin
28 )
29 }
30 })
31 .collect();
32 let body = format!(
33 "Target: {label} ({target})\n\
34 CORS preflight failures:\n{}\n\
35 Instance: {}\n\
36 Time: {}\n\n\
37 Browser-side uploads will silently fail without CORS.\n\n\
38 - PoM",
39 details.join("\n"),
40 self.instance_name,
41 chrono::Utc::now().to_rfc3339(),
42 );
43
44 self.fire_failure(
45 &subject,
46 &body,
47 "high",
48 "pom-cors",
49 Some(target),
50 AlertMeta {
51 key: &alert_key,
52 category: AlertCategory::CorsFailure,
53 from: None,
54 to: None,
55 error: None,
56 },
57 )
58 .await;
59 }
60
61 #[instrument(skip_all)]
62 pub async fn send_cors_recovery_alert(&self, target: &str, label: &str) {
63 let alert_key = format!("cors:{target}");
64 let subject = format!("[PoM] {label}: CORS preflights recovered");
65 let body = format!(
66 "Target: {label} ({target})\n\
67 All CORS preflight checks passing.\n\
68 Instance: {}\n\
69 Time: {}\n\n\
70 - PoM",
71 self.instance_name,
72 chrono::Utc::now().to_rfc3339(),
73 );
74
75 self.fire_recovery(
76 &subject,
77 &body,
78 AlertMeta {
79 key: &alert_key,
80 category: AlertCategory::CorsRecovery,
81 from: None,
82 to: None,
83 error: None,
84 },
85 )
86 .await;
87 }
88 }
89