v2_service_definition_CreateOrUpdateServiceDefinitions_2621709423/
v2_service-definition_CreateOrUpdateServiceDefinitions_2621709423.rs1use datadog_api_client::datadog;
3use datadog_api_client::datadogV2::api_service_definition::ServiceDefinitionAPI;
4use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot2;
5use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot2Contact;
6use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot2Integrations;
7use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot2Link;
8use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot2Opsgenie;
9use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot2OpsgenieRegion;
10use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot2Pagerduty;
11use datadog_api_client::datadogV2::model::ServiceDefinitionV2Dot2Version;
12use datadog_api_client::datadogV2::model::ServiceDefinitionsCreateRequest;
13use serde_json::Value;
14use std::collections::BTreeMap;
15
16#[tokio::main]
17async fn main() {
18    let body = ServiceDefinitionsCreateRequest::ServiceDefinitionV2Dot2(Box::new(
19        ServiceDefinitionV2Dot2::new(
20            "service-exampleservicedefinition".to_string(),
21            ServiceDefinitionV2Dot2Version::V2_2,
22        )
23        .contacts(vec![ServiceDefinitionV2Dot2Contact::new(
24            "contact@datadoghq.com".to_string(),
25            "email".to_string(),
26        )
27        .name("Team Email".to_string())])
28        .extensions(BTreeMap::from([(
29            "myorgextension".to_string(),
30            Value::from("extensionvalue"),
31        )]))
32        .integrations(
33            ServiceDefinitionV2Dot2Integrations::new()
34                .opsgenie(
35                    ServiceDefinitionV2Dot2Opsgenie::new(
36                        "https://my-org.opsgenie.com/service/123e4567-e89b-12d3-a456-426614174000"
37                            .to_string(),
38                    )
39                    .region(ServiceDefinitionV2Dot2OpsgenieRegion::US),
40                )
41                .pagerduty(ServiceDefinitionV2Dot2Pagerduty::new().service_url(
42                    "https://my-org.pagerduty.com/service-directory/PMyService".to_string(),
43                )),
44        )
45        .links(vec![
46            ServiceDefinitionV2Dot2Link::new(
47                "Runbook".to_string(),
48                "runbook".to_string(),
49                "https://my-runbook".to_string(),
50            ),
51            ServiceDefinitionV2Dot2Link::new(
52                "Source Code".to_string(),
53                "repo".to_string(),
54                "https://github.com/DataDog/schema".to_string(),
55            )
56            .provider("GitHub".to_string()),
57            ServiceDefinitionV2Dot2Link::new(
58                "Architecture".to_string(),
59                "doc".to_string(),
60                "https://my-runbook".to_string(),
61            )
62            .provider("Gigoogle drivetHub".to_string()),
63        ])
64        .tags(vec!["my:tag".to_string(), "service:tag".to_string()])
65        .team("my-team".to_string()),
66    ));
67    let configuration = datadog::Configuration::new();
68    let api = ServiceDefinitionAPI::with_config(configuration);
69    let resp = api.create_or_update_service_definitions(body).await;
70    if let Ok(value) = resp {
71        println!("{:#?}", value);
72    } else {
73        println!("{:#?}", resp.unwrap_err());
74    }
75}