postfix_log_parser/formatters/json/
postfix_script.rs1use crate::events::postfix_script::{
4 PostfixScriptEvent, PostfixScriptFatalError, PostfixScriptOperation, PostfixScriptWarningType,
5};
6use serde_json::{json, Value};
7
8pub fn format_postfix_script_event(event: &PostfixScriptEvent) -> Value {
10 match event {
11 PostfixScriptEvent::SystemOperation { operation, .. } => match operation {
12 PostfixScriptOperation::Starting => {
13 json!({
14 "event_type": "system_starting",
15 "description": "Postfix mail system is starting"
16 })
17 }
18 PostfixScriptOperation::Running { pid } => {
19 json!({
20 "event_type": "system_running",
21 "master_pid": pid,
22 "description": "Postfix mail system is running"
23 })
24 }
25 PostfixScriptOperation::Refreshing => {
26 json!({
27 "event_type": "system_refreshing",
28 "description": "Postfix mail system is refreshing"
29 })
30 }
31 },
32 PostfixScriptEvent::FatalError { error, .. } => match error {
33 PostfixScriptFatalError::CannotExecutePostconf => {
34 json!({
35 "event_type": "fatal_error",
36 "error_type": "cannot_execute_postconf",
37 "description": "Cannot execute postconf command",
38 "severity": "fatal"
39 })
40 }
41 PostfixScriptFatalError::CannotExecuteCommand { command } => {
42 json!({
43 "event_type": "fatal_error",
44 "error_type": "cannot_execute_command",
45 "command": command,
46 "description": format!("Cannot execute command: {}", command),
47 "severity": "fatal"
48 })
49 }
50 PostfixScriptFatalError::MissingPath { path } => {
51 json!({
52 "event_type": "fatal_error",
53 "error_type": "missing_path",
54 "path": path,
55 "description": format!("Missing directory or file: {}", path),
56 "severity": "fatal"
57 })
58 }
59 PostfixScriptFatalError::Other { message } => {
60 json!({
61 "event_type": "fatal_error",
62 "error_type": "other",
63 "message": message,
64 "description": "Other fatal error",
65 "severity": "fatal"
66 })
67 }
68 },
69 PostfixScriptEvent::Warning { warning, .. } => match warning {
70 PostfixScriptWarningType::NotOwnedBy {
71 path,
72 expected_owner,
73 } => {
74 json!({
75 "event_type": "warning",
76 "warning_type": "not_owned_by",
77 "path": path,
78 "expected_owner": expected_owner,
79 "description": format!("File/directory not owned by {}: {}", expected_owner, path),
80 "severity": "warning"
81 })
82 }
83 PostfixScriptWarningType::GroupWritable { path } => {
84 json!({
85 "event_type": "warning",
86 "warning_type": "group_writable",
87 "path": path,
88 "description": format!("File/directory is group or other writable: {}", path),
89 "severity": "warning"
90 })
91 }
92 PostfixScriptWarningType::SymlinkLeaves { path } => {
93 json!({
94 "event_type": "warning",
95 "warning_type": "symlink_leaves",
96 "path": path,
97 "description": format!("Symlink leaves directory: {}", path),
98 "severity": "warning"
99 })
100 }
101 PostfixScriptWarningType::Other { message } => {
102 json!({
103 "event_type": "warning",
104 "warning_type": "other",
105 "message": message,
106 "description": "Other warning",
107 "severity": "warning"
108 })
109 }
110 },
111 }
112}