use serde::{Deserialize, Serialize};
pub mod rules;
pub mod instance;
pub mod channels;
pub mod silence;
pub mod history;
pub mod grouping;
pub mod evaluator;
pub mod manager;
#[cfg(test)]
mod tests;
pub use rules::{
AggregationFunction, AlertRuleDefinition, ConditionExpression, ThresholdOperator,
};
pub use instance::AlertInstance;
pub use channels::{NotificationChannel, NotificationSender};
pub use silence::{SilenceMatcher, SilenceManager, SilenceRule};
pub use history::{AlertHistory, AlertHistoryEvent, AlertHistoryEventType};
pub use grouping::{AlertGroup, AlertGrouper};
pub use evaluator::{ConditionEvaluator, MetricDataPoint, MetricProvider};
pub use manager::AlertEngine;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub enum AlertLevel {
Info = 0,
Warning = 1,
Error = 2,
Critical = 3,
Page = 4,
}
impl AlertLevel {
#[must_use]
pub const fn as_str(&self) -> &'static str {
match self {
Self::Info => "info",
Self::Warning => "warning",
Self::Error => "error",
Self::Critical => "critical",
Self::Page => "page",
}
}
pub fn from_str(s: &str) -> Option<Self> {
match s.to_lowercase().as_str() {
"info" | "informational" => Some(Self::Info),
"warning" | "warn" => Some(Self::Warning),
"error" | "err" => Some(Self::Error),
"critical" | "crit" => Some(Self::Critical),
"page" | "pager" => Some(Self::Page),
_ => None,
}
}
}
impl Default for AlertLevel {
fn default() -> Self {
Self::Warning
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum AlertState {
Inactive,
Pending,
Firing,
Resolved,
Silenced,
Acknowledged,
}
impl AlertState {
#[must_use]
pub const fn is_active(&self) -> bool {
matches!(self, Self::Pending | Self::Firing)
}
#[must_use]
pub const fn requires_attention(&self) -> bool {
matches!(self, Self::Firing)
}
}