postfix_log_parser/formatters/json/
cleanup.rs1use crate::events::cleanup::CleanupEvent;
2use serde_json::{json, Value};
3
4pub fn format_cleanup_event(event: &CleanupEvent) -> Value {
7 match event {
8 CleanupEvent::MessageId {
9 queue_id,
10 message_id,
11 } => {
12 json!({
13 "event_type": "message_id",
14 "queue_id": queue_id,
15 "message_id": message_id,
16 "description": "邮件Message-ID处理"
17 })
18 }
19
20 CleanupEvent::QueueFileWarning {
21 operation,
22 file_path,
23 error_reason,
24 } => {
25 json!({
26 "event_type": "queue_file_warning",
27 "operation": operation,
28 "file_path": file_path,
29 "error_reason": error_reason,
30 "severity": "warning",
31 "description": "队列文件操作警告"
32 })
33 }
34
35 CleanupEvent::MessageSize { queue_id, size } => {
36 json!({
37 "event_type": "message_size",
38 "queue_id": queue_id,
39 "size": size,
40 "size_mb": *size as f64 / 1024.0 / 1024.0,
41 "description": "邮件大小信息"
42 })
43 }
44
45 CleanupEvent::HeaderProcessing {
46 queue_id,
47 header_name,
48 header_value,
49 action,
50 } => {
51 json!({
52 "event_type": "header_processing",
53 "queue_id": queue_id,
54 "header_name": header_name,
55 "header_value": header_value,
56 "action": action,
57 "description": "邮件头处理"
58 })
59 }
60
61 CleanupEvent::FilterAction {
62 queue_id,
63 filter_name,
64 action,
65 details,
66 } => {
67 json!({
68 "event_type": "filter_action",
69 "queue_id": queue_id,
70 "filter_name": filter_name,
71 "action": action,
72 "details": details,
73 "description": "邮件过滤器处理"
74 })
75 }
76
77 CleanupEvent::AddressRewrite {
78 queue_id,
79 address_type,
80 original_address,
81 rewritten_address,
82 } => {
83 json!({
84 "event_type": "address_rewrite",
85 "queue_id": queue_id,
86 "address_type": address_type,
87 "original_address": original_address,
88 "rewritten_address": rewritten_address,
89 "description": "地址重写"
90 })
91 }
92
93 CleanupEvent::MessageRewrite {
94 queue_id,
95 rewrite_type,
96 original,
97 rewritten,
98 } => {
99 json!({
100 "event_type": "message_rewrite",
101 "queue_id": queue_id,
102 "rewrite_type": rewrite_type,
103 "original": original,
104 "rewritten": rewritten,
105 "description": "邮件内容重写"
106 })
107 }
108
109 CleanupEvent::MessageReject {
110 queue_id,
111 reason,
112 action,
113 } => {
114 json!({
115 "event_type": "message_reject",
116 "queue_id": queue_id,
117 "reason": reason,
118 "action": action,
119 "severity": "error",
120 "description": "邮件拒绝"
121 })
122 }
123
124 CleanupEvent::ResourceLimit {
125 resource_type,
126 limit_details,
127 current_value,
128 limit_value,
129 } => {
130 json!({
131 "event_type": "resource_limit",
132 "resource_type": resource_type,
133 "limit_details": limit_details,
134 "current_value": current_value,
135 "limit_value": limit_value,
136 "severity": "warning",
137 "description": "资源限制警告"
138 })
139 }
140
141 CleanupEvent::MilterInteraction {
142 queue_id,
143 milter_name,
144 command,
145 response,
146 } => {
147 json!({
148 "event_type": "milter_interaction",
149 "queue_id": queue_id,
150 "milter_name": milter_name,
151 "command": command,
152 "response": response,
153 "description": "Milter交互"
154 })
155 }
156
157 CleanupEvent::ConfigurationWarning {
158 warning_type,
159 message,
160 } => {
161 json!({
162 "event_type": "configuration_warning",
163 "warning_type": warning_type,
164 "message": message,
165 "severity": "warning",
166 "description": "配置警告"
167 })
168 }
169
170 CleanupEvent::Statistics {
171 processed,
172 rejected,
173 errors,
174 } => {
175 json!({
176 "event_type": "statistics",
177 "processed": processed,
178 "rejected": rejected,
179 "errors": errors,
180 "description": "Cleanup处理统计"
181 })
182 }
183
184 CleanupEvent::SnowflakeInit {
185 node_id,
186 node_bits,
187 seq_bits,
188 } => {
189 json!({
190 "event_type": "snowflake_init",
191 "node_id": node_id,
192 "node_bits": node_bits,
193 "seq_bits": seq_bits,
194 "description": "Snowflake ID生成器初始化"
195 })
196 }
197
198 CleanupEvent::MessageHold {
199 queue_id,
200 hold_reason,
201 sender,
202 recipient,
203 client_ip,
204 client_hostname,
205 client_port,
206 protocol,
207 helo,
208 description,
209 } => {
210 json!({
211 "event_type": "message_hold",
212 "queue_id": queue_id,
213 "hold_reason": hold_reason,
214 "sender": sender,
215 "recipient": recipient,
216 "client_ip": client_ip,
217 "client_hostname": client_hostname,
218 "client_port": client_port,
219 "protocol": protocol,
220 "helo": helo,
221 "description": description,
222 "severity": "warning"
223 })
224 }
225
226 CleanupEvent::MessageDiscard {
227 queue_id,
228 discard_reason,
229 sender,
230 recipient,
231 client_ip,
232 client_hostname,
233 client_port,
234 protocol,
235 helo,
236 description,
237 } => {
238 json!({
239 "event_type": "discarded",
240 "queue_id": queue_id,
241 "discard_reason": discard_reason,
242 "sender": sender,
243 "recipient": recipient,
244 "client_ip": client_ip,
245 "client_hostname": client_hostname,
246 "client_port": client_port,
247 "protocol": protocol,
248 "helo": helo,
249 "description": description,
250 "severity": "info"
251 })
252 }
253
254 CleanupEvent::MessageRemoved {
255 queue_id,
256 removal_reason,
257 details,
258 } => {
259 json!({
260 "event_type": "message_removed",
261 "queue_id": queue_id,
262 "removal_reason": removal_reason,
263 "details": details,
264 "description": "邮件从队列中移除"
265 })
266 }
267
268 CleanupEvent::Other {
269 event_type,
270 message,
271 queue_id,
272 } => {
273 json!({
274 "event_type": "other",
275 "sub_type": event_type,
276 "message": message,
277 "queue_id": queue_id,
278 "description": "其他Cleanup事件"
279 })
280 }
281 }
282}