postfix_log_parser/events/
cleanup.rs1use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
11pub enum CleanupEvent {
12 MessageId {
14 queue_id: String,
15 message_id: String,
16 },
17
18 QueueFileWarning {
20 operation: String, file_path: String, error_reason: String, },
24
25 MessageRewrite {
28 queue_id: String,
29 rewrite_type: String, original: String, rewritten: String, },
33
34 MessageSize {
37 queue_id: String,
38 size: u64, },
40
41 HeaderProcessing {
44 queue_id: String,
45 header_name: String, header_value: String, action: String, },
49
50 FilterAction {
53 queue_id: String,
54 filter_name: String, action: String, details: Option<String>, },
58
59 AddressRewrite {
62 queue_id: String,
63 address_type: String, original_address: String,
65 rewritten_address: String,
66 },
67
68 MessageReject {
71 queue_id: String,
72 reason: String, action: String, },
75
76 ResourceLimit {
79 resource_type: String, limit_details: String, current_value: Option<u64>,
82 limit_value: Option<u64>,
83 },
84
85 MilterInteraction {
88 queue_id: String,
89 milter_name: String, command: String, response: Option<String>, },
93
94 ConfigurationWarning {
97 warning_type: String, message: String, },
100
101 Statistics {
104 processed: Option<u32>, rejected: Option<u32>, errors: Option<u32>, },
108
109 SnowflakeInit {
112 node_id: u32, node_bits: u32, seq_bits: u32, },
116
117 MessageHold {
120 queue_id: String,
121 hold_reason: String, sender: Option<String>, recipient: Option<String>, client_ip: Option<String>, client_hostname: Option<String>, client_port: Option<u16>, protocol: Option<String>, helo: Option<String>, description: String, },
131
132 MessageDiscard {
135 queue_id: String,
136 discard_reason: String, sender: Option<String>, recipient: Option<String>, client_ip: Option<String>, client_hostname: Option<String>, client_port: Option<u16>, protocol: Option<String>, helo: Option<String>, description: String, },
146
147 MessageRemoved {
150 queue_id: String,
151 removal_reason: String, details: Option<String>, },
154
155 Other {
158 event_type: String,
159 message: String,
160 queue_id: Option<String>,
161 },
162}
163
164impl CleanupEvent {
165 pub fn event_type(&self) -> &'static str {
166 match self {
167 CleanupEvent::MessageId { .. } => "message_id",
168 CleanupEvent::QueueFileWarning { .. } => "queue_file_warning",
169 CleanupEvent::MessageRewrite { .. } => "message_rewrite",
170 CleanupEvent::MessageSize { .. } => "message_size",
171 CleanupEvent::HeaderProcessing { .. } => "header_processing",
172 CleanupEvent::FilterAction { .. } => "filter_action",
173 CleanupEvent::AddressRewrite { .. } => "address_rewrite",
174 CleanupEvent::MessageReject { .. } => "message_reject",
175 CleanupEvent::ResourceLimit { .. } => "resource_limit",
176 CleanupEvent::MilterInteraction { .. } => "milter_interaction",
177 CleanupEvent::ConfigurationWarning { .. } => "configuration_warning",
178 CleanupEvent::Statistics { .. } => "statistics",
179 CleanupEvent::SnowflakeInit { .. } => "snowflake_init",
180 CleanupEvent::MessageHold { .. } => "message_hold",
181 CleanupEvent::MessageDiscard { .. } => "message_discard",
182 CleanupEvent::MessageRemoved { .. } => "message_removed",
183 CleanupEvent::Other { .. } => "other",
184 }
185 }
186
187 pub fn queue_id(&self) -> Option<&str> {
189 match self {
190 CleanupEvent::MessageId { queue_id, .. } => Some(queue_id),
191 CleanupEvent::MessageRewrite { queue_id, .. } => Some(queue_id),
192 CleanupEvent::MessageSize { queue_id, .. } => Some(queue_id),
193 CleanupEvent::HeaderProcessing { queue_id, .. } => Some(queue_id),
194 CleanupEvent::FilterAction { queue_id, .. } => Some(queue_id),
195 CleanupEvent::AddressRewrite { queue_id, .. } => Some(queue_id),
196 CleanupEvent::MessageReject { queue_id, .. } => Some(queue_id),
197 CleanupEvent::MilterInteraction { queue_id, .. } => Some(queue_id),
198 CleanupEvent::MessageHold { queue_id, .. } => Some(queue_id),
199 CleanupEvent::MessageDiscard { queue_id, .. } => Some(queue_id),
200 CleanupEvent::MessageRemoved { queue_id, .. } => Some(queue_id),
201 CleanupEvent::Other { queue_id, .. } => queue_id.as_deref(),
202 _ => None,
203 }
204 }
205
206 pub fn is_error_event(&self) -> bool {
208 matches!(
209 self,
210 CleanupEvent::QueueFileWarning { .. }
211 | CleanupEvent::MessageReject { .. }
212 | CleanupEvent::ResourceLimit { .. }
213 )
214 }
215
216 pub fn is_warning_event(&self) -> bool {
218 matches!(
219 self,
220 CleanupEvent::QueueFileWarning { .. }
221 | CleanupEvent::ConfigurationWarning { .. }
222 | CleanupEvent::ResourceLimit { .. }
223 )
224 }
225
226 pub fn is_normal_event(&self) -> bool {
228 matches!(
229 self,
230 CleanupEvent::MessageId { .. }
231 | CleanupEvent::MessageSize { .. }
232 | CleanupEvent::HeaderProcessing { .. }
233 | CleanupEvent::FilterAction { .. }
234 | CleanupEvent::MessageDiscard { .. }
235 | CleanupEvent::MessageRemoved { .. }
236 | CleanupEvent::SnowflakeInit { .. }
237 )
238 }
239}