v2_security_monitoring_CreateSignalNotificationRule/
v2_security-monitoring_CreateSignalNotificationRule.rs

1// Create a new signal-based notification rule returns "Successfully created the
2// notification rule." response
3use datadog_api_client::datadog;
4use datadog_api_client::datadogV2::api_security_monitoring::SecurityMonitoringAPI;
5use datadog_api_client::datadogV2::model::CreateNotificationRuleParameters;
6use datadog_api_client::datadogV2::model::CreateNotificationRuleParametersData;
7use datadog_api_client::datadogV2::model::CreateNotificationRuleParametersDataAttributes;
8use datadog_api_client::datadogV2::model::NotificationRulesType;
9use datadog_api_client::datadogV2::model::RuleSeverity;
10use datadog_api_client::datadogV2::model::RuleTypesItems;
11use datadog_api_client::datadogV2::model::Selectors;
12use datadog_api_client::datadogV2::model::TriggerSource;
13
14#[tokio::main]
15async fn main() {
16    let body =
17        CreateNotificationRuleParameters::new().data(CreateNotificationRuleParametersData::new(
18            CreateNotificationRuleParametersDataAttributes::new(
19                "Rule 1".to_string(),
20                Selectors::new(TriggerSource::SECURITY_FINDINGS)
21                    .query("(source:production_service OR env:prod)".to_string())
22                    .rule_types(vec![
23                        RuleTypesItems::MISCONFIGURATION,
24                        RuleTypesItems::ATTACK_PATH,
25                    ])
26                    .severities(vec![RuleSeverity::CRITICAL]),
27                vec!["@john.doe@email.com".to_string()],
28            )
29            .enabled(true)
30            .time_aggregation(86400),
31            NotificationRulesType::NOTIFICATION_RULES,
32        ));
33    let configuration = datadog::Configuration::new();
34    let api = SecurityMonitoringAPI::with_config(configuration);
35    let resp = api.create_signal_notification_rule(body).await;
36    if let Ok(value) = resp {
37        println!("{:#?}", value);
38    } else {
39        println!("{:#?}", resp.unwrap_err());
40    }
41}