use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum QmgrEvent {
ConfigurationWarning {
warning_type: String,
message: String,
},
MessageActive {
queue_id: String,
from: String,
size: u64,
nrcpt: u32,
},
MessageRemoved {
queue_id: String,
reason: Option<String>,
},
MessageSkipped {
queue_id: String,
reason: String,
status_details: Option<String>,
},
MessageDeferred {
queue_id: String,
from: String,
to: Option<String>,
relay: Option<String>,
delay: String,
delays: Option<String>,
dsn: Option<String>,
status: String,
},
MessageSent {
queue_id: String,
from: String,
to: String,
relay: String,
delay: String,
delays: Option<String>,
dsn: Option<String>,
status: String,
},
MessageBounced {
queue_id: String,
from: String,
to: String,
reason: String,
dsn: Option<String>,
},
QueueStats {
active: Option<u32>,
deferred: Option<u32>,
hold: Option<u32>,
incoming: Option<u32>,
maildrop: Option<u32>,
},
TransportStatus {
transport: String,
status: String,
details: Option<String>,
},
ResourceLimit {
resource_type: String,
current_value: Option<u32>,
limit_value: Option<u32>,
message: String,
},
QueueFlush {
queue_name: Option<String>,
message_count: Option<u32>,
},
Other {
event_type: String,
message: String,
queue_id: Option<String>,
},
}
impl QmgrEvent {
pub fn event_type(&self) -> &'static str {
match self {
QmgrEvent::ConfigurationWarning { .. } => "configuration_warning",
QmgrEvent::MessageActive { .. } => "message_active",
QmgrEvent::MessageRemoved { .. } => "message_removed",
QmgrEvent::MessageSkipped { .. } => "message_skipped",
QmgrEvent::MessageDeferred { .. } => "message_deferred",
QmgrEvent::MessageSent { .. } => "message_sent",
QmgrEvent::MessageBounced { .. } => "message_bounced",
QmgrEvent::QueueStats { .. } => "queue_stats",
QmgrEvent::TransportStatus { .. } => "transport_status",
QmgrEvent::ResourceLimit { .. } => "resource_limit",
QmgrEvent::QueueFlush { .. } => "queue_flush",
QmgrEvent::Other { .. } => "other",
}
}
pub fn queue_id(&self) -> Option<&str> {
match self {
QmgrEvent::MessageActive { queue_id, .. } => Some(queue_id),
QmgrEvent::MessageRemoved { queue_id, .. } => Some(queue_id),
QmgrEvent::MessageSkipped { queue_id, .. } => Some(queue_id),
QmgrEvent::MessageDeferred { queue_id, .. } => Some(queue_id),
QmgrEvent::MessageSent { queue_id, .. } => Some(queue_id),
QmgrEvent::MessageBounced { queue_id, .. } => Some(queue_id),
QmgrEvent::Other { queue_id, .. } => queue_id.as_deref(),
_ => None,
}
}
pub fn is_error_event(&self) -> bool {
matches!(
self,
QmgrEvent::MessageBounced { .. } | QmgrEvent::ResourceLimit { .. }
)
}
pub fn is_warning_event(&self) -> bool {
matches!(
self,
QmgrEvent::ConfigurationWarning { .. } | QmgrEvent::MessageDeferred { .. }
)
}
}