v2_logs_custom_destinations_CreateLogsCustomDestination_1091442807/
v2_logs-custom-destinations_CreateLogsCustomDestination_1091442807.rs

1// Create a Custom Header HTTP custom destination returns "OK" response
2use datadog_api_client::datadog;
3use datadog_api_client::datadogV2::api_logs_custom_destinations::LogsCustomDestinationsAPI;
4use datadog_api_client::datadogV2::model::CustomDestinationAttributeTagsRestrictionListType;
5use datadog_api_client::datadogV2::model::CustomDestinationCreateRequest;
6use datadog_api_client::datadogV2::model::CustomDestinationCreateRequestAttributes;
7use datadog_api_client::datadogV2::model::CustomDestinationCreateRequestDefinition;
8use datadog_api_client::datadogV2::model::CustomDestinationForwardDestination;
9use datadog_api_client::datadogV2::model::CustomDestinationForwardDestinationHttp;
10use datadog_api_client::datadogV2::model::CustomDestinationForwardDestinationHttpType;
11use datadog_api_client::datadogV2::model::CustomDestinationHttpDestinationAuth;
12use datadog_api_client::datadogV2::model::CustomDestinationHttpDestinationAuthCustomHeader;
13use datadog_api_client::datadogV2::model::CustomDestinationHttpDestinationAuthCustomHeaderType;
14use datadog_api_client::datadogV2::model::CustomDestinationType;
15
16#[tokio::main]
17async fn main() {
18    let body =
19        CustomDestinationCreateRequest
20        ::new().data(
21            CustomDestinationCreateRequestDefinition::new(
22                CustomDestinationCreateRequestAttributes::new(
23                    CustomDestinationForwardDestination::CustomDestinationForwardDestinationHttp(
24                        Box::new(
25                            CustomDestinationForwardDestinationHttp::new(
26                                CustomDestinationHttpDestinationAuth::CustomDestinationHttpDestinationAuthCustomHeader(
27                                    Box::new(
28                                        CustomDestinationHttpDestinationAuthCustomHeader::new(
29                                            "MY-AUTHENTICATION-HEADER".to_string(),
30                                            "my-secret".to_string(),
31                                            CustomDestinationHttpDestinationAuthCustomHeaderType::CUSTOM_HEADER,
32                                        ),
33                                    ),
34                                ),
35                                "https://example.com".to_string(),
36                                CustomDestinationForwardDestinationHttpType::HTTP,
37                            ),
38                        ),
39                    ),
40                    "Nginx logs".to_string(),
41                )
42                    .enabled(false)
43                    .forward_tags(false)
44                    .forward_tags_restriction_list(vec!["datacenter".to_string(), "host".to_string()])
45                    .forward_tags_restriction_list_type(CustomDestinationAttributeTagsRestrictionListType::ALLOW_LIST)
46                    .query("source:nginx".to_string()),
47                CustomDestinationType::CUSTOM_DESTINATION,
48            ),
49        );
50    let configuration = datadog::Configuration::new();
51    let api = LogsCustomDestinationsAPI::with_config(configuration);
52    let resp = api.create_logs_custom_destination(body).await;
53    if let Ok(value) = resp {
54        println!("{:#?}", value);
55    } else {
56        println!("{:#?}", resp.unwrap_err());
57    }
58}