datadog-api-client 0.30.0

Rust client for the Datadog API.
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.
use serde::de::{Error, MapAccess, Visitor};
use serde::{Deserialize, Deserializer, Serialize};
use serde_with::skip_serializing_none;
use std::fmt::{self, Formatter};

/// The incident's attributes from a response.
#[non_exhaustive]
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct IncidentResponseAttributes {
    /// Timestamp of when the incident was archived.
    #[serde(
        rename = "archived",
        default,
        with = "::serde_with::rust::double_option"
    )]
    pub archived: Option<Option<chrono::DateTime<chrono::Utc>>>,
    /// The incident case id.
    #[serde(
        rename = "case_id",
        default,
        with = "::serde_with::rust::double_option"
    )]
    pub case_id: Option<Option<i64>>,
    /// Timestamp when the incident was created.
    #[serde(rename = "created")]
    pub created: Option<chrono::DateTime<chrono::Utc>>,
    /// Length of the incident's customer impact in seconds.
    /// Equals the difference between `customer_impact_start` and `customer_impact_end`.
    #[serde(rename = "customer_impact_duration")]
    pub customer_impact_duration: Option<i64>,
    /// Timestamp when customers were no longer impacted by the incident.
    #[serde(
        rename = "customer_impact_end",
        default,
        with = "::serde_with::rust::double_option"
    )]
    pub customer_impact_end: Option<Option<chrono::DateTime<chrono::Utc>>>,
    /// A summary of the impact customers experienced during the incident.
    #[serde(
        rename = "customer_impact_scope",
        default,
        with = "::serde_with::rust::double_option"
    )]
    pub customer_impact_scope: Option<Option<String>>,
    /// Timestamp when customers began being impacted by the incident.
    #[serde(
        rename = "customer_impact_start",
        default,
        with = "::serde_with::rust::double_option"
    )]
    pub customer_impact_start: Option<Option<chrono::DateTime<chrono::Utc>>>,
    /// A flag indicating whether the incident caused customer impact.
    #[serde(rename = "customer_impacted")]
    pub customer_impacted: Option<bool>,
    /// Timestamp when the incident was declared.
    #[serde(rename = "declared")]
    pub declared: Option<chrono::DateTime<chrono::Utc>>,
    /// Incident's non Datadog creator.
    #[serde(
        rename = "declared_by",
        default,
        with = "::serde_with::rust::double_option"
    )]
    pub declared_by: Option<Option<crate::datadogV2::model::IncidentNonDatadogCreator>>,
    /// UUID of the user who declared the incident.
    #[serde(
        rename = "declared_by_uuid",
        default,
        with = "::serde_with::rust::double_option"
    )]
    pub declared_by_uuid: Option<Option<String>>,
    /// Timestamp when the incident was detected.
    #[serde(
        rename = "detected",
        default,
        with = "::serde_with::rust::double_option"
    )]
    pub detected: Option<Option<chrono::DateTime<chrono::Utc>>>,
    /// A condensed view of the user-defined fields attached to incidents.
    #[serde(rename = "fields")]
    pub fields: Option<
        std::collections::BTreeMap<String, crate::datadogV2::model::IncidentFieldAttributes>,
    >,
    /// A unique identifier that represents an incident type.
    #[serde(rename = "incident_type_uuid")]
    pub incident_type_uuid: Option<String>,
    /// A flag indicating whether the incident is a test incident.
    #[serde(rename = "is_test")]
    pub is_test: Option<bool>,
    /// Timestamp when the incident was last modified.
    #[serde(rename = "modified")]
    pub modified: Option<chrono::DateTime<chrono::Utc>>,
    /// Incident's non Datadog creator.
    #[serde(
        rename = "non_datadog_creator",
        default,
        with = "::serde_with::rust::double_option"
    )]
    pub non_datadog_creator: Option<Option<crate::datadogV2::model::IncidentNonDatadogCreator>>,
    /// Notification handles that will be notified of the incident during update.
    #[serde(
        rename = "notification_handles",
        default,
        with = "::serde_with::rust::double_option"
    )]
    pub notification_handles:
        Option<Option<Vec<crate::datadogV2::model::IncidentNotificationHandle>>>,
    /// The monotonically increasing integer ID for the incident.
    #[serde(rename = "public_id")]
    pub public_id: Option<i64>,
    /// Timestamp when the incident's state was last changed from active or stable to resolved or completed.
    #[serde(
        rename = "resolved",
        default,
        with = "::serde_with::rust::double_option"
    )]
    pub resolved: Option<Option<chrono::DateTime<chrono::Utc>>>,
    /// The incident severity.
    #[serde(rename = "severity")]
    pub severity: Option<crate::datadogV2::model::IncidentSeverity>,
    /// The state incident.
    #[serde(rename = "state", default, with = "::serde_with::rust::double_option")]
    pub state: Option<Option<String>>,
    /// The amount of time in seconds to detect the incident.
    /// Equals the difference between `customer_impact_start` and `detected`.
    #[serde(rename = "time_to_detect")]
    pub time_to_detect: Option<i64>,
    /// The amount of time in seconds to call incident after detection. Equals the difference of `detected` and `created`.
    #[serde(rename = "time_to_internal_response")]
    pub time_to_internal_response: Option<i64>,
    /// The amount of time in seconds to resolve customer impact after detecting the issue. Equals the difference between `customer_impact_end` and `detected`.
    #[serde(rename = "time_to_repair")]
    pub time_to_repair: Option<i64>,
    /// The amount of time in seconds to resolve the incident after it was created. Equals the difference between `created` and `resolved`.
    #[serde(rename = "time_to_resolve")]
    pub time_to_resolve: Option<i64>,
    /// The title of the incident, which summarizes what happened.
    #[serde(rename = "title")]
    pub title: String,
    /// The incident visibility status.
    #[serde(
        rename = "visibility",
        default,
        with = "::serde_with::rust::double_option"
    )]
    pub visibility: Option<Option<String>>,
    #[serde(flatten)]
    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
    #[serde(skip)]
    #[serde(default)]
    pub(crate) _unparsed: bool,
}

impl IncidentResponseAttributes {
    pub fn new(title: String) -> IncidentResponseAttributes {
        IncidentResponseAttributes {
            archived: None,
            case_id: None,
            created: None,
            customer_impact_duration: None,
            customer_impact_end: None,
            customer_impact_scope: None,
            customer_impact_start: None,
            customer_impacted: None,
            declared: None,
            declared_by: None,
            declared_by_uuid: None,
            detected: None,
            fields: None,
            incident_type_uuid: None,
            is_test: None,
            modified: None,
            non_datadog_creator: None,
            notification_handles: None,
            public_id: None,
            resolved: None,
            severity: None,
            state: None,
            time_to_detect: None,
            time_to_internal_response: None,
            time_to_repair: None,
            time_to_resolve: None,
            title,
            visibility: None,
            additional_properties: std::collections::BTreeMap::new(),
            _unparsed: false,
        }
    }

    pub fn archived(mut self, value: Option<chrono::DateTime<chrono::Utc>>) -> Self {
        self.archived = Some(value);
        self
    }

    pub fn case_id(mut self, value: Option<i64>) -> Self {
        self.case_id = Some(value);
        self
    }

    pub fn created(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
        self.created = Some(value);
        self
    }

    pub fn customer_impact_duration(mut self, value: i64) -> Self {
        self.customer_impact_duration = Some(value);
        self
    }

    pub fn customer_impact_end(mut self, value: Option<chrono::DateTime<chrono::Utc>>) -> Self {
        self.customer_impact_end = Some(value);
        self
    }

    pub fn customer_impact_scope(mut self, value: Option<String>) -> Self {
        self.customer_impact_scope = Some(value);
        self
    }

    pub fn customer_impact_start(mut self, value: Option<chrono::DateTime<chrono::Utc>>) -> Self {
        self.customer_impact_start = Some(value);
        self
    }

    pub fn customer_impacted(mut self, value: bool) -> Self {
        self.customer_impacted = Some(value);
        self
    }

    pub fn declared(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
        self.declared = Some(value);
        self
    }

    pub fn declared_by(
        mut self,
        value: Option<crate::datadogV2::model::IncidentNonDatadogCreator>,
    ) -> Self {
        self.declared_by = Some(value);
        self
    }

    pub fn declared_by_uuid(mut self, value: Option<String>) -> Self {
        self.declared_by_uuid = Some(value);
        self
    }

    pub fn detected(mut self, value: Option<chrono::DateTime<chrono::Utc>>) -> Self {
        self.detected = Some(value);
        self
    }

    pub fn fields(
        mut self,
        value: std::collections::BTreeMap<String, crate::datadogV2::model::IncidentFieldAttributes>,
    ) -> Self {
        self.fields = Some(value);
        self
    }

    pub fn incident_type_uuid(mut self, value: String) -> Self {
        self.incident_type_uuid = Some(value);
        self
    }

    pub fn is_test(mut self, value: bool) -> Self {
        self.is_test = Some(value);
        self
    }

    pub fn modified(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
        self.modified = Some(value);
        self
    }

    pub fn non_datadog_creator(
        mut self,
        value: Option<crate::datadogV2::model::IncidentNonDatadogCreator>,
    ) -> Self {
        self.non_datadog_creator = Some(value);
        self
    }

    pub fn notification_handles(
        mut self,
        value: Option<Vec<crate::datadogV2::model::IncidentNotificationHandle>>,
    ) -> Self {
        self.notification_handles = Some(value);
        self
    }

    pub fn public_id(mut self, value: i64) -> Self {
        self.public_id = Some(value);
        self
    }

    pub fn resolved(mut self, value: Option<chrono::DateTime<chrono::Utc>>) -> Self {
        self.resolved = Some(value);
        self
    }

    pub fn severity(mut self, value: crate::datadogV2::model::IncidentSeverity) -> Self {
        self.severity = Some(value);
        self
    }

    pub fn state(mut self, value: Option<String>) -> Self {
        self.state = Some(value);
        self
    }

    pub fn time_to_detect(mut self, value: i64) -> Self {
        self.time_to_detect = Some(value);
        self
    }

    pub fn time_to_internal_response(mut self, value: i64) -> Self {
        self.time_to_internal_response = Some(value);
        self
    }

    pub fn time_to_repair(mut self, value: i64) -> Self {
        self.time_to_repair = Some(value);
        self
    }

    pub fn time_to_resolve(mut self, value: i64) -> Self {
        self.time_to_resolve = Some(value);
        self
    }

    pub fn visibility(mut self, value: Option<String>) -> Self {
        self.visibility = Some(value);
        self
    }

    pub fn additional_properties(
        mut self,
        value: std::collections::BTreeMap<String, serde_json::Value>,
    ) -> Self {
        self.additional_properties = value;
        self
    }
}

impl<'de> Deserialize<'de> for IncidentResponseAttributes {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: Deserializer<'de>,
    {
        struct IncidentResponseAttributesVisitor;
        impl<'a> Visitor<'a> for IncidentResponseAttributesVisitor {
            type Value = IncidentResponseAttributes;

            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
                f.write_str("a mapping")
            }

            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
            where
                M: MapAccess<'a>,
            {
                let mut archived: Option<Option<chrono::DateTime<chrono::Utc>>> = None;
                let mut case_id: Option<Option<i64>> = None;
                let mut created: Option<chrono::DateTime<chrono::Utc>> = None;
                let mut customer_impact_duration: Option<i64> = None;
                let mut customer_impact_end: Option<Option<chrono::DateTime<chrono::Utc>>> = None;
                let mut customer_impact_scope: Option<Option<String>> = None;
                let mut customer_impact_start: Option<Option<chrono::DateTime<chrono::Utc>>> = None;
                let mut customer_impacted: Option<bool> = None;
                let mut declared: Option<chrono::DateTime<chrono::Utc>> = None;
                let mut declared_by: Option<
                    Option<crate::datadogV2::model::IncidentNonDatadogCreator>,
                > = None;
                let mut declared_by_uuid: Option<Option<String>> = None;
                let mut detected: Option<Option<chrono::DateTime<chrono::Utc>>> = None;
                let mut fields: Option<
                    std::collections::BTreeMap<
                        String,
                        crate::datadogV2::model::IncidentFieldAttributes,
                    >,
                > = None;
                let mut incident_type_uuid: Option<String> = None;
                let mut is_test: Option<bool> = None;
                let mut modified: Option<chrono::DateTime<chrono::Utc>> = None;
                let mut non_datadog_creator: Option<
                    Option<crate::datadogV2::model::IncidentNonDatadogCreator>,
                > = None;
                let mut notification_handles: Option<
                    Option<Vec<crate::datadogV2::model::IncidentNotificationHandle>>,
                > = None;
                let mut public_id: Option<i64> = None;
                let mut resolved: Option<Option<chrono::DateTime<chrono::Utc>>> = None;
                let mut severity: Option<crate::datadogV2::model::IncidentSeverity> = None;
                let mut state: Option<Option<String>> = None;
                let mut time_to_detect: Option<i64> = None;
                let mut time_to_internal_response: Option<i64> = None;
                let mut time_to_repair: Option<i64> = None;
                let mut time_to_resolve: Option<i64> = None;
                let mut title: Option<String> = None;
                let mut visibility: Option<Option<String>> = None;
                let mut additional_properties: std::collections::BTreeMap<
                    String,
                    serde_json::Value,
                > = std::collections::BTreeMap::new();
                let mut _unparsed = false;

                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
                    match k.as_str() {
                        "archived" => {
                            archived = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "case_id" => {
                            case_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "created" => {
                            if v.is_null() {
                                continue;
                            }
                            created = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "customer_impact_duration" => {
                            if v.is_null() {
                                continue;
                            }
                            customer_impact_duration =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "customer_impact_end" => {
                            customer_impact_end =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "customer_impact_scope" => {
                            customer_impact_scope =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "customer_impact_start" => {
                            customer_impact_start =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "customer_impacted" => {
                            if v.is_null() {
                                continue;
                            }
                            customer_impacted =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "declared" => {
                            if v.is_null() {
                                continue;
                            }
                            declared = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "declared_by" => {
                            declared_by =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "declared_by_uuid" => {
                            declared_by_uuid =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "detected" => {
                            detected = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "fields" => {
                            if v.is_null() {
                                continue;
                            }
                            fields = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "incident_type_uuid" => {
                            if v.is_null() {
                                continue;
                            }
                            incident_type_uuid =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "is_test" => {
                            if v.is_null() {
                                continue;
                            }
                            is_test = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "modified" => {
                            if v.is_null() {
                                continue;
                            }
                            modified = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "non_datadog_creator" => {
                            non_datadog_creator =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "notification_handles" => {
                            notification_handles =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "public_id" => {
                            if v.is_null() {
                                continue;
                            }
                            public_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "resolved" => {
                            resolved = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "severity" => {
                            if v.is_null() {
                                continue;
                            }
                            severity = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                            if let Some(ref _severity) = severity {
                                match _severity {
                                    crate::datadogV2::model::IncidentSeverity::UnparsedObject(
                                        _severity,
                                    ) => {
                                        _unparsed = true;
                                    }
                                    _ => {}
                                }
                            }
                        }
                        "state" => {
                            state = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "time_to_detect" => {
                            if v.is_null() {
                                continue;
                            }
                            time_to_detect =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "time_to_internal_response" => {
                            if v.is_null() {
                                continue;
                            }
                            time_to_internal_response =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "time_to_repair" => {
                            if v.is_null() {
                                continue;
                            }
                            time_to_repair =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "time_to_resolve" => {
                            if v.is_null() {
                                continue;
                            }
                            time_to_resolve =
                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "title" => {
                            title = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        "visibility" => {
                            visibility = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
                        }
                        &_ => {
                            if let Ok(value) = serde_json::from_value(v.clone()) {
                                additional_properties.insert(k, value);
                            }
                        }
                    }
                }
                let title = title.ok_or_else(|| M::Error::missing_field("title"))?;

                let content = IncidentResponseAttributes {
                    archived,
                    case_id,
                    created,
                    customer_impact_duration,
                    customer_impact_end,
                    customer_impact_scope,
                    customer_impact_start,
                    customer_impacted,
                    declared,
                    declared_by,
                    declared_by_uuid,
                    detected,
                    fields,
                    incident_type_uuid,
                    is_test,
                    modified,
                    non_datadog_creator,
                    notification_handles,
                    public_id,
                    resolved,
                    severity,
                    state,
                    time_to_detect,
                    time_to_internal_response,
                    time_to_repair,
                    time_to_resolve,
                    title,
                    visibility,
                    additional_properties,
                    _unparsed,
                };

                Ok(content)
            }
        }

        deserializer.deserialize_any(IncidentResponseAttributesVisitor)
    }
}