postfix_log_parser/events/
cleanup.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
7pub enum CleanupEvent {
8 MessageId {
11 queue_id: String,
12 message_id: String,
13 },
14
15 QueueFileWarning {
18 operation: String, file_path: String, error_reason: String, },
22
23 MessageRewrite {
26 queue_id: String,
27 rewrite_type: String, original: String, rewritten: String, },
31
32 MessageSize {
35 queue_id: String,
36 size: u64, },
38
39 HeaderProcessing {
42 queue_id: String,
43 header_name: String, header_value: String, action: String, },
47
48 FilterAction {
51 queue_id: String,
52 filter_name: String, action: String, details: Option<String>, },
56
57 AddressRewrite {
60 queue_id: String,
61 address_type: String, original_address: String,
63 rewritten_address: String,
64 },
65
66 MessageReject {
69 queue_id: String,
70 reason: String, action: String, },
73
74 ResourceLimit {
77 resource_type: String, limit_details: String, current_value: Option<u64>,
80 limit_value: Option<u64>,
81 },
82
83 MilterInteraction {
86 queue_id: String,
87 milter_name: String, command: String, response: Option<String>, },
91
92 ConfigurationWarning {
95 warning_type: String, message: String, },
98
99 Statistics {
102 processed: Option<u32>, rejected: Option<u32>, errors: Option<u32>, },
106
107 Other {
110 event_type: String,
111 message: String,
112 queue_id: Option<String>,
113 },
114}
115
116impl CleanupEvent {
117 pub fn event_type(&self) -> &'static str {
118 match self {
119 CleanupEvent::MessageId { .. } => "message_id",
120 CleanupEvent::QueueFileWarning { .. } => "queue_file_warning",
121 CleanupEvent::MessageRewrite { .. } => "message_rewrite",
122 CleanupEvent::MessageSize { .. } => "message_size",
123 CleanupEvent::HeaderProcessing { .. } => "header_processing",
124 CleanupEvent::FilterAction { .. } => "filter_action",
125 CleanupEvent::AddressRewrite { .. } => "address_rewrite",
126 CleanupEvent::MessageReject { .. } => "message_reject",
127 CleanupEvent::ResourceLimit { .. } => "resource_limit",
128 CleanupEvent::MilterInteraction { .. } => "milter_interaction",
129 CleanupEvent::ConfigurationWarning { .. } => "configuration_warning",
130 CleanupEvent::Statistics { .. } => "statistics",
131 CleanupEvent::Other { .. } => "other",
132 }
133 }
134
135 pub fn queue_id(&self) -> Option<&str> {
137 match self {
138 CleanupEvent::MessageId { queue_id, .. } => Some(queue_id),
139 CleanupEvent::MessageRewrite { queue_id, .. } => Some(queue_id),
140 CleanupEvent::MessageSize { queue_id, .. } => Some(queue_id),
141 CleanupEvent::HeaderProcessing { queue_id, .. } => Some(queue_id),
142 CleanupEvent::FilterAction { queue_id, .. } => Some(queue_id),
143 CleanupEvent::AddressRewrite { queue_id, .. } => Some(queue_id),
144 CleanupEvent::MessageReject { queue_id, .. } => Some(queue_id),
145 CleanupEvent::MilterInteraction { queue_id, .. } => Some(queue_id),
146 CleanupEvent::Other { queue_id, .. } => queue_id.as_deref(),
147 _ => None,
148 }
149 }
150
151 pub fn is_error_event(&self) -> bool {
153 matches!(
154 self,
155 CleanupEvent::QueueFileWarning { .. }
156 | CleanupEvent::MessageReject { .. }
157 | CleanupEvent::ResourceLimit { .. }
158 )
159 }
160
161 pub fn is_warning_event(&self) -> bool {
163 matches!(
164 self,
165 CleanupEvent::QueueFileWarning { .. }
166 | CleanupEvent::ConfigurationWarning { .. }
167 | CleanupEvent::ResourceLimit { .. }
168 )
169 }
170
171 pub fn is_normal_event(&self) -> bool {
173 matches!(
174 self,
175 CleanupEvent::MessageId { .. }
176 | CleanupEvent::MessageSize { .. }
177 | CleanupEvent::HeaderProcessing { .. }
178 | CleanupEvent::FilterAction { .. }
179 )
180 }
181}