v2_logs_custom_destinations_CreateLogsCustomDestination_1288180912/
v2_logs-custom-destinations_CreateLogsCustomDestination_1288180912.rs

1// Create a Splunk 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::CustomDestinationForwardDestinationSplunk;
10use datadog_api_client::datadogV2::model::CustomDestinationForwardDestinationSplunkType;
11use datadog_api_client::datadogV2::model::CustomDestinationType;
12
13#[tokio::main]
14async fn main() {
15    let body =
16        CustomDestinationCreateRequest::new().data(CustomDestinationCreateRequestDefinition::new(
17            CustomDestinationCreateRequestAttributes::new(
18                CustomDestinationForwardDestination::CustomDestinationForwardDestinationSplunk(
19                    Box::new(CustomDestinationForwardDestinationSplunk::new(
20                        "my-access-token".to_string(),
21                        "https://example.com".to_string(),
22                        CustomDestinationForwardDestinationSplunkType::SPLUNK_HEC,
23                    )),
24                ),
25                "Nginx logs".to_string(),
26            )
27            .enabled(false)
28            .forward_tags(false)
29            .forward_tags_restriction_list(vec!["datacenter".to_string(), "host".to_string()])
30            .forward_tags_restriction_list_type(
31                CustomDestinationAttributeTagsRestrictionListType::ALLOW_LIST,
32            )
33            .query("source:nginx".to_string()),
34            CustomDestinationType::CUSTOM_DESTINATION,
35        ));
36    let configuration = datadog::Configuration::new();
37    let api = LogsCustomDestinationsAPI::with_config(configuration);
38    let resp = api.create_logs_custom_destination(body).await;
39    if let Ok(value) = resp {
40        println!("{:#?}", value);
41    } else {
42        println!("{:#?}", resp.unwrap_err());
43    }
44}