datadog_api_client/datadogV1/model/
model_monitor_update_request.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/// Object describing a monitor update request.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct MonitorUpdateRequest {
14    /// Timestamp of the monitor creation.
15    #[serde(rename = "created")]
16    pub created: Option<chrono::DateTime<chrono::Utc>>,
17    /// Object describing the creator of the shared element.
18    #[serde(rename = "creator")]
19    pub creator: Option<crate::datadogV1::model::Creator>,
20    /// Whether or not the monitor is deleted. (Always `null`)
21    #[serde(
22        rename = "deleted",
23        default,
24        with = "::serde_with::rust::double_option"
25    )]
26    pub deleted: Option<Option<chrono::DateTime<chrono::Utc>>>,
27    /// Indicates whether the monitor is in a draft or published state.
28    ///
29    /// `draft`: The monitor appears as Draft and does not send notifications.
30    /// `published`: The monitor is active and evaluates conditions and notify as configured.
31    ///
32    /// This field is in preview. The draft value is only available to customers with the feature enabled.
33    ///
34    #[serde(rename = "draft_status")]
35    pub draft_status: Option<crate::datadogV1::model::MonitorDraftStatus>,
36    /// ID of this monitor.
37    #[serde(rename = "id")]
38    pub id: Option<i64>,
39    /// A message to include with notifications for this monitor.
40    #[serde(rename = "message")]
41    pub message: Option<String>,
42    /// Last timestamp when the monitor was edited.
43    #[serde(rename = "modified")]
44    pub modified: Option<chrono::DateTime<chrono::Utc>>,
45    /// Whether or not the monitor is broken down on different groups.
46    #[serde(rename = "multi")]
47    pub multi: Option<bool>,
48    /// The monitor name.
49    #[serde(rename = "name")]
50    pub name: Option<String>,
51    /// List of options associated with your monitor.
52    #[serde(rename = "options")]
53    pub options: Option<crate::datadogV1::model::MonitorOptions>,
54    /// The different states your monitor can be in.
55    #[serde(rename = "overall_state")]
56    pub overall_state: Option<crate::datadogV1::model::MonitorOverallStates>,
57    /// Integer from 1 (high) to 5 (low) indicating alert severity.
58    #[serde(
59        rename = "priority",
60        default,
61        with = "::serde_with::rust::double_option"
62    )]
63    pub priority: Option<Option<i64>>,
64    /// The monitor query.
65    #[serde(rename = "query")]
66    pub query: Option<String>,
67    /// A list of unique role identifiers to define which roles are allowed to edit the monitor. The unique identifiers for all roles can be pulled from the [Roles API](<https://docs.datadoghq.com/api/latest/roles/#list-roles>) and are located in the `data.id` field. Editing a monitor includes any updates to the monitor configuration, monitor deletion, and muting of the monitor for any amount of time. You can use the [Restriction Policies API](<https://docs.datadoghq.com/api/latest/restriction-policies/>) to manage write authorization for individual monitors by teams and users, in addition to roles.
68    #[serde(
69        rename = "restricted_roles",
70        default,
71        with = "::serde_with::rust::double_option"
72    )]
73    pub restricted_roles: Option<Option<Vec<String>>>,
74    /// Wrapper object with the different monitor states.
75    #[serde(rename = "state")]
76    pub state: Option<crate::datadogV1::model::MonitorState>,
77    /// Tags associated to your monitor.
78    #[serde(rename = "tags")]
79    pub tags: Option<Vec<String>>,
80    /// The type of the monitor. For more information about `type`, see the [monitor options](<https://docs.datadoghq.com/monitors/guide/monitor_api_options/>) docs.
81    #[serde(rename = "type")]
82    pub type_: Option<crate::datadogV1::model::MonitorType>,
83    #[serde(flatten)]
84    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
85    #[serde(skip)]
86    #[serde(default)]
87    pub(crate) _unparsed: bool,
88}
89
90impl MonitorUpdateRequest {
91    pub fn new() -> MonitorUpdateRequest {
92        MonitorUpdateRequest {
93            created: None,
94            creator: None,
95            deleted: None,
96            draft_status: None,
97            id: None,
98            message: None,
99            modified: None,
100            multi: None,
101            name: None,
102            options: None,
103            overall_state: None,
104            priority: None,
105            query: None,
106            restricted_roles: None,
107            state: None,
108            tags: None,
109            type_: None,
110            additional_properties: std::collections::BTreeMap::new(),
111            _unparsed: false,
112        }
113    }
114
115    pub fn created(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
116        self.created = Some(value);
117        self
118    }
119
120    pub fn creator(mut self, value: crate::datadogV1::model::Creator) -> Self {
121        self.creator = Some(value);
122        self
123    }
124
125    pub fn deleted(mut self, value: Option<chrono::DateTime<chrono::Utc>>) -> Self {
126        self.deleted = Some(value);
127        self
128    }
129
130    pub fn draft_status(mut self, value: crate::datadogV1::model::MonitorDraftStatus) -> Self {
131        self.draft_status = Some(value);
132        self
133    }
134
135    pub fn id(mut self, value: i64) -> Self {
136        self.id = Some(value);
137        self
138    }
139
140    pub fn message(mut self, value: String) -> Self {
141        self.message = Some(value);
142        self
143    }
144
145    pub fn modified(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
146        self.modified = Some(value);
147        self
148    }
149
150    pub fn multi(mut self, value: bool) -> Self {
151        self.multi = Some(value);
152        self
153    }
154
155    pub fn name(mut self, value: String) -> Self {
156        self.name = Some(value);
157        self
158    }
159
160    pub fn options(mut self, value: crate::datadogV1::model::MonitorOptions) -> Self {
161        self.options = Some(value);
162        self
163    }
164
165    pub fn overall_state(mut self, value: crate::datadogV1::model::MonitorOverallStates) -> Self {
166        self.overall_state = Some(value);
167        self
168    }
169
170    pub fn priority(mut self, value: Option<i64>) -> Self {
171        self.priority = Some(value);
172        self
173    }
174
175    pub fn query(mut self, value: String) -> Self {
176        self.query = Some(value);
177        self
178    }
179
180    pub fn restricted_roles(mut self, value: Option<Vec<String>>) -> Self {
181        self.restricted_roles = Some(value);
182        self
183    }
184
185    pub fn state(mut self, value: crate::datadogV1::model::MonitorState) -> Self {
186        self.state = Some(value);
187        self
188    }
189
190    pub fn tags(mut self, value: Vec<String>) -> Self {
191        self.tags = Some(value);
192        self
193    }
194
195    pub fn type_(mut self, value: crate::datadogV1::model::MonitorType) -> Self {
196        self.type_ = Some(value);
197        self
198    }
199
200    pub fn additional_properties(
201        mut self,
202        value: std::collections::BTreeMap<String, serde_json::Value>,
203    ) -> Self {
204        self.additional_properties = value;
205        self
206    }
207}
208
209impl Default for MonitorUpdateRequest {
210    fn default() -> Self {
211        Self::new()
212    }
213}
214
215impl<'de> Deserialize<'de> for MonitorUpdateRequest {
216    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
217    where
218        D: Deserializer<'de>,
219    {
220        struct MonitorUpdateRequestVisitor;
221        impl<'a> Visitor<'a> for MonitorUpdateRequestVisitor {
222            type Value = MonitorUpdateRequest;
223
224            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
225                f.write_str("a mapping")
226            }
227
228            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
229            where
230                M: MapAccess<'a>,
231            {
232                let mut created: Option<chrono::DateTime<chrono::Utc>> = None;
233                let mut creator: Option<crate::datadogV1::model::Creator> = None;
234                let mut deleted: Option<Option<chrono::DateTime<chrono::Utc>>> = None;
235                let mut draft_status: Option<crate::datadogV1::model::MonitorDraftStatus> = None;
236                let mut id: Option<i64> = None;
237                let mut message: Option<String> = None;
238                let mut modified: Option<chrono::DateTime<chrono::Utc>> = None;
239                let mut multi: Option<bool> = None;
240                let mut name: Option<String> = None;
241                let mut options: Option<crate::datadogV1::model::MonitorOptions> = None;
242                let mut overall_state: Option<crate::datadogV1::model::MonitorOverallStates> = None;
243                let mut priority: Option<Option<i64>> = None;
244                let mut query: Option<String> = None;
245                let mut restricted_roles: Option<Option<Vec<String>>> = None;
246                let mut state: Option<crate::datadogV1::model::MonitorState> = None;
247                let mut tags: Option<Vec<String>> = None;
248                let mut type_: Option<crate::datadogV1::model::MonitorType> = None;
249                let mut additional_properties: std::collections::BTreeMap<
250                    String,
251                    serde_json::Value,
252                > = std::collections::BTreeMap::new();
253                let mut _unparsed = false;
254
255                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
256                    match k.as_str() {
257                        "created" => {
258                            if v.is_null() {
259                                continue;
260                            }
261                            created = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
262                        }
263                        "creator" => {
264                            if v.is_null() {
265                                continue;
266                            }
267                            creator = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
268                        }
269                        "deleted" => {
270                            deleted = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
271                        }
272                        "draft_status" => {
273                            if v.is_null() {
274                                continue;
275                            }
276                            draft_status =
277                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
278                            if let Some(ref _draft_status) = draft_status {
279                                match _draft_status {
280                                    crate::datadogV1::model::MonitorDraftStatus::UnparsedObject(
281                                        _draft_status,
282                                    ) => {
283                                        _unparsed = true;
284                                    }
285                                    _ => {}
286                                }
287                            }
288                        }
289                        "id" => {
290                            if v.is_null() {
291                                continue;
292                            }
293                            id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
294                        }
295                        "message" => {
296                            if v.is_null() {
297                                continue;
298                            }
299                            message = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
300                        }
301                        "modified" => {
302                            if v.is_null() {
303                                continue;
304                            }
305                            modified = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
306                        }
307                        "multi" => {
308                            if v.is_null() {
309                                continue;
310                            }
311                            multi = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
312                        }
313                        "name" => {
314                            if v.is_null() {
315                                continue;
316                            }
317                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
318                        }
319                        "options" => {
320                            if v.is_null() {
321                                continue;
322                            }
323                            options = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
324                        }
325                        "overall_state" => {
326                            if v.is_null() {
327                                continue;
328                            }
329                            overall_state =
330                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
331                            if let Some(ref _overall_state) = overall_state {
332                                match _overall_state {
333                                    crate::datadogV1::model::MonitorOverallStates::UnparsedObject(_overall_state) => {
334                                        _unparsed = true;
335                                    },
336                                    _ => {}
337                                }
338                            }
339                        }
340                        "priority" => {
341                            priority = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
342                        }
343                        "query" => {
344                            if v.is_null() {
345                                continue;
346                            }
347                            query = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
348                        }
349                        "restricted_roles" => {
350                            restricted_roles =
351                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
352                        }
353                        "state" => {
354                            if v.is_null() {
355                                continue;
356                            }
357                            state = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
358                        }
359                        "tags" => {
360                            if v.is_null() {
361                                continue;
362                            }
363                            tags = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
364                        }
365                        "type" => {
366                            if v.is_null() {
367                                continue;
368                            }
369                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
370                            if let Some(ref _type_) = type_ {
371                                match _type_ {
372                                    crate::datadogV1::model::MonitorType::UnparsedObject(
373                                        _type_,
374                                    ) => {
375                                        _unparsed = true;
376                                    }
377                                    _ => {}
378                                }
379                            }
380                        }
381                        &_ => {
382                            if let Ok(value) = serde_json::from_value(v.clone()) {
383                                additional_properties.insert(k, value);
384                            }
385                        }
386                    }
387                }
388
389                let content = MonitorUpdateRequest {
390                    created,
391                    creator,
392                    deleted,
393                    draft_status,
394                    id,
395                    message,
396                    modified,
397                    multi,
398                    name,
399                    options,
400                    overall_state,
401                    priority,
402                    query,
403                    restricted_roles,
404                    state,
405                    tags,
406                    type_,
407                    additional_properties,
408                    _unparsed,
409                };
410
411                Ok(content)
412            }
413        }
414
415        deserializer.deserialize_any(MonitorUpdateRequestVisitor)
416    }
417}