v2_incidents_CreateIncidentNotificationTemplate/
v2_incidents_CreateIncidentNotificationTemplate.rs

1// Create incident notification template returns "Created" response
2use datadog_api_client::datadog;
3use datadog_api_client::datadogV2::api_incidents::IncidentsAPI;
4use datadog_api_client::datadogV2::model::CreateIncidentNotificationTemplateRequest;
5use datadog_api_client::datadogV2::model::IncidentNotificationTemplateCreateAttributes;
6use datadog_api_client::datadogV2::model::IncidentNotificationTemplateCreateData;
7use datadog_api_client::datadogV2::model::IncidentNotificationTemplateCreateDataRelationships;
8use datadog_api_client::datadogV2::model::IncidentNotificationTemplateType;
9use datadog_api_client::datadogV2::model::IncidentTypeType;
10use datadog_api_client::datadogV2::model::RelationshipToIncidentType;
11use datadog_api_client::datadogV2::model::RelationshipToIncidentTypeData;
12
13#[tokio::main]
14async fn main() {
15    // there is a valid "incident_type" in the system
16    let incident_type_data_id = std::env::var("INCIDENT_TYPE_DATA_ID").unwrap();
17    let body = CreateIncidentNotificationTemplateRequest::new(
18        IncidentNotificationTemplateCreateData::new(
19            IncidentNotificationTemplateCreateAttributes::new(
20                "alert".to_string(),
21                r#"An incident has been declared.
22
23Title: Sample Incident Title
24Severity: SEV-2
25Affected Services: web-service, database-service
26Status: active
27
28Please join the incident channel for updates."#
29                    .to_string(),
30                "Example-Incident".to_string(),
31                "SEV-2 Incident: Sample Incident Title".to_string(),
32            ),
33            IncidentNotificationTemplateType::NOTIFICATION_TEMPLATES,
34        )
35        .relationships(
36            IncidentNotificationTemplateCreateDataRelationships::new().incident_type(
37                RelationshipToIncidentType::new(RelationshipToIncidentTypeData::new(
38                    incident_type_data_id.clone(),
39                    IncidentTypeType::INCIDENT_TYPES,
40                )),
41            ),
42        ),
43    );
44    let mut configuration = datadog::Configuration::new();
45    configuration.set_unstable_operation_enabled("v2.CreateIncidentNotificationTemplate", true);
46    let api = IncidentsAPI::with_config(configuration);
47    let resp = api.create_incident_notification_template(body).await;
48    if let Ok(value) = resp {
49        println!("{:#?}", value);
50    } else {
51        println!("{:#?}", resp.unwrap_err());
52    }
53}