use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Severity {
Info,
Warning,
Critical,
}
impl Severity {
pub fn as_str(self) -> &'static str {
match self {
Severity::Info => "info",
Severity::Warning => "warning",
Severity::Critical => "critical",
}
}
}
impl std::str::FromStr for Severity {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"info" => Ok(Severity::Info),
"warning" => Ok(Severity::Warning),
"critical" => Ok(Severity::Critical),
other => Err(format!("unknown severity `{other}`")),
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct Alert {
pub ts: i64,
pub mac: Option<String>,
pub severity: Severity,
pub kind: String,
pub message: String,
}
impl Alert {
pub fn new(
ts: i64,
mac: Option<String>,
severity: Severity,
kind: impl Into<String>,
message: impl Into<String>,
) -> Self {
Self {
ts,
mac,
severity,
kind: kind.into(),
message: message.into(),
}
}
}