omni_orchestrator/schemas/v1/models/
alert.rs

1use std::collections::HashMap;
2
3use rocket::serde::json::Json;
4use serde::{Deserialize, Serialize};
5use chrono::{DateTime, NaiveDateTime, Utc};
6use serde_json::Value;
7use sqlx::Row;
8
9// System Alerts
10#[derive(Debug, sqlx::FromRow, Serialize, Deserialize)]
11pub struct Alert {
12    pub id: i64,
13    pub alert_type: String,
14    pub severity: String,
15    pub service: String,
16    pub message: String,
17    pub timestamp: DateTime<Utc>,
18    pub status: String,
19    pub resolved_at: Option<DateTime<Utc>>,
20    pub resolved_by: Option<i64>,
21    pub metadata: Option<serde_json::Value>,
22    pub org_id: Option<i64>,
23    pub app_id: Option<i64>,
24    pub instance_id: Option<i64>,
25    pub region_id: Option<i64>,
26    pub node_id: Option<i64>,
27}
28
29// Alert Acknowledgments
30#[derive(Debug, sqlx::FromRow, Serialize, Deserialize)]
31pub struct AlertAcknowledgment {
32    pub id: i64,
33    pub alert_id: i64,
34    pub user_id: i64,
35    pub acknowledged_at: DateTime<Utc>,
36    pub notes: Option<String>,
37}
38
39// Alert Escalations
40#[derive(Debug, sqlx::FromRow, Serialize, Deserialize)]
41pub struct AlertEscalation {
42    pub id: i64,
43    pub alert_id: i64,
44    pub escalation_level: i64,
45    pub escalated_at: DateTime<Utc>,
46    pub escalated_to: serde_json::Value,
47    pub escalation_method: String,
48    pub response_required_by: Option<DateTime<Utc>>,
49}
50
51/// Represents an alert with all its related data (acknowledgments, escalations, and history).
52/// This comprehensive view is useful for detailed alert pages.
53#[derive(Debug, Serialize, Deserialize)]
54pub struct AlertWithRelatedData {
55    /// The core alert data
56    pub alert: Alert,
57    /// List of all acknowledgments for this alert
58    pub acknowledgments: Vec<AlertAcknowledgment>,
59    /// List of all escalations for this alert
60    pub escalations: Vec<AlertEscalation>,
61    /// History of all actions taken on this alert
62    pub history: Vec<AlertHistory>
63}
64
65/// Represents an alert with its acknowledgment information.
66/// This is useful for displaying alerts with their acknowledgment status.
67#[derive(Debug, Serialize, Deserialize)]
68pub struct AlertWithAcknowledgments {
69    /// The core alert data
70    pub alert: Alert,
71    /// List of acknowledgments for this alert
72    pub acknowledgments: Vec<AlertAcknowledgment>,
73    /// Whether the alert has been acknowledged
74    pub is_acknowledged: bool,
75    /// Total number of acknowledgments
76    pub acknowledgment_count: i64,
77    /// Timestamp of the most recent acknowledgment, if any
78    pub latest_acknowledgment: Option<chrono::DateTime<chrono::Utc>>,
79}
80
81// Alert History
82#[derive(Debug, sqlx::FromRow, Serialize, Deserialize)]
83pub struct AlertHistory {
84    pub id: i64,
85    pub alert_id: i64,
86    pub action: String,
87    pub performed_by: Option<i64>,
88    pub performed_at: DateTime<Utc>,
89    pub previous_state: Option<serde_json::Value>,
90    pub new_state: Option<serde_json::Value>,
91    pub notes: Option<String>,
92}