postfix_log_parser/events/
master.rs

1//! Master daemon events
2//!
3//! This module defines the events for the master component,
4//! which is responsible for process management and daemon control.
5
6use crate::events::base::BaseEvent;
7use serde::{Deserialize, Serialize};
8
9/// Master daemon event types
10#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11pub enum MasterEvent {
12    /// Daemon lifecycle management
13    DaemonLifecycle {
14        base: BaseEvent,
15        lifecycle: MasterLifecycleEvent,
16    },
17    /// Process management warnings
18    ProcessWarning {
19        base: BaseEvent,
20        warning: MasterProcessWarning,
21    },
22    /// Service limit warnings  
23    ServiceLimit {
24        base: BaseEvent,
25        limit: MasterServiceLimit,
26    },
27    /// Configuration and stress warnings
28    ConfigurationWarning {
29        base: BaseEvent,
30        warning: MasterConfigWarning,
31    },
32}
33
34/// Master daemon lifecycle events
35#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
36pub enum MasterLifecycleEvent {
37    /// Daemon started with version info
38    Started {
39        version: String,
40        configuration: String,
41    },
42    /// Configuration reload
43    Reload {
44        version: String,
45        configuration: String,
46    },
47}
48
49/// Process management warnings
50#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
51pub enum MasterProcessWarning {
52    /// Process killed by signal
53    ProcessKilled {
54        service: String,
55        process_path: String,
56        pid: u32,
57        signal: u8,
58    },
59    /// Bad command startup (throttling)
60    BadCommandStartup { service: String },
61}
62
63/// Service limit warnings
64#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
65pub enum MasterServiceLimit {
66    /// Service has reached process limit
67    ProcessLimitReached {
68        service: String,
69        service_address: String,
70        limit: u32,
71    },
72}
73
74/// Configuration and stress warnings
75#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
76pub enum MasterConfigWarning {
77    /// Process count or service time suggestion
78    ProcessCountSuggestion,
79    /// Stress configuration reference
80    StressConfigReference { url: String },
81}
82
83impl MasterEvent {
84    /// Get the base event
85    pub fn base(&self) -> &BaseEvent {
86        match self {
87            MasterEvent::DaemonLifecycle { base, .. } => base,
88            MasterEvent::ProcessWarning { base, .. } => base,
89            MasterEvent::ServiceLimit { base, .. } => base,
90            MasterEvent::ConfigurationWarning { base, .. } => base,
91        }
92    }
93
94    /// Get the base event mutably
95    pub fn base_mut(&mut self) -> &mut BaseEvent {
96        match self {
97            MasterEvent::DaemonLifecycle { base, .. } => base,
98            MasterEvent::ProcessWarning { base, .. } => base,
99            MasterEvent::ServiceLimit { base, .. } => base,
100            MasterEvent::ConfigurationWarning { base, .. } => base,
101        }
102    }
103
104    /// Get the event type string
105    pub fn event_type(&self) -> &'static str {
106        match self {
107            MasterEvent::DaemonLifecycle { lifecycle, .. } => match lifecycle {
108                MasterLifecycleEvent::Started { .. } => "daemon_started",
109                MasterLifecycleEvent::Reload { .. } => "daemon_reload",
110            },
111            MasterEvent::ProcessWarning { warning, .. } => match warning {
112                MasterProcessWarning::ProcessKilled { .. } => "process_killed",
113                MasterProcessWarning::BadCommandStartup { .. } => "bad_command_startup",
114            },
115            MasterEvent::ServiceLimit { .. } => "service_limit_reached",
116            MasterEvent::ConfigurationWarning { warning, .. } => match warning {
117                MasterConfigWarning::ProcessCountSuggestion => "process_count_suggestion",
118                MasterConfigWarning::StressConfigReference { .. } => "stress_config_reference",
119            },
120        }
121    }
122}