datadog_api_client/datadogV2/model/
model_observability_pipeline_rsyslog_source.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 `rsyslog` source listens for logs over TCP or UDP from an `rsyslog` server using the syslog protocol.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct ObservabilityPipelineRsyslogSource {
14    /// The unique identifier for this component. Used to reference this component in other parts of the pipeline (e.g., as input to downstream components).
15    #[serde(rename = "id")]
16    pub id: String,
17    /// Protocol used by the syslog source to receive messages.
18    #[serde(rename = "mode")]
19    pub mode: crate::datadogV2::model::ObservabilityPipelineSyslogSourceMode,
20    /// Configuration for enabling TLS encryption between the pipeline component and external services.
21    #[serde(rename = "tls")]
22    pub tls: Option<crate::datadogV2::model::ObservabilityPipelineTls>,
23    /// The source type. The value should always be `rsyslog`.
24    #[serde(rename = "type")]
25    pub type_: crate::datadogV2::model::ObservabilityPipelineRsyslogSourceType,
26    #[serde(flatten)]
27    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
28    #[serde(skip)]
29    #[serde(default)]
30    pub(crate) _unparsed: bool,
31}
32
33impl ObservabilityPipelineRsyslogSource {
34    pub fn new(
35        id: String,
36        mode: crate::datadogV2::model::ObservabilityPipelineSyslogSourceMode,
37        type_: crate::datadogV2::model::ObservabilityPipelineRsyslogSourceType,
38    ) -> ObservabilityPipelineRsyslogSource {
39        ObservabilityPipelineRsyslogSource {
40            id,
41            mode,
42            tls: None,
43            type_,
44            additional_properties: std::collections::BTreeMap::new(),
45            _unparsed: false,
46        }
47    }
48
49    pub fn tls(mut self, value: crate::datadogV2::model::ObservabilityPipelineTls) -> Self {
50        self.tls = Some(value);
51        self
52    }
53
54    pub fn additional_properties(
55        mut self,
56        value: std::collections::BTreeMap<String, serde_json::Value>,
57    ) -> Self {
58        self.additional_properties = value;
59        self
60    }
61}
62
63impl<'de> Deserialize<'de> for ObservabilityPipelineRsyslogSource {
64    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
65    where
66        D: Deserializer<'de>,
67    {
68        struct ObservabilityPipelineRsyslogSourceVisitor;
69        impl<'a> Visitor<'a> for ObservabilityPipelineRsyslogSourceVisitor {
70            type Value = ObservabilityPipelineRsyslogSource;
71
72            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
73                f.write_str("a mapping")
74            }
75
76            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
77            where
78                M: MapAccess<'a>,
79            {
80                let mut id: Option<String> = None;
81                let mut mode: Option<
82                    crate::datadogV2::model::ObservabilityPipelineSyslogSourceMode,
83                > = None;
84                let mut tls: Option<crate::datadogV2::model::ObservabilityPipelineTls> = None;
85                let mut type_: Option<
86                    crate::datadogV2::model::ObservabilityPipelineRsyslogSourceType,
87                > = None;
88                let mut additional_properties: std::collections::BTreeMap<
89                    String,
90                    serde_json::Value,
91                > = std::collections::BTreeMap::new();
92                let mut _unparsed = false;
93
94                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
95                    match k.as_str() {
96                        "id" => {
97                            id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
98                        }
99                        "mode" => {
100                            mode = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
101                            if let Some(ref _mode) = mode {
102                                match _mode {
103                                    crate::datadogV2::model::ObservabilityPipelineSyslogSourceMode::UnparsedObject(_mode) => {
104                                        _unparsed = true;
105                                    },
106                                    _ => {}
107                                }
108                            }
109                        }
110                        "tls" => {
111                            if v.is_null() {
112                                continue;
113                            }
114                            tls = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
115                        }
116                        "type" => {
117                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
118                            if let Some(ref _type_) = type_ {
119                                match _type_ {
120                                    crate::datadogV2::model::ObservabilityPipelineRsyslogSourceType::UnparsedObject(_type_) => {
121                                        _unparsed = true;
122                                    },
123                                    _ => {}
124                                }
125                            }
126                        }
127                        &_ => {
128                            if let Ok(value) = serde_json::from_value(v.clone()) {
129                                additional_properties.insert(k, value);
130                            }
131                        }
132                    }
133                }
134                let id = id.ok_or_else(|| M::Error::missing_field("id"))?;
135                let mode = mode.ok_or_else(|| M::Error::missing_field("mode"))?;
136                let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
137
138                let content = ObservabilityPipelineRsyslogSource {
139                    id,
140                    mode,
141                    tls,
142                    type_,
143                    additional_properties,
144                    _unparsed,
145                };
146
147                Ok(content)
148            }
149        }
150
151        deserializer.deserialize_any(ObservabilityPipelineRsyslogSourceVisitor)
152    }
153}