postfix-log-parser 0.2.0

高性能模块化Postfix日志解析器,经3.2GB生产数据验证,SMTPD事件100%准确率
Documentation
//! 组件解析器模块
//!
//! 每个Postfix组件都有对应的解析器,负责解析该组件产生的日志

use crate::error::ParseError;
use crate::events::ComponentEvent;

/// 组件解析器trait
///
/// 所有组件解析器都必须实现这个trait
pub trait ComponentParser: Send + Sync {
    /// 解析日志消息为组件事件
    ///
    /// # Arguments
    ///
    /// * `message` - 从基础日志格式中提取的消息部分
    ///
    /// # Returns
    ///
    /// 成功时返回对应的组件事件,失败时返回解析错误
    fn parse(&self, message: &str) -> Result<ComponentEvent, ParseError>;

    /// 获取组件名称
    fn component_name(&self) -> &'static str;

    /// 检查是否可以解析指定的消息
    ///
    /// 默认实现总是返回true,子类可以重写以提供更精确的检查
    fn can_parse(&self, _message: &str) -> bool {
        true
    }
}

// 导出各个组件解析器模块
pub mod anvil;
pub mod bounce;
pub mod cleanup;
pub mod discard;
pub mod error;
pub mod local;
pub mod master;
pub mod pickup;
pub mod postfix_script;
pub mod postlogd;
pub mod postmap;
pub mod postsuper;
pub mod proxymap;
pub mod qmgr;
pub mod relay;
pub mod sendmail;
pub mod smtp;
pub mod smtpd;
pub mod trivial_rewrite;
pub mod virtual_parser;

// 重新导出主要的解析器结构
pub use bounce::BounceParser;
pub use cleanup::CleanupParser;
pub use error::ErrorParser;
pub use local::LocalParser;
pub use master::MasterParser;
pub use postfix_script::PostfixScriptParser;
pub use postmap::PostmapParser;
pub use postsuper::PostsuperParser;
pub use qmgr::QmgrParser;
pub use relay::RelayParser;
pub use smtp::SmtpParser;
pub use smtpd::SmtpdParser;
pub use virtual_parser::VirtualParser;