Dispatch notifications for an alert transition. Sends to all configured targets (TOPIC, WEBHOOK, INSERT INTO). Errors are logged but do not prevent other targets from being notified.
(
state: &Arc<SharedState>,
alert: &AlertDef,
group_key: &str,
value: f64,
transition: HysteresisTransition,
now_ms: u64,
)
| 24 | /// Sends to all configured targets (TOPIC, WEBHOOK, INSERT INTO). |
| 25 | /// Errors are logged but do not prevent other targets from being notified. |
| 26 | pub async fn dispatch_notifications( |
| 27 | state: &Arc<SharedState>, |
| 28 | alert: &AlertDef, |
| 29 | group_key: &str, |
| 30 | value: f64, |
| 31 | transition: HysteresisTransition, |
| 32 | now_ms: u64, |
| 33 | ) { |
| 34 | let status_str = match transition { |
| 35 | HysteresisTransition::Fired => "ACTIVE", |
| 36 | HysteresisTransition::Recovered => "CLEARED", |
| 37 | HysteresisTransition::NoChange => return, // No notification needed. |
| 38 | }; |
| 39 | |
| 40 | let event = AlertEvent { |
| 41 | alert_name: alert.name.clone(), |
| 42 | group_key: group_key.to_string(), |
| 43 | severity: alert.severity.clone(), |
| 44 | status: status_str.to_string(), |
| 45 | value, |
| 46 | threshold: alert.condition.threshold, |
| 47 | timestamp_ms: now_ms, |
| 48 | collection: alert.collection.clone(), |
| 49 | }; |
| 50 | |
| 51 | for target in &alert.notify_targets { |
| 52 | match target { |
| 53 | NotifyTarget::Topic { name } => { |
| 54 | notify_topic(state, alert.tenant_id, name, &event); |
| 55 | } |
| 56 | NotifyTarget::Webhook { url } => { |
| 57 | let timeout = Duration::from_secs(state.tuning.scheduler.webhook_timeout_secs); |
| 58 | notify_webhook_with_client(state.http_client(), url, &event, timeout).await; |
| 59 | } |
| 60 | NotifyTarget::InsertInto { table, columns } => { |
| 61 | notify_insert(state, alert.tenant_id, &alert.owner, table, columns, &event).await; |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /// Publish alert event to a CDC topic. |
| 68 | fn notify_topic(state: &SharedState, tenant_id: u64, topic_name: &str, event: &AlertEvent) { |
no test coverage detected