datadog_api_client/datadogV2/model/
model_process_summary_attributes.rs

1// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2// This product includes software developed at Datadog (https://www.datadoghq.com/).
3// Copyright 2019-Present Datadog, Inc.
4use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9/// Attributes for a process summary.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct ProcessSummaryAttributes {
14    /// Process command line.
15    #[serde(rename = "cmdline")]
16    pub cmdline: Option<String>,
17    /// Host running the process.
18    #[serde(rename = "host")]
19    pub host: Option<String>,
20    /// Process ID.
21    #[serde(rename = "pid")]
22    pub pid: Option<i64>,
23    /// Parent process ID.
24    #[serde(rename = "ppid")]
25    pub ppid: Option<i64>,
26    /// Time the process was started.
27    #[serde(rename = "start")]
28    pub start: Option<String>,
29    /// List of tags associated with the process.
30    #[serde(rename = "tags")]
31    pub tags: Option<Vec<String>>,
32    /// Time the process was seen.
33    #[serde(rename = "timestamp")]
34    pub timestamp: Option<String>,
35    /// Process owner.
36    #[serde(rename = "user")]
37    pub user: Option<String>,
38    #[serde(flatten)]
39    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
40    #[serde(skip)]
41    #[serde(default)]
42    pub(crate) _unparsed: bool,
43}
44
45impl ProcessSummaryAttributes {
46    pub fn new() -> ProcessSummaryAttributes {
47        ProcessSummaryAttributes {
48            cmdline: None,
49            host: None,
50            pid: None,
51            ppid: None,
52            start: None,
53            tags: None,
54            timestamp: None,
55            user: None,
56            additional_properties: std::collections::BTreeMap::new(),
57            _unparsed: false,
58        }
59    }
60
61    pub fn cmdline(mut self, value: String) -> Self {
62        self.cmdline = Some(value);
63        self
64    }
65
66    pub fn host(mut self, value: String) -> Self {
67        self.host = Some(value);
68        self
69    }
70
71    pub fn pid(mut self, value: i64) -> Self {
72        self.pid = Some(value);
73        self
74    }
75
76    pub fn ppid(mut self, value: i64) -> Self {
77        self.ppid = Some(value);
78        self
79    }
80
81    pub fn start(mut self, value: String) -> Self {
82        self.start = Some(value);
83        self
84    }
85
86    pub fn tags(mut self, value: Vec<String>) -> Self {
87        self.tags = Some(value);
88        self
89    }
90
91    pub fn timestamp(mut self, value: String) -> Self {
92        self.timestamp = Some(value);
93        self
94    }
95
96    pub fn user(mut self, value: String) -> Self {
97        self.user = Some(value);
98        self
99    }
100
101    pub fn additional_properties(
102        mut self,
103        value: std::collections::BTreeMap<String, serde_json::Value>,
104    ) -> Self {
105        self.additional_properties = value;
106        self
107    }
108}
109
110impl Default for ProcessSummaryAttributes {
111    fn default() -> Self {
112        Self::new()
113    }
114}
115
116impl<'de> Deserialize<'de> for ProcessSummaryAttributes {
117    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
118    where
119        D: Deserializer<'de>,
120    {
121        struct ProcessSummaryAttributesVisitor;
122        impl<'a> Visitor<'a> for ProcessSummaryAttributesVisitor {
123            type Value = ProcessSummaryAttributes;
124
125            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
126                f.write_str("a mapping")
127            }
128
129            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
130            where
131                M: MapAccess<'a>,
132            {
133                let mut cmdline: Option<String> = None;
134                let mut host: Option<String> = None;
135                let mut pid: Option<i64> = None;
136                let mut ppid: Option<i64> = None;
137                let mut start: Option<String> = None;
138                let mut tags: Option<Vec<String>> = None;
139                let mut timestamp: Option<String> = None;
140                let mut user: Option<String> = None;
141                let mut additional_properties: std::collections::BTreeMap<
142                    String,
143                    serde_json::Value,
144                > = std::collections::BTreeMap::new();
145                let mut _unparsed = false;
146
147                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
148                    match k.as_str() {
149                        "cmdline" => {
150                            if v.is_null() {
151                                continue;
152                            }
153                            cmdline = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
154                        }
155                        "host" => {
156                            if v.is_null() {
157                                continue;
158                            }
159                            host = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
160                        }
161                        "pid" => {
162                            if v.is_null() {
163                                continue;
164                            }
165                            pid = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
166                        }
167                        "ppid" => {
168                            if v.is_null() {
169                                continue;
170                            }
171                            ppid = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
172                        }
173                        "start" => {
174                            if v.is_null() {
175                                continue;
176                            }
177                            start = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
178                        }
179                        "tags" => {
180                            if v.is_null() {
181                                continue;
182                            }
183                            tags = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
184                        }
185                        "timestamp" => {
186                            if v.is_null() {
187                                continue;
188                            }
189                            timestamp = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
190                        }
191                        "user" => {
192                            if v.is_null() {
193                                continue;
194                            }
195                            user = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
196                        }
197                        &_ => {
198                            if let Ok(value) = serde_json::from_value(v.clone()) {
199                                additional_properties.insert(k, value);
200                            }
201                        }
202                    }
203                }
204
205                let content = ProcessSummaryAttributes {
206                    cmdline,
207                    host,
208                    pid,
209                    ppid,
210                    start,
211                    tags,
212                    timestamp,
213                    user,
214                    additional_properties,
215                    _unparsed,
216                };
217
218                Ok(content)
219            }
220        }
221
222        deserializer.deserialize_any(ProcessSummaryAttributesVisitor)
223    }
224}