postfix_log_parser/events/
postmap.rs1use chrono::{DateTime, Utc};
6use serde::{Deserialize, Serialize};
7use std::collections::HashMap;
8
9#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13pub struct PostmapEvent {
14 pub timestamp: DateTime<Utc>,
16
17 pub process_id: u32,
19
20 pub event_type: PostmapEventType,
22
23 pub details: PostmapDetails,
25
26 pub extensions: HashMap<String, String>,
29}
30
31#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
32pub enum PostmapEventType {
33 FileError,
34 CommandError,
35}
36
37#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
41pub struct PostmapDetails {
42 pub error_type: ErrorType,
44
45 pub file_path: Option<String>,
48
49 pub error_message: String,
52
53 pub command_args: Option<String>,
56}
57
58#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
59pub enum ErrorType {
60 FileNotFound,
61 DirectoryNotFound,
62 InvalidCommandArgs,
63}
64
65impl PostmapEvent {
66 pub fn new(
67 timestamp: DateTime<Utc>,
68 process_id: u32,
69 event_type: PostmapEventType,
70 details: PostmapDetails,
71 ) -> Self {
72 Self {
73 timestamp,
74 process_id,
75 event_type,
76 details,
77 extensions: HashMap::new(),
78 }
79 }
80
81 pub fn add_extension(&mut self, key: String, value: String) {
82 self.extensions.insert(key, value);
83 }
84}
85
86impl PostmapDetails {
87 pub fn new_file_error(error_type: ErrorType, file_path: String, error_message: String) -> Self {
88 Self {
89 error_type,
90 file_path: Some(file_path),
91 error_message,
92 command_args: None,
93 }
94 }
95
96 pub fn new_command_error(error_message: String, command_args: Option<String>) -> Self {
97 Self {
98 error_type: ErrorType::InvalidCommandArgs,
99 file_path: None,
100 error_message,
101 command_args,
102 }
103 }
104}