postfix_log_parser/events/
postmap.rs1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4
5#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6pub struct PostmapEvent {
7 pub timestamp: DateTime<Utc>,
8 pub process_id: u32,
9 pub event_type: PostmapEventType,
10 pub details: PostmapDetails,
11 pub extensions: HashMap<String, String>,
12}
13
14#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
15pub enum PostmapEventType {
16 FileError,
17 CommandError,
18}
19
20#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
21pub struct PostmapDetails {
22 pub error_type: ErrorType,
23 pub file_path: Option<String>,
24 pub error_message: String,
25 pub command_args: Option<String>,
26}
27
28#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
29pub enum ErrorType {
30 FileNotFound,
31 DirectoryNotFound,
32 InvalidCommandArgs,
33}
34
35impl PostmapEvent {
36 pub fn new(
37 timestamp: DateTime<Utc>,
38 process_id: u32,
39 event_type: PostmapEventType,
40 details: PostmapDetails,
41 ) -> Self {
42 Self {
43 timestamp,
44 process_id,
45 event_type,
46 details,
47 extensions: HashMap::new(),
48 }
49 }
50
51 pub fn add_extension(&mut self, key: String, value: String) {
52 self.extensions.insert(key, value);
53 }
54}
55
56impl PostmapDetails {
57 pub fn new_file_error(error_type: ErrorType, file_path: String, error_message: String) -> Self {
58 Self {
59 error_type,
60 file_path: Some(file_path),
61 error_message,
62 command_args: None,
63 }
64 }
65
66 pub fn new_command_error(error_message: String, command_args: Option<String>) -> Self {
67 Self {
68 error_type: ErrorType::InvalidCommandArgs,
69 file_path: None,
70 error_message,
71 command_args,
72 }
73 }
74}
75