v2_incidents_CreateIncidentNotificationRule/
v2_incidents_CreateIncidentNotificationRule.rs

1// Create an incident notification rule returns "Created" response
2use datadog_api_client::datadog;
3use datadog_api_client::datadogV2::api_incidents::IncidentsAPI;
4use datadog_api_client::datadogV2::model::CreateIncidentNotificationRuleRequest;
5use datadog_api_client::datadogV2::model::IncidentNotificationRuleConditionsItems;
6use datadog_api_client::datadogV2::model::IncidentNotificationRuleCreateAttributes;
7use datadog_api_client::datadogV2::model::IncidentNotificationRuleCreateAttributesVisibility;
8use datadog_api_client::datadogV2::model::IncidentNotificationRuleCreateData;
9use datadog_api_client::datadogV2::model::IncidentNotificationRuleCreateDataRelationships;
10use datadog_api_client::datadogV2::model::IncidentNotificationRuleType;
11use datadog_api_client::datadogV2::model::IncidentNotificationTemplateType;
12use datadog_api_client::datadogV2::model::IncidentTypeType;
13use datadog_api_client::datadogV2::model::RelationshipToIncidentNotificationTemplate;
14use datadog_api_client::datadogV2::model::RelationshipToIncidentNotificationTemplateData;
15use datadog_api_client::datadogV2::model::RelationshipToIncidentType;
16use datadog_api_client::datadogV2::model::RelationshipToIncidentTypeData;
17use uuid::Uuid;
18
19#[tokio::main]
20async fn main() {
21    let body = CreateIncidentNotificationRuleRequest::new(
22        IncidentNotificationRuleCreateData::new(
23            IncidentNotificationRuleCreateAttributes::new(
24                vec![IncidentNotificationRuleConditionsItems::new(
25                    "severity".to_string(),
26                    vec!["SEV-1".to_string(), "SEV-2".to_string()],
27                )],
28                vec![
29                    "@team-email@company.com".to_string(),
30                    "@slack-channel".to_string(),
31                ],
32                "incident_created_trigger".to_string(),
33            )
34            .enabled(true)
35            .renotify_on(vec!["status".to_string(), "severity".to_string()])
36            .visibility(IncidentNotificationRuleCreateAttributesVisibility::ORGANIZATION),
37            IncidentNotificationRuleType::INCIDENT_NOTIFICATION_RULES,
38        )
39        .relationships(
40            IncidentNotificationRuleCreateDataRelationships::new()
41                .incident_type(RelationshipToIncidentType::new(
42                    RelationshipToIncidentTypeData::new(
43                        "00000000-0000-0000-0000-000000000000".to_string(),
44                        IncidentTypeType::INCIDENT_TYPES,
45                    ),
46                ))
47                .notification_template(RelationshipToIncidentNotificationTemplate::new(
48                    RelationshipToIncidentNotificationTemplateData::new(
49                        Uuid::parse_str("00000000-0000-0000-0000-000000000001")
50                            .expect("invalid UUID"),
51                        IncidentNotificationTemplateType::NOTIFICATION_TEMPLATES,
52                    ),
53                )),
54        ),
55    );
56    let mut configuration = datadog::Configuration::new();
57    configuration.set_unstable_operation_enabled("v2.CreateIncidentNotificationRule", true);
58    let api = IncidentsAPI::with_config(configuration);
59    let resp = api.create_incident_notification_rule(body).await;
60    if let Ok(value) = resp {
61        println!("{:#?}", value);
62    } else {
63        println!("{:#?}", resp.unwrap_err());
64    }
65}