Function create_alert

Source
pub async fn create_alert(
    pool: &Pool<MySql>,
    alert_type: &str,
    severity: &str,
    service: &str,
    message: &str,
    metadata: Option<Value>,
    org_id: Option<i64>,
    app_id: Option<i64>,
    instance_id: Option<i64>,
    region_id: Option<i64>,
    node_id: Option<i64>,
) -> Result<Alert>
Expand description

Creates a new alert in the database.

This function inserts a new alert record with the provided parameters and adds an initial history record to document the alert creation.

§Arguments

  • pool - Database connection pool for executing the query
  • alert_type - Type of alert (e.g., “cpu_usage”, “memory_usage”, “disk_space”)
  • severity - Severity level of the alert (critical, warning, info)
  • service - Name of the service that generated the alert
  • message - Alert message text describing the issue
  • metadata - Optional JSON data with additional alert details
  • org_id - Optional organization ID related to the alert
  • app_id - Optional application ID related to the alert
  • instance_id - Optional instance ID related to the alert
  • region_id - Optional region ID related to the alert
  • node_id - Optional node/worker ID related to the alert

§Returns

  • Ok(Alert) - Successfully created alert, including database-assigned fields
  • Err(anyhow::Error) - Failed to create alert