llm_sentinel_alerting/
lib.rs1#![warn(missing_debug_implementations, rust_2018_idioms, unreachable_pub)]
13
14pub mod deduplication;
15pub mod rabbitmq;
16pub mod webhook;
17
18use async_trait::async_trait;
19use llm_sentinel_core::{events::AnomalyEvent, Result};
20use serde::{Deserialize, Serialize};
21
22#[async_trait]
24pub trait Alerter: Send + Sync {
25 async fn send(&self, alert: &AnomalyEvent) -> Result<()>;
27
28 async fn send_batch(&self, alerts: &[AnomalyEvent]) -> Result<()> {
30 for alert in alerts {
31 self.send(alert).await?;
32 }
33 Ok(())
34 }
35
36 async fn health_check(&self) -> Result<()>;
38
39 fn name(&self) -> &str;
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct AlertMetadata {
46 pub alert_id: String,
48 pub attempts: u32,
50 pub last_attempt: chrono::DateTime<chrono::Utc>,
52 pub status: AlertStatus,
54}
55
56#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
58pub enum AlertStatus {
59 Pending,
61 Delivered,
63 Failed,
65 Deduplicated,
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
71pub struct AlertConfig {
72 pub enable_deduplication: bool,
74 pub deduplication_window_secs: u64,
76 pub max_retries: u32,
78 pub retry_delay_ms: u64,
80 pub backoff_multiplier: f64,
82}
83
84impl Default for AlertConfig {
85 fn default() -> Self {
86 Self {
87 enable_deduplication: true,
88 deduplication_window_secs: 300, max_retries: 3,
90 retry_delay_ms: 1000,
91 backoff_multiplier: 2.0,
92 }
93 }
94}
95
96pub mod prelude {
98 pub use crate::deduplication::{AlertDeduplicator, DeduplicationConfig};
99 pub use crate::rabbitmq::{RabbitMqAlerter, RabbitMqConfig};
100 pub use crate::webhook::{WebhookAlerter, WebhookConfig};
101 pub use crate::{AlertConfig, AlertStatus, Alerter};
102}