postfix-log-parser 0.2.0

高性能模块化Postfix日志解析器,经3.2GB生产数据验证,SMTPD事件100%准确率
Documentation
//! Master daemon events
//!
//! This module defines the events for the master component,
//! which is responsible for process management and daemon control.

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

/// Master daemon event types
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum MasterEvent {
    /// Daemon lifecycle management
    DaemonLifecycle {
        base: BaseEvent,
        lifecycle: MasterLifecycleEvent,
    },
    /// Process management warnings
    ProcessWarning {
        base: BaseEvent,
        warning: MasterProcessWarning,
    },
    /// Service limit warnings  
    ServiceLimit {
        base: BaseEvent,
        limit: MasterServiceLimit,
    },
    /// Configuration and stress warnings
    ConfigurationWarning {
        base: BaseEvent,
        warning: MasterConfigWarning,
    },
}

/// Master daemon lifecycle events
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum MasterLifecycleEvent {
    /// Daemon started with version info
    Started {
        version: String,
        configuration: String,
    },
    /// Configuration reload
    Reload {
        version: String,
        configuration: String,
    },
}

/// Process management warnings
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum MasterProcessWarning {
    /// Process killed by signal
    ProcessKilled {
        service: String,
        process_path: String,
        pid: u32,
        signal: u8,
    },
    /// Bad command startup (throttling)
    BadCommandStartup { service: String },
}

/// Service limit warnings
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum MasterServiceLimit {
    /// Service has reached process limit
    ProcessLimitReached {
        service: String,
        service_address: String,
        limit: u32,
    },
}

/// Configuration and stress warnings
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum MasterConfigWarning {
    /// Process count or service time suggestion
    ProcessCountSuggestion,
    /// Stress configuration reference
    StressConfigReference { url: String },
}

impl MasterEvent {
    /// Get the base event
    pub fn base(&self) -> &BaseEvent {
        match self {
            MasterEvent::DaemonLifecycle { base, .. } => base,
            MasterEvent::ProcessWarning { base, .. } => base,
            MasterEvent::ServiceLimit { base, .. } => base,
            MasterEvent::ConfigurationWarning { base, .. } => base,
        }
    }

    /// Get the base event mutably
    pub fn base_mut(&mut self) -> &mut BaseEvent {
        match self {
            MasterEvent::DaemonLifecycle { base, .. } => base,
            MasterEvent::ProcessWarning { base, .. } => base,
            MasterEvent::ServiceLimit { base, .. } => base,
            MasterEvent::ConfigurationWarning { base, .. } => base,
        }
    }

    /// Get the event type string
    pub fn event_type(&self) -> &'static str {
        match self {
            MasterEvent::DaemonLifecycle { lifecycle, .. } => match lifecycle {
                MasterLifecycleEvent::Started { .. } => "daemon_started",
                MasterLifecycleEvent::Reload { .. } => "daemon_reload",
            },
            MasterEvent::ProcessWarning { warning, .. } => match warning {
                MasterProcessWarning::ProcessKilled { .. } => "process_killed",
                MasterProcessWarning::BadCommandStartup { .. } => "bad_command_startup",
            },
            MasterEvent::ServiceLimit { .. } => "service_limit_reached",
            MasterEvent::ConfigurationWarning { warning, .. } => match warning {
                MasterConfigWarning::ProcessCountSuggestion => "process_count_suggestion",
                MasterConfigWarning::StressConfigReference { .. } => "stress_config_reference",
            },
        }
    }
}