postfix_log_parser/components/
mod.rs

1//! 组件解析器模块
2//!
3//! 每个Postfix组件都有对应的解析器,负责解析该组件产生的日志
4
5use crate::error::ParseError;
6use crate::events::ComponentEvent;
7
8/// 组件解析器trait
9///
10/// 所有组件解析器都必须实现这个trait
11pub trait ComponentParser: Send + Sync {
12    /// 解析日志消息为组件事件
13    ///
14    /// # Arguments
15    ///
16    /// * `message` - 从基础日志格式中提取的消息部分
17    ///
18    /// # Returns
19    ///
20    /// 成功时返回对应的组件事件,失败时返回解析错误
21    fn parse(&self, message: &str) -> Result<ComponentEvent, ParseError>;
22
23    /// 获取组件名称
24    fn component_name(&self) -> &'static str;
25
26    /// 检查是否可以解析指定的消息
27    ///
28    /// 默认实现总是返回true,子类可以重写以提供更精确的检查
29    fn can_parse(&self, _message: &str) -> bool {
30        true
31    }
32}
33
34// 导出各个组件解析器模块
35pub mod anvil;
36pub mod bounce;
37pub mod cleanup;
38pub mod discard;
39pub mod error;
40pub mod local;
41pub mod master;
42pub mod pickup;
43pub mod postfix_script;
44pub mod postlogd;
45pub mod postmap;
46pub mod postsuper;
47pub mod proxymap;
48pub mod qmgr;
49pub mod relay;
50pub mod sendmail;
51pub mod smtp;
52pub mod smtpd;
53pub mod trivial_rewrite;
54pub mod virtual_parser;
55
56// 重新导出主要的解析器结构
57pub use bounce::BounceParser;
58pub use cleanup::CleanupParser;
59pub use error::ErrorParser;
60pub use local::LocalParser;
61pub use master::MasterParser;
62pub use postfix_script::PostfixScriptParser;
63pub use postmap::PostmapParser;
64pub use postsuper::PostsuperParser;
65pub use qmgr::QmgrParser;
66pub use relay::RelayParser;
67pub use smtp::SmtpParser;
68pub use smtpd::SmtpdParser;
69pub use virtual_parser::VirtualParser;