postfix_log_parser/events/
qmgr.rs1use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
10pub enum QmgrEvent {
11 ConfigurationWarning {
13 warning_type: String,
14 message: String,
15 },
16
17 MessageActive {
19 queue_id: String,
20 from: String,
21 size: u64,
22 nrcpt: u32,
23 },
24
25 MessageRemoved {
27 queue_id: String,
28 reason: Option<String>,
30 },
31
32 MessageSkipped {
34 queue_id: String,
35 reason: String,
37 status_details: Option<String>,
39 },
40
41 MessageDeferred {
44 queue_id: String,
45 from: String,
46 to: Option<String>,
47 relay: Option<String>,
48 delay: String,
49 delays: Option<String>,
50 dsn: Option<String>,
51 status: String,
52 },
53
54 MessageSent {
56 queue_id: String,
57 from: String,
58 to: String,
59 relay: String,
60 delay: String,
61 delays: Option<String>,
62 dsn: Option<String>,
63 status: String,
64 },
65
66 MessageBounced {
68 queue_id: String,
69 from: String,
70 to: String,
71 reason: String,
72 dsn: Option<String>,
73 },
74
75 QueueStats {
78 active: Option<u32>,
79 deferred: Option<u32>,
80 hold: Option<u32>,
81 incoming: Option<u32>,
82 maildrop: Option<u32>,
83 },
84
85 TransportStatus {
88 transport: String,
89 status: String,
90 details: Option<String>,
91 },
92
93 ResourceLimit {
96 resource_type: String,
97 current_value: Option<u32>,
98 limit_value: Option<u32>,
99 message: String,
100 },
101
102 QueueFlush {
105 queue_name: Option<String>,
106 message_count: Option<u32>,
107 },
108
109 Other {
112 event_type: String,
113 message: String,
114 queue_id: Option<String>,
115 },
116}
117
118impl QmgrEvent {
119 pub fn event_type(&self) -> &'static str {
120 match self {
121 QmgrEvent::ConfigurationWarning { .. } => "configuration_warning",
122 QmgrEvent::MessageActive { .. } => "message_active",
123 QmgrEvent::MessageRemoved { .. } => "message_removed",
124 QmgrEvent::MessageSkipped { .. } => "message_skipped",
125 QmgrEvent::MessageDeferred { .. } => "message_deferred",
126 QmgrEvent::MessageSent { .. } => "message_sent",
127 QmgrEvent::MessageBounced { .. } => "message_bounced",
128 QmgrEvent::QueueStats { .. } => "queue_stats",
129 QmgrEvent::TransportStatus { .. } => "transport_status",
130 QmgrEvent::ResourceLimit { .. } => "resource_limit",
131 QmgrEvent::QueueFlush { .. } => "queue_flush",
132 QmgrEvent::Other { .. } => "other",
133 }
134 }
135
136 pub fn queue_id(&self) -> Option<&str> {
138 match self {
139 QmgrEvent::MessageActive { queue_id, .. } => Some(queue_id),
140 QmgrEvent::MessageRemoved { queue_id, .. } => Some(queue_id),
141 QmgrEvent::MessageSkipped { queue_id, .. } => Some(queue_id),
142 QmgrEvent::MessageDeferred { queue_id, .. } => Some(queue_id),
143 QmgrEvent::MessageSent { queue_id, .. } => Some(queue_id),
144 QmgrEvent::MessageBounced { queue_id, .. } => Some(queue_id),
145 QmgrEvent::Other { queue_id, .. } => queue_id.as_deref(),
146 _ => None,
147 }
148 }
149
150 pub fn is_error_event(&self) -> bool {
152 matches!(
153 self,
154 QmgrEvent::MessageBounced { .. } | QmgrEvent::ResourceLimit { .. }
155 )
156 }
157
158 pub fn is_warning_event(&self) -> bool {
160 matches!(
161 self,
162 QmgrEvent::ConfigurationWarning { .. } | QmgrEvent::MessageDeferred { .. }
163 )
164 }
165}