MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / dispatch_notifications

Function dispatch_notifications

nodedb/src/event/alert/notify.rs:26–65  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

24/// Sends to all configured targets (TOPIC, WEBHOOK, INSERT INTO).
25/// Errors are logged but do not prevent other targets from being notified.
26pub 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.
68fn notify_topic(state: &SharedState, tenant_id: u64, topic_name: &str, event: &AlertEvent) {

Callers 1

evaluate_alertFunction · 0.85

Calls 6

notify_topicFunction · 0.85
notify_insertFunction · 0.85
to_stringMethod · 0.80
http_clientMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected