postfix-log-parser 0.2.0

高性能模块化Postfix日志解析器,经3.2GB生产数据验证,SMTPD事件100%准确率
Documentation
//! Postfix Script events
//!
//! This module defines the events for the postfix-script component,
//! which is responsible for administrative commands and system management.

use crate::events::base::BaseEvent;
use serde::{Deserialize, Serialize};

/// Postfix script system operation types
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum PostfixScriptOperation {
    /// Starting the Postfix mail system
    Starting,
    /// System is running with PID
    Running { pid: Option<u32> },
    /// Refreshing the Postfix mail system  
    Refreshing,
}

/// Postfix script fatal error types
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum PostfixScriptFatalError {
    /// Cannot execute postconf command
    CannotExecutePostconf,
    /// Cannot execute other command
    CannotExecuteCommand { command: String },
    /// Missing directory or file
    MissingPath { path: String },
    /// Other fatal errors
    Other { message: String },
}

/// Postfix script warning types
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum PostfixScriptWarningType {
    /// File/directory not owned by expected user
    NotOwnedBy {
        path: String,
        expected_owner: String,
    },
    /// Group or other writable permissions issue
    GroupWritable { path: String },
    /// Symlink leaves directory
    SymlinkLeaves { path: String },
    /// Other warning
    Other { message: String },
}

/// Postfix script events
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum PostfixScriptEvent {
    /// System operation (start, run, refresh)
    SystemOperation {
        base: BaseEvent,
        operation: PostfixScriptOperation,
    },
    /// Fatal error occurred
    FatalError {
        base: BaseEvent,
        error: PostfixScriptFatalError,
    },
    /// Warning issued
    Warning {
        base: BaseEvent,
        warning: PostfixScriptWarningType,
    },
}

impl PostfixScriptEvent {
    /// Get the base event
    pub fn base(&self) -> &BaseEvent {
        match self {
            PostfixScriptEvent::SystemOperation { base, .. } => base,
            PostfixScriptEvent::FatalError { base, .. } => base,
            PostfixScriptEvent::Warning { base, .. } => base,
        }
    }

    /// Get the base event mutably
    pub fn base_mut(&mut self) -> &mut BaseEvent {
        match self {
            PostfixScriptEvent::SystemOperation { base, .. } => base,
            PostfixScriptEvent::FatalError { base, .. } => base,
            PostfixScriptEvent::Warning { base, .. } => base,
        }
    }

    /// Get the event type string
    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",
        }
    }
}