use crate::events::base::BaseEvent;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum PostfixScriptOperation {
Starting,
Running { pid: Option<u32> },
Refreshing,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum PostfixScriptFatalError {
CannotExecutePostconf,
CannotExecuteCommand { command: String },
MissingPath { path: String },
Other { message: String },
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum PostfixScriptWarningType {
NotOwnedBy {
path: String,
expected_owner: String,
},
GroupWritable { path: String },
SymlinkLeaves { path: String },
Other { message: String },
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum PostfixScriptEvent {
SystemOperation {
base: BaseEvent,
operation: PostfixScriptOperation,
},
FatalError {
base: BaseEvent,
error: PostfixScriptFatalError,
},
Warning {
base: BaseEvent,
warning: PostfixScriptWarningType,
},
}
impl PostfixScriptEvent {
pub fn base(&self) -> &BaseEvent {
match self {
PostfixScriptEvent::SystemOperation { base, .. } => base,
PostfixScriptEvent::FatalError { base, .. } => base,
PostfixScriptEvent::Warning { base, .. } => base,
}
}
pub fn base_mut(&mut self) -> &mut BaseEvent {
match self {
PostfixScriptEvent::SystemOperation { base, .. } => base,
PostfixScriptEvent::FatalError { base, .. } => base,
PostfixScriptEvent::Warning { base, .. } => base,
}
}
pub fn event_type(&self) -> &'static str {
match self {
PostfixScriptEvent::SystemOperation { operation, .. } => match operation {
PostfixScriptOperation::Starting => "system_starting",
PostfixScriptOperation::Running { .. } => "system_running",
PostfixScriptOperation::Refreshing => "system_refreshing",
},
PostfixScriptEvent::FatalError { .. } => "fatal_error",
PostfixScriptEvent::Warning { .. } => "warning",
}
}
}