datadog_api_client/datadogV2/model/
model_security_monitoring_signal_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/// The object containing all signal attributes and their
10/// associated values.
11#[non_exhaustive]
12#[skip_serializing_none]
13#[derive(Clone, Debug, PartialEq, Serialize)]
14pub struct SecurityMonitoringSignalAttributes {
15    /// A JSON object of attributes in the security signal.
16    #[serde(rename = "custom")]
17    pub custom: Option<std::collections::BTreeMap<String, serde_json::Value>>,
18    /// The message in the security signal defined by the rule that generated the signal.
19    #[serde(rename = "message")]
20    pub message: Option<String>,
21    /// An array of tags associated with the security signal.
22    #[serde(rename = "tags")]
23    pub tags: Option<Vec<String>>,
24    /// The timestamp of the security signal.
25    #[serde(rename = "timestamp")]
26    pub timestamp: Option<chrono::DateTime<chrono::Utc>>,
27    #[serde(flatten)]
28    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
29    #[serde(skip)]
30    #[serde(default)]
31    pub(crate) _unparsed: bool,
32}
33
34impl SecurityMonitoringSignalAttributes {
35    pub fn new() -> SecurityMonitoringSignalAttributes {
36        SecurityMonitoringSignalAttributes {
37            custom: None,
38            message: None,
39            tags: None,
40            timestamp: None,
41            additional_properties: std::collections::BTreeMap::new(),
42            _unparsed: false,
43        }
44    }
45
46    pub fn custom(mut self, value: std::collections::BTreeMap<String, serde_json::Value>) -> Self {
47        self.custom = Some(value);
48        self
49    }
50
51    pub fn message(mut self, value: String) -> Self {
52        self.message = Some(value);
53        self
54    }
55
56    pub fn tags(mut self, value: Vec<String>) -> Self {
57        self.tags = Some(value);
58        self
59    }
60
61    pub fn timestamp(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
62        self.timestamp = Some(value);
63        self
64    }
65
66    pub fn additional_properties(
67        mut self,
68        value: std::collections::BTreeMap<String, serde_json::Value>,
69    ) -> Self {
70        self.additional_properties = value;
71        self
72    }
73}
74
75impl Default for SecurityMonitoringSignalAttributes {
76    fn default() -> Self {
77        Self::new()
78    }
79}
80
81impl<'de> Deserialize<'de> for SecurityMonitoringSignalAttributes {
82    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
83    where
84        D: Deserializer<'de>,
85    {
86        struct SecurityMonitoringSignalAttributesVisitor;
87        impl<'a> Visitor<'a> for SecurityMonitoringSignalAttributesVisitor {
88            type Value = SecurityMonitoringSignalAttributes;
89
90            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
91                f.write_str("a mapping")
92            }
93
94            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
95            where
96                M: MapAccess<'a>,
97            {
98                let mut custom: Option<std::collections::BTreeMap<String, serde_json::Value>> =
99                    None;
100                let mut message: Option<String> = None;
101                let mut tags: Option<Vec<String>> = None;
102                let mut timestamp: Option<chrono::DateTime<chrono::Utc>> = None;
103                let mut additional_properties: std::collections::BTreeMap<
104                    String,
105                    serde_json::Value,
106                > = std::collections::BTreeMap::new();
107                let mut _unparsed = false;
108
109                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
110                    match k.as_str() {
111                        "custom" => {
112                            if v.is_null() {
113                                continue;
114                            }
115                            custom = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
116                        }
117                        "message" => {
118                            if v.is_null() {
119                                continue;
120                            }
121                            message = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
122                        }
123                        "tags" => {
124                            if v.is_null() {
125                                continue;
126                            }
127                            tags = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
128                        }
129                        "timestamp" => {
130                            if v.is_null() {
131                                continue;
132                            }
133                            timestamp = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
134                        }
135                        &_ => {
136                            if let Ok(value) = serde_json::from_value(v.clone()) {
137                                additional_properties.insert(k, value);
138                            }
139                        }
140                    }
141                }
142
143                let content = SecurityMonitoringSignalAttributes {
144                    custom,
145                    message,
146                    tags,
147                    timestamp,
148                    additional_properties,
149                    _unparsed,
150                };
151
152                Ok(content)
153            }
154        }
155
156        deserializer.deserialize_any(SecurityMonitoringSignalAttributesVisitor)
157    }
158}