postfix_log_parser/events/
postfix_script.rs

1//! Postfix Script events
2//!
3//! This module defines the events for the postfix-script component,
4//! which is responsible for administrative commands and system management.
5
6use crate::events::base::BaseEvent;
7use serde::{Deserialize, Serialize};
8
9/// Postfix script system operation types
10#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11pub enum PostfixScriptOperation {
12    /// Starting the Postfix mail system
13    Starting,
14    /// System is running with PID
15    Running { pid: Option<u32> },
16    /// Refreshing the Postfix mail system  
17    Refreshing,
18}
19
20/// Postfix script fatal error types
21#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
22pub enum PostfixScriptFatalError {
23    /// Cannot execute postconf command
24    CannotExecutePostconf,
25    /// Cannot execute other command
26    CannotExecuteCommand { command: String },
27    /// Missing directory or file
28    MissingPath { path: String },
29    /// Other fatal errors
30    Other { message: String },
31}
32
33/// Postfix script warning types
34#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
35pub enum PostfixScriptWarningType {
36    /// File/directory not owned by expected user
37    NotOwnedBy {
38        path: String,
39        expected_owner: String,
40    },
41    /// Group or other writable permissions issue
42    GroupWritable { path: String },
43    /// Symlink leaves directory
44    SymlinkLeaves { path: String },
45    /// Other warning
46    Other { message: String },
47}
48
49/// Postfix script events
50#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
51pub enum PostfixScriptEvent {
52    /// System operation (start, run, refresh)
53    SystemOperation {
54        base: BaseEvent,
55        operation: PostfixScriptOperation,
56    },
57    /// Fatal error occurred
58    FatalError {
59        base: BaseEvent,
60        error: PostfixScriptFatalError,
61    },
62    /// Warning issued
63    Warning {
64        base: BaseEvent,
65        warning: PostfixScriptWarningType,
66    },
67}
68
69impl PostfixScriptEvent {
70    /// Get the base event
71    pub fn base(&self) -> &BaseEvent {
72        match self {
73            PostfixScriptEvent::SystemOperation { base, .. } => base,
74            PostfixScriptEvent::FatalError { base, .. } => base,
75            PostfixScriptEvent::Warning { base, .. } => base,
76        }
77    }
78
79    /// Get the base event mutably
80    pub fn base_mut(&mut self) -> &mut BaseEvent {
81        match self {
82            PostfixScriptEvent::SystemOperation { base, .. } => base,
83            PostfixScriptEvent::FatalError { base, .. } => base,
84            PostfixScriptEvent::Warning { base, .. } => base,
85        }
86    }
87
88    /// Get the event type string
89    pub fn event_type(&self) -> &'static str {
90        match self {
91            PostfixScriptEvent::SystemOperation { operation, .. } => match operation {
92                PostfixScriptOperation::Starting => "system_starting",
93                PostfixScriptOperation::Running { .. } => "system_running",
94                PostfixScriptOperation::Refreshing => "system_refreshing",
95            },
96            PostfixScriptEvent::FatalError { .. } => "fatal_error",
97            PostfixScriptEvent::Warning { .. } => "warning",
98        }
99    }
100}