libomni/types/db/v1/
alert.rs

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