use coraza_sys::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Severity {
Unknown,
Debug,
Info,
Notice,
Warning,
Error,
Critical,
Alert,
Emergency,
}
impl From<coraza_severity_t> for Severity {
fn from(val: coraza_severity_t) -> Self {
match val {
coraza_severity_t_CORAZA_SEVERITY_DEBUG => Severity::Debug,
coraza_severity_t_CORAZA_SEVERITY_INFO => Severity::Info,
coraza_severity_t_CORAZA_SEVERITY_NOTICE => Severity::Notice,
coraza_severity_t_CORAZA_SEVERITY_WARNING => Severity::Warning,
coraza_severity_t_CORAZA_SEVERITY_ERROR => Severity::Error,
coraza_severity_t_CORAZA_SEVERITY_CRITICAL => Severity::Critical,
coraza_severity_t_CORAZA_SEVERITY_ALERT => Severity::Alert,
coraza_severity_t_CORAZA_SEVERITY_EMERGENCY => Severity::Emergency,
_ => Severity::Unknown,
}
}
}
impl std::fmt::Display for Severity {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Severity::Unknown => write!(f, "UNKNOWN"),
Severity::Debug => write!(f, "DEBUG"),
Severity::Info => write!(f, "INFO"),
Severity::Notice => write!(f, "NOTICE"),
Severity::Warning => write!(f, "WARNING"),
Severity::Error => write!(f, "ERROR"),
Severity::Critical => write!(f, "CRITICAL"),
Severity::Alert => write!(f, "ALERT"),
Severity::Emergency => write!(f, "EMERGENCY"),
}
}
}
#[derive(Debug, Clone)]
pub struct MatchedRule {
pub message: String,
pub severity: Severity,
pub rule_id: i32,
pub uri: String,
pub client_ip: String,
pub server_ip: String,
pub disruptive: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum LogLevel {
Unknown,
Trace,
Debug,
Info,
Warn,
Error,
}
impl From<coraza_debug_log_level_t> for LogLevel {
fn from(val: coraza_debug_log_level_t) -> Self {
match val {
coraza_debug_log_level_t_CORAZA_DEBUG_LOG_LEVEL_TRACE => LogLevel::Trace,
coraza_debug_log_level_t_CORAZA_DEBUG_LOG_LEVEL_DEBUG => LogLevel::Debug,
coraza_debug_log_level_t_CORAZA_DEBUG_LOG_LEVEL_INFO => LogLevel::Info,
coraza_debug_log_level_t_CORAZA_DEBUG_LOG_LEVEL_WARN => LogLevel::Warn,
coraza_debug_log_level_t_CORAZA_DEBUG_LOG_LEVEL_ERROR => LogLevel::Error,
_ => LogLevel::Unknown,
}
}
}
impl std::fmt::Display for LogLevel {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
LogLevel::Unknown => write!(f, "UNKNOWN"),
LogLevel::Trace => write!(f, "TRACE"),
LogLevel::Debug => write!(f, "DEBUG"),
LogLevel::Info => write!(f, "INFO"),
LogLevel::Warn => write!(f, "WARN"),
LogLevel::Error => write!(f, "ERROR"),
}
}
}