1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
use metrics::counter;
use vector_lib::internal_event::InternalEvent;
use vector_lib::internal_event::{error_stage, error_type};

#[derive(Debug)]
pub struct WindowsServiceStart<'a> {
    pub already_started: bool,
    pub name: &'a str,
}

impl<'a> InternalEvent for WindowsServiceStart<'a> {
    fn emit(self) {
        info!(
            already_started = %self.already_started,
            name = self.name,
            "Started Windows Service.",
        );
        counter!(
            "windows_service_start_total",
            "already_started" => self.already_started.to_string(),
        )
        .increment(1);
    }
}

#[derive(Debug)]
pub struct WindowsServiceStop<'a> {
    pub already_stopped: bool,
    pub name: &'a str,
}

impl<'a> InternalEvent for WindowsServiceStop<'a> {
    fn emit(self) {
        info!(
            already_stopped = %self.already_stopped,
            name = ?self.name,
            "Stopped Windows Service.",
        );
        counter!(
            "windows_service_stop_total",
            "already_stopped" => self.already_stopped.to_string(),
        )
        .increment(1);
    }
}

#[derive(Debug)]
pub struct WindowsServiceRestart<'a> {
    pub name: &'a str,
}

impl<'a> InternalEvent for WindowsServiceRestart<'a> {
    fn emit(self) {
        info!(
            name = ?self.name,
            "Restarted Windows Service."
        );
        counter!("windows_service_restart_total").increment(1)
    }
}

#[derive(Debug)]
pub struct WindowsServiceInstall<'a> {
    pub name: &'a str,
}

impl<'a> InternalEvent for WindowsServiceInstall<'a> {
    fn emit(self) {
        info!(
            name = ?self.name,
            "Installed Windows Service.",
        );
        counter!("windows_service_install_total").increment(1);
    }
}

#[derive(Debug)]
pub struct WindowsServiceUninstall<'a> {
    pub name: &'a str,
}

impl<'a> InternalEvent for WindowsServiceUninstall<'a> {
    fn emit(self) {
        info!(
            name = ?self.name,
            "Uninstalled Windows Service.",
        );
        counter!("windows_service_uninstall_total").increment(1);
    }
}

#[derive(Debug)]
pub struct WindowsServiceDoesNotExistError<'a> {
    pub name: &'a str,
}

impl<'a> InternalEvent for WindowsServiceDoesNotExistError<'a> {
    fn emit(self) {
        error!(
            message = "Windows service does not exist. Maybe it needs to be installed.",
            name = self.name,
            error_code = "service_missing",
            error_type = error_type::CONDITION_FAILED,
            stage = error_stage::PROCESSING,
            internal_log_rate_limit = true,
        );
        counter!(
            "component_errors_total",
            "error_code" => "service_missing",
            "error_type" => error_type::CONDITION_FAILED,
            "stage" => error_stage::PROCESSING,
        )
        .increment(1);
    }
}