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

Function notify_insert

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

INSERT alert event into a history table via StatementExecutor.

(
    state: &SharedState,
    tenant_id: u64,
    owner: &str,
    table: &str,
    columns: &[String],
    event: &AlertEvent,
)

Source from the content-addressed store, hash-verified

177
178/// INSERT alert event into a history table via StatementExecutor.
179async fn notify_insert(
180 state: &SharedState,
181 tenant_id: u64,
182 owner: &str,
183 table: &str,
184 columns: &[String],
185 event: &AlertEvent,
186) {
187 // Build INSERT statement.
188 let col_list = if columns.is_empty() {
189 "alert_name, group_key, severity, status, value, threshold, timestamp_ms".to_string()
190 } else {
191 columns.join(", ")
192 };
193
194 let values = format!(
195 "'{}', '{}', '{}', '{}', {}, {}, {}",
196 escape_sql(&event.alert_name),
197 escape_sql(&event.group_key),
198 escape_sql(&event.severity),
199 escape_sql(&event.status),
200 event.value,
201 event.threshold,
202 event.timestamp_ms,
203 );
204
205 let sql = format!("BEGIN INSERT INTO {table} ({col_list}) VALUES ({values}); END");
206
207 let identity = alert_identity(TenantId::new(tenant_id), owner);
208 let block = match crate::control::planner::procedural::parse_block(&sql) {
209 Ok(b) => b,
210 Err(e) => {
211 warn!(
212 alert = event.alert_name,
213 table,
214 error = %e,
215 "failed to parse INSERT statement for alert history"
216 );
217 return;
218 }
219 };
220
221 let executor = StatementExecutor::new(state, identity, TenantId::new(tenant_id), 0);
222 let bindings = RowBindings::empty();
223
224 if let Err(e) = executor.execute_block(&block, &bindings).await {
225 warn!(
226 alert = event.alert_name,
227 table,
228 error = %e,
229 "failed to INSERT alert event into history table"
230 );
231 } else {
232 info!(
233 alert = event.alert_name,
234 table,
235 status = event.status,
236 "alert event inserted into history table"

Callers 1

dispatch_notificationsFunction · 0.85

Calls 7

alert_identityFunction · 0.85
parse_blockFunction · 0.85
to_stringMethod · 0.80
joinMethod · 0.80
execute_blockMethod · 0.80
emptyFunction · 0.50
is_emptyMethod · 0.45

Tested by

no test coverage detected