diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 17509b568..a0d181216 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -29565,6 +29565,8 @@ components: additionalProperties: false description: Attributes of the monitor notification rule. properties: + conditional_recipients: + $ref: '#/components/schemas/MonitorNotificationRuleConditionalRecipients' filter: $ref: '#/components/schemas/MonitorNotificationRuleFilter' name: @@ -29573,8 +29575,36 @@ components: $ref: '#/components/schemas/MonitorNotificationRuleRecipients' required: - name + type: object + MonitorNotificationRuleCondition: + description: Conditions for `conditional_recipients`. + properties: + recipients: + $ref: '#/components/schemas/MonitorNotificationRuleRecipients' + scope: + $ref: '#/components/schemas/MonitorNotificationRuleScope' + required: + - scope - recipients type: object + MonitorNotificationRuleConditionalRecipients: + description: Use conditional recipients to define different recipients for different + situations. + properties: + conditions: + description: Conditions of the notification rule. + items: + $ref: '#/components/schemas/MonitorNotificationRuleCondition' + maxItems: 10 + minItems: 1 + type: array + fallback_recipients: + $ref: '#/components/schemas/MonitorNotificationRuleRecipients' + description: If none of the `conditions` applied, `fallback_recipients` + will get notified. + required: + - conditions + type: object MonitorNotificationRuleCreateRequest: description: Request for creating a monitor notification rule. properties: @@ -29714,6 +29744,8 @@ components: additionalProperties: {} description: Attributes of the monitor notification rule. properties: + conditional_recipients: + $ref: '#/components/schemas/MonitorNotificationRuleConditionalRecipients' created: description: Creation time of the monitor notification rule. example: 2020-01-02 03:04:00+00:00 @@ -29735,6 +29767,12 @@ components: description: An object related to a monitor notification rule. oneOf: - $ref: '#/components/schemas/User' + MonitorNotificationRuleScope: + description: The scope to which the monitor applied. + example: transition_type:alert + maxLength: 3000 + minLength: 1 + type: string MonitorNotificationRuleUpdateRequest: description: Request for updating a monitor notification rule. properties: diff --git a/LICENSE-3rdparty.csv b/LICENSE-3rdparty.csv index 62d19e475..ffd05ed70 100644 --- a/LICENSE-3rdparty.csv +++ b/LICENSE-3rdparty.csv @@ -129,6 +129,7 @@ serde_json,https://github.com/serde-rs/json,MIT OR Apache-2.0,"Erick Tryzelaar < serde_urlencoded,https://github.com/nox/serde_urlencoded,MIT OR Apache-2.0,Anthony Ramine serde_with,https://github.com/jonasbb/serde_with,MIT OR Apache-2.0,"Jonas Bushart, Marcin Kaźmierczak" serde_with_macros,https://github.com/jonasbb/serde_with,MIT OR Apache-2.0,Jonas Bushart +simd-adler32,https://github.com/mcountryman/simd-adler32,MIT,Marvin Countryman slab,https://github.com/tokio-rs/slab,MIT,Carl Lerche smallvec,https://github.com/servo/rust-smallvec,MIT OR Apache-2.0,The Servo Project Developers socket2,https://github.com/rust-lang/socket2,MIT OR Apache-2.0,"Alex Crichton , Thomas de Zeeuw " diff --git a/examples/v2_monitors_CreateMonitorNotificationRule.rs b/examples/v2_monitors_CreateMonitorNotificationRule.rs index 99d1c7645..0e31b6fae 100644 --- a/examples/v2_monitors_CreateMonitorNotificationRule.rs +++ b/examples/v2_monitors_CreateMonitorNotificationRule.rs @@ -12,17 +12,18 @@ use datadog_api_client::datadogV2::model::MonitorNotificationRuleResourceType; async fn main() { let body = MonitorNotificationRuleCreateRequest::new( MonitorNotificationRuleCreateRequestData::new( - MonitorNotificationRuleAttributes::new( - "test rule".to_string(), - vec!["slack-test-channel".to_string(), "jira-test".to_string()], - ) - .filter( - MonitorNotificationRuleFilter::MonitorNotificationRuleFilterTags(Box::new( - MonitorNotificationRuleFilterTags::new( - vec!["test:example-monitor".to_string()], - ), - )), - ), + MonitorNotificationRuleAttributes::new("test rule".to_string()) + .filter( + MonitorNotificationRuleFilter::MonitorNotificationRuleFilterTags(Box::new( + MonitorNotificationRuleFilterTags::new(vec![ + "test:example-monitor".to_string() + ]), + )), + ) + .recipients(vec![ + "slack-test-channel".to_string(), + "jira-test".to_string(), + ]), ) .type_(MonitorNotificationRuleResourceType::MONITOR_NOTIFICATION_RULE), ); diff --git a/examples/v2_monitors_CreateMonitorNotificationRule_1181818787.rs b/examples/v2_monitors_CreateMonitorNotificationRule_1181818787.rs new file mode 100644 index 000000000..5de055411 --- /dev/null +++ b/examples/v2_monitors_CreateMonitorNotificationRule_1181818787.rs @@ -0,0 +1,43 @@ +// Create a monitor notification rule with conditional recipients returns "OK" +// response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_monitors::MonitorsAPI; +use datadog_api_client::datadogV2::model::MonitorNotificationRuleAttributes; +use datadog_api_client::datadogV2::model::MonitorNotificationRuleCondition; +use datadog_api_client::datadogV2::model::MonitorNotificationRuleConditionalRecipients; +use datadog_api_client::datadogV2::model::MonitorNotificationRuleCreateRequest; +use datadog_api_client::datadogV2::model::MonitorNotificationRuleCreateRequestData; +use datadog_api_client::datadogV2::model::MonitorNotificationRuleFilter; +use datadog_api_client::datadogV2::model::MonitorNotificationRuleFilterTags; +use datadog_api_client::datadogV2::model::MonitorNotificationRuleResourceType; + +#[tokio::main] +async fn main() { + let body = MonitorNotificationRuleCreateRequest::new( + MonitorNotificationRuleCreateRequestData::new( + MonitorNotificationRuleAttributes::new("test rule".to_string()) + .conditional_recipients(MonitorNotificationRuleConditionalRecipients::new(vec![ + MonitorNotificationRuleCondition::new( + vec!["slack-test-channel".to_string(), "jira-test".to_string()], + "transition_type:is_alert".to_string(), + ), + ])) + .filter( + MonitorNotificationRuleFilter::MonitorNotificationRuleFilterTags(Box::new( + MonitorNotificationRuleFilterTags::new(vec![ + "test:example-monitor".to_string() + ]), + )), + ), + ) + .type_(MonitorNotificationRuleResourceType::MONITOR_NOTIFICATION_RULE), + ); + let configuration = datadog::Configuration::new(); + let api = MonitorsAPI::with_config(configuration); + let resp = api.create_monitor_notification_rule(body).await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/examples/v2_monitors_UpdateMonitorNotificationRule.rs b/examples/v2_monitors_UpdateMonitorNotificationRule.rs index a1207b2bf..247708c0a 100644 --- a/examples/v2_monitors_UpdateMonitorNotificationRule.rs +++ b/examples/v2_monitors_UpdateMonitorNotificationRule.rs @@ -15,18 +15,16 @@ async fn main() { std::env::var("MONITOR_NOTIFICATION_RULE_DATA_ID").unwrap(); let body = MonitorNotificationRuleUpdateRequest::new( MonitorNotificationRuleUpdateRequestData::new( - MonitorNotificationRuleAttributes::new( - "updated rule".to_string(), - vec!["slack-test-channel".to_string()], - ) - .filter( - MonitorNotificationRuleFilter::MonitorNotificationRuleFilterTags(Box::new( - MonitorNotificationRuleFilterTags::new(vec![ - "test:example-monitor".to_string(), - "host:abc".to_string(), - ]), - )), - ), + MonitorNotificationRuleAttributes::new("updated rule".to_string()) + .filter( + MonitorNotificationRuleFilter::MonitorNotificationRuleFilterTags(Box::new( + MonitorNotificationRuleFilterTags::new(vec![ + "test:example-monitor".to_string(), + "host:abc".to_string(), + ]), + )), + ) + .recipients(vec!["slack-test-channel".to_string()]), monitor_notification_rule_data_id.clone(), ) .type_(MonitorNotificationRuleResourceType::MONITOR_NOTIFICATION_RULE), diff --git a/examples/v2_monitors_UpdateMonitorNotificationRule_1400905713.rs b/examples/v2_monitors_UpdateMonitorNotificationRule_1400905713.rs new file mode 100644 index 000000000..827eb1cb3 --- /dev/null +++ b/examples/v2_monitors_UpdateMonitorNotificationRule_1400905713.rs @@ -0,0 +1,50 @@ +// Update a monitor notification rule with conditional_recipients returns "OK" +// response +use datadog_api_client::datadog; +use datadog_api_client::datadogV2::api_monitors::MonitorsAPI; +use datadog_api_client::datadogV2::model::MonitorNotificationRuleAttributes; +use datadog_api_client::datadogV2::model::MonitorNotificationRuleCondition; +use datadog_api_client::datadogV2::model::MonitorNotificationRuleConditionalRecipients; +use datadog_api_client::datadogV2::model::MonitorNotificationRuleFilter; +use datadog_api_client::datadogV2::model::MonitorNotificationRuleFilterTags; +use datadog_api_client::datadogV2::model::MonitorNotificationRuleResourceType; +use datadog_api_client::datadogV2::model::MonitorNotificationRuleUpdateRequest; +use datadog_api_client::datadogV2::model::MonitorNotificationRuleUpdateRequestData; + +#[tokio::main] +async fn main() { + // there is a valid "monitor_notification_rule" in the system + let monitor_notification_rule_data_id = + std::env::var("MONITOR_NOTIFICATION_RULE_DATA_ID").unwrap(); + let body = MonitorNotificationRuleUpdateRequest::new( + MonitorNotificationRuleUpdateRequestData::new( + MonitorNotificationRuleAttributes::new("updated rule".to_string()) + .conditional_recipients(MonitorNotificationRuleConditionalRecipients::new(vec![ + MonitorNotificationRuleCondition::new( + vec!["slack-test-channel".to_string(), "jira-test".to_string()], + "transition_type:is_alert".to_string(), + ), + ])) + .filter( + MonitorNotificationRuleFilter::MonitorNotificationRuleFilterTags(Box::new( + MonitorNotificationRuleFilterTags::new(vec![ + "test:example-monitor".to_string(), + "host:abc".to_string(), + ]), + )), + ), + monitor_notification_rule_data_id.clone(), + ) + .type_(MonitorNotificationRuleResourceType::MONITOR_NOTIFICATION_RULE), + ); + let configuration = datadog::Configuration::new(); + let api = MonitorsAPI::with_config(configuration); + let resp = api + .update_monitor_notification_rule(monitor_notification_rule_data_id.clone(), body) + .await; + if let Ok(value) = resp { + println!("{:#?}", value); + } else { + println!("{:#?}", resp.unwrap_err()); + } +} diff --git a/src/datadogV2/model/mod.rs b/src/datadogV2/model/mod.rs index 6e3338c17..0a5ba6ecc 100644 --- a/src/datadogV2/model/mod.rs +++ b/src/datadogV2/model/mod.rs @@ -3428,6 +3428,10 @@ pub mod model_monitor_notification_rule_data; pub use self::model_monitor_notification_rule_data::MonitorNotificationRuleData; pub mod model_monitor_notification_rule_response_attributes; pub use self::model_monitor_notification_rule_response_attributes::MonitorNotificationRuleResponseAttributes; +pub mod model_monitor_notification_rule_conditional_recipients; +pub use self::model_monitor_notification_rule_conditional_recipients::MonitorNotificationRuleConditionalRecipients; +pub mod model_monitor_notification_rule_condition; +pub use self::model_monitor_notification_rule_condition::MonitorNotificationRuleCondition; pub mod model_monitor_notification_rule_filter_tags; pub use self::model_monitor_notification_rule_filter_tags::MonitorNotificationRuleFilterTags; pub mod model_monitor_notification_rule_filter; diff --git a/src/datadogV2/model/model_monitor_notification_rule_attributes.rs b/src/datadogV2/model/model_monitor_notification_rule_attributes.rs index 398cfdff6..dcb3666a3 100644 --- a/src/datadogV2/model/model_monitor_notification_rule_attributes.rs +++ b/src/datadogV2/model/model_monitor_notification_rule_attributes.rs @@ -11,6 +11,10 @@ use std::fmt::{self, Formatter}; #[skip_serializing_none] #[derive(Clone, Debug, PartialEq, Serialize)] pub struct MonitorNotificationRuleAttributes { + /// Use conditional recipients to define different recipients for different situations. + #[serde(rename = "conditional_recipients")] + pub conditional_recipients: + Option, /// Filter used to associate the notification rule with monitors. #[serde(rename = "filter")] pub filter: Option, @@ -19,26 +23,40 @@ pub struct MonitorNotificationRuleAttributes { pub name: String, /// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'. #[serde(rename = "recipients")] - pub recipients: Vec, + pub recipients: Option>, #[serde(skip)] #[serde(default)] pub(crate) _unparsed: bool, } impl MonitorNotificationRuleAttributes { - pub fn new(name: String, recipients: Vec) -> MonitorNotificationRuleAttributes { + pub fn new(name: String) -> MonitorNotificationRuleAttributes { MonitorNotificationRuleAttributes { + conditional_recipients: None, filter: None, name, - recipients, + recipients: None, _unparsed: false, } } + pub fn conditional_recipients( + mut self, + value: crate::datadogV2::model::MonitorNotificationRuleConditionalRecipients, + ) -> Self { + self.conditional_recipients = Some(value); + self + } + pub fn filter(mut self, value: crate::datadogV2::model::MonitorNotificationRuleFilter) -> Self { self.filter = Some(value); self } + + pub fn recipients(mut self, value: Vec) -> Self { + self.recipients = Some(value); + self + } } impl<'de> Deserialize<'de> for MonitorNotificationRuleAttributes { @@ -58,6 +76,9 @@ impl<'de> Deserialize<'de> for MonitorNotificationRuleAttributes { where M: MapAccess<'a>, { + let mut conditional_recipients: Option< + crate::datadogV2::model::MonitorNotificationRuleConditionalRecipients, + > = None; let mut filter: Option = None; let mut name: Option = None; @@ -66,6 +87,13 @@ impl<'de> Deserialize<'de> for MonitorNotificationRuleAttributes { while let Some((k, v)) = map.next_entry::()? { match k.as_str() { + "conditional_recipients" => { + if v.is_null() { + continue; + } + conditional_recipients = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } "filter" => { if v.is_null() { continue; @@ -84,6 +112,9 @@ impl<'de> Deserialize<'de> for MonitorNotificationRuleAttributes { name = Some(serde_json::from_value(v).map_err(M::Error::custom)?); } "recipients" => { + if v.is_null() { + continue; + } recipients = Some(serde_json::from_value(v).map_err(M::Error::custom)?); } &_ => { @@ -94,9 +125,9 @@ impl<'de> Deserialize<'de> for MonitorNotificationRuleAttributes { } } let name = name.ok_or_else(|| M::Error::missing_field("name"))?; - let recipients = recipients.ok_or_else(|| M::Error::missing_field("recipients"))?; let content = MonitorNotificationRuleAttributes { + conditional_recipients, filter, name, recipients, diff --git a/src/datadogV2/model/model_monitor_notification_rule_condition.rs b/src/datadogV2/model/model_monitor_notification_rule_condition.rs new file mode 100644 index 000000000..fce098126 --- /dev/null +++ b/src/datadogV2/model/model_monitor_notification_rule_condition.rs @@ -0,0 +1,102 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Conditions for `conditional_recipients`. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct MonitorNotificationRuleCondition { + /// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'. + #[serde(rename = "recipients")] + pub recipients: Vec, + /// The scope to which the monitor applied. + #[serde(rename = "scope")] + pub scope: String, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl MonitorNotificationRuleCondition { + pub fn new(recipients: Vec, scope: String) -> MonitorNotificationRuleCondition { + MonitorNotificationRuleCondition { + recipients, + scope, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for MonitorNotificationRuleCondition { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct MonitorNotificationRuleConditionVisitor; + impl<'a> Visitor<'a> for MonitorNotificationRuleConditionVisitor { + type Value = MonitorNotificationRuleCondition; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut recipients: Option> = None; + let mut scope: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "recipients" => { + recipients = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "scope" => { + scope = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let recipients = recipients.ok_or_else(|| M::Error::missing_field("recipients"))?; + let scope = scope.ok_or_else(|| M::Error::missing_field("scope"))?; + + let content = MonitorNotificationRuleCondition { + recipients, + scope, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(MonitorNotificationRuleConditionVisitor) + } +} diff --git a/src/datadogV2/model/model_monitor_notification_rule_conditional_recipients.rs b/src/datadogV2/model/model_monitor_notification_rule_conditional_recipients.rs new file mode 100644 index 000000000..e41ef44f2 --- /dev/null +++ b/src/datadogV2/model/model_monitor_notification_rule_conditional_recipients.rs @@ -0,0 +1,114 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Use conditional recipients to define different recipients for different situations. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct MonitorNotificationRuleConditionalRecipients { + /// Conditions of the notification rule. + #[serde(rename = "conditions")] + pub conditions: Vec, + /// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'. + #[serde(rename = "fallback_recipients")] + pub fallback_recipients: Option>, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl MonitorNotificationRuleConditionalRecipients { + pub fn new( + conditions: Vec, + ) -> MonitorNotificationRuleConditionalRecipients { + MonitorNotificationRuleConditionalRecipients { + conditions, + fallback_recipients: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn fallback_recipients(mut self, value: Vec) -> Self { + self.fallback_recipients = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for MonitorNotificationRuleConditionalRecipients { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct MonitorNotificationRuleConditionalRecipientsVisitor; + impl<'a> Visitor<'a> for MonitorNotificationRuleConditionalRecipientsVisitor { + type Value = MonitorNotificationRuleConditionalRecipients; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut conditions: Option< + Vec, + > = None; + let mut fallback_recipients: Option> = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "conditions" => { + conditions = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "fallback_recipients" => { + if v.is_null() { + continue; + } + fallback_recipients = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let conditions = conditions.ok_or_else(|| M::Error::missing_field("conditions"))?; + + let content = MonitorNotificationRuleConditionalRecipients { + conditions, + fallback_recipients, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(MonitorNotificationRuleConditionalRecipientsVisitor) + } +} diff --git a/src/datadogV2/model/model_monitor_notification_rule_response_attributes.rs b/src/datadogV2/model/model_monitor_notification_rule_response_attributes.rs index 9ec292c63..f59b95939 100644 --- a/src/datadogV2/model/model_monitor_notification_rule_response_attributes.rs +++ b/src/datadogV2/model/model_monitor_notification_rule_response_attributes.rs @@ -11,6 +11,10 @@ use std::fmt::{self, Formatter}; #[skip_serializing_none] #[derive(Clone, Debug, PartialEq, Serialize)] pub struct MonitorNotificationRuleResponseAttributes { + /// Use conditional recipients to define different recipients for different situations. + #[serde(rename = "conditional_recipients")] + pub conditional_recipients: + Option, /// Creation time of the monitor notification rule. #[serde(rename = "created")] pub created: Option>, @@ -36,6 +40,7 @@ pub struct MonitorNotificationRuleResponseAttributes { impl MonitorNotificationRuleResponseAttributes { pub fn new() -> MonitorNotificationRuleResponseAttributes { MonitorNotificationRuleResponseAttributes { + conditional_recipients: None, created: None, filter: None, modified: None, @@ -46,6 +51,14 @@ impl MonitorNotificationRuleResponseAttributes { } } + pub fn conditional_recipients( + mut self, + value: crate::datadogV2::model::MonitorNotificationRuleConditionalRecipients, + ) -> Self { + self.conditional_recipients = Some(value); + self + } + pub fn created(mut self, value: chrono::DateTime) -> Self { self.created = Some(value); self @@ -103,6 +116,9 @@ impl<'de> Deserialize<'de> for MonitorNotificationRuleResponseAttributes { where M: MapAccess<'a>, { + let mut conditional_recipients: Option< + crate::datadogV2::model::MonitorNotificationRuleConditionalRecipients, + > = None; let mut created: Option> = None; let mut filter: Option = None; @@ -117,6 +133,13 @@ impl<'de> Deserialize<'de> for MonitorNotificationRuleResponseAttributes { while let Some((k, v)) = map.next_entry::()? { match k.as_str() { + "conditional_recipients" => { + if v.is_null() { + continue; + } + conditional_recipients = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } "created" => { if v.is_null() { continue; @@ -164,6 +187,7 @@ impl<'de> Deserialize<'de> for MonitorNotificationRuleResponseAttributes { } let content = MonitorNotificationRuleResponseAttributes { + conditional_recipients, created, filter, modified, diff --git a/tests/scenarios/cassettes/v2/monitors/Create-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.frozen b/tests/scenarios/cassettes/v2/monitors/Create-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.frozen new file mode 100644 index 000000000..da684d32e --- /dev/null +++ b/tests/scenarios/cassettes/v2/monitors/Create-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.frozen @@ -0,0 +1 @@ +2025-09-26T01:50:59.027Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/monitors/Create-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.json b/tests/scenarios/cassettes/v2/monitors/Create-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.json new file mode 100644 index 000000000..16cfee8e5 --- /dev/null +++ b/tests/scenarios/cassettes/v2/monitors/Create-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.json @@ -0,0 +1,67 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"conditional_recipients\":{\"conditions\":[{\"recipients\":[\"slack-test-channel\",\"jira-test\"],\"scope\":\"transition_type:is_alert\"}]},\"filter\":{\"tags\":[\"test:test-create_a_monitor_notification_rule_with_conditional_recipients_returns_ok_response-1758851459\"]},\"name\":\"test rule\"},\"type\":\"monitor-notification-rule\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/monitor/notification_rule" + }, + "response": { + "body": { + "string": "{\"data\":{\"type\":\"monitor-notification-rule\",\"attributes\":{\"name\":\"test rule\",\"filter\":{\"tags\":[\"test:test-create_a_monitor_notification_rule_with_conditional_recipients_returns_ok_response-1758851459\"]},\"created_at\":\"2025-09-26T01:51:00.132009+00:00\",\"conditional_recipients\":{\"conditions\":[{\"recipients\":[\"slack-test-channel\",\"jira-test\"],\"scope\":\"transition_type:is_alert\"}]},\"modified_at\":\"1970-01-01T00:00:00+00:00\"},\"id\":\"707b82d7-6898-4b20-a577-64f76881fe89\",\"relationships\":{\"created_by\":{\"data\":{\"type\":\"users\",\"id\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\"}}}},\"included\":[{\"type\":\"users\",\"id\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\",\"attributes\":{\"name\":\"CI Account\",\"handle\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\",\"created_at\":\"2020-12-29T22:58:44.733921+00:00\",\"modified_at\":\"2021-04-27T13:54:01.547888+00:00\",\"email\":\"team-intg-tools-libs-spam@datadoghq.com\",\"icon\":\"https://secure.gravatar.com/avatar/b7c189b5b4c2c429d7c1e0bc3749330e?s=48&d=retro\",\"title\":null,\"verified\":true,\"service_account\":true,\"disabled\":false,\"allowed_login_methods\":[],\"status\":\"Active\"}}]}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Fri, 26 Sep 2025 01:50:59 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "*/*" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/monitor/notification_rule/707b82d7-6898-4b20-a577-64f76881fe89" + }, + "response": { + "body": { + "string": "", + "encoding": null + }, + "headers": { + "Content-Type": [ + "text/html; charset=utf-8" + ] + }, + "status": { + "code": 204, + "message": "No Content" + } + }, + "recorded_at": "Fri, 26 Sep 2025 01:50:59 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/monitors/Update-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.frozen b/tests/scenarios/cassettes/v2/monitors/Update-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.frozen new file mode 100644 index 000000000..8543967b2 --- /dev/null +++ b/tests/scenarios/cassettes/v2/monitors/Update-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.frozen @@ -0,0 +1 @@ +2025-09-26T01:51:00.504Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v2/monitors/Update-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.json b/tests/scenarios/cassettes/v2/monitors/Update-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.json new file mode 100644 index 000000000..79c3f20d5 --- /dev/null +++ b/tests/scenarios/cassettes/v2/monitors/Update-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.json @@ -0,0 +1,101 @@ +{ + "http_interactions": [ + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"filter\":{\"tags\":[\"app:test-update_a_monitor_notification_rule_with_conditional_recipients_returns_ok_response-1758851460\"]},\"name\":\"test rule\",\"recipients\":[\"slack-monitor-app\"]},\"type\":\"monitor-notification-rule\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "post", + "uri": "https://api.datadoghq.com/api/v2/monitor/notification_rule" + }, + "response": { + "body": { + "string": "{\"data\":{\"type\":\"monitor-notification-rule\",\"attributes\":{\"filter\":{\"tags\":[\"app:test-update_a_monitor_notification_rule_with_conditional_recipients_returns_ok_response-1758851460\"]},\"created_at\":\"2025-09-26T01:51:00.665373+00:00\",\"name\":\"test rule\",\"recipients\":[\"slack-monitor-app\"],\"modified_at\":\"1970-01-01T00:00:00+00:00\"},\"id\":\"954d2f74-ec41-4f7b-9f63-7146075f3537\",\"relationships\":{\"created_by\":{\"data\":{\"type\":\"users\",\"id\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\"}}}},\"included\":[{\"type\":\"users\",\"id\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\",\"attributes\":{\"name\":\"CI Account\",\"handle\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\",\"created_at\":\"2020-12-29T22:58:44.733921+00:00\",\"modified_at\":\"2021-04-27T13:54:01.547888+00:00\",\"email\":\"team-intg-tools-libs-spam@datadoghq.com\",\"icon\":\"https://secure.gravatar.com/avatar/b7c189b5b4c2c429d7c1e0bc3749330e?s=48&d=retro\",\"title\":null,\"verified\":true,\"service_account\":true,\"disabled\":false,\"allowed_login_methods\":[],\"status\":\"Active\"}}]}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Fri, 26 Sep 2025 01:51:00 GMT" + }, + { + "request": { + "body": { + "string": "{\"data\":{\"attributes\":{\"conditional_recipients\":{\"conditions\":[{\"recipients\":[\"slack-test-channel\",\"jira-test\"],\"scope\":\"transition_type:is_alert\"}]},\"filter\":{\"tags\":[\"test:test-update_a_monitor_notification_rule_with_conditional_recipients_returns_ok_response-1758851460\",\"host:abc\"]},\"name\":\"updated rule\"},\"id\":\"954d2f74-ec41-4f7b-9f63-7146075f3537\",\"type\":\"monitor-notification-rule\"}}", + "encoding": null + }, + "headers": { + "Accept": [ + "application/json" + ], + "Content-Type": [ + "application/json" + ] + }, + "method": "patch", + "uri": "https://api.datadoghq.com/api/v2/monitor/notification_rule/954d2f74-ec41-4f7b-9f63-7146075f3537" + }, + "response": { + "body": { + "string": "{\"data\":{\"type\":\"monitor-notification-rule\",\"id\":\"954d2f74-ec41-4f7b-9f63-7146075f3537\",\"attributes\":{\"filter\":{\"tags\":[\"test:test-update_a_monitor_notification_rule_with_conditional_recipients_returns_ok_response-1758851460\",\"host:abc\"]},\"modified_at\":\"2025-09-26T01:51:00.876883+00:00\",\"conditional_recipients\":{\"conditions\":[{\"scope\":\"transition_type:is_alert\",\"recipients\":[\"slack-test-channel\",\"jira-test\"]}]},\"name\":\"updated rule\",\"created_at\":\"2025-09-26T01:51:00.665373+00:00\"},\"relationships\":{\"created_by\":{\"data\":{\"type\":\"users\",\"id\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\"}}}},\"included\":[{\"type\":\"users\",\"id\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\",\"attributes\":{\"name\":\"CI Account\",\"handle\":\"9919ec9b-ebc7-49ee-8dc8-03626e717cca\",\"created_at\":\"2020-12-29T22:58:44.733921+00:00\",\"modified_at\":\"2021-04-27T13:54:01.547888+00:00\",\"email\":\"team-intg-tools-libs-spam@datadoghq.com\",\"icon\":\"https://secure.gravatar.com/avatar/b7c189b5b4c2c429d7c1e0bc3749330e?s=48&d=retro\",\"title\":null,\"verified\":true,\"service_account\":true,\"disabled\":false,\"allowed_login_methods\":[],\"status\":\"Active\"}}]}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Fri, 26 Sep 2025 01:51:00 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "*/*" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v2/monitor/notification_rule/954d2f74-ec41-4f7b-9f63-7146075f3537" + }, + "response": { + "body": { + "string": "", + "encoding": null + }, + "headers": { + "Content-Type": [ + "text/html; charset=utf-8" + ] + }, + "status": { + "code": 204, + "message": "No Content" + } + }, + "recorded_at": "Fri, 26 Sep 2025 01:51:00 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/features/v2/monitors.feature b/tests/scenarios/features/v2/monitors.feature index d49f00dd0..3fd3138f9 100644 --- a/tests/scenarios/features/v2/monitors.feature +++ b/tests/scenarios/features/v2/monitors.feature @@ -44,6 +44,14 @@ Feature: Monitors Then the response status is 200 OK And the response "data.attributes.name" is equal to "test rule" + @team:DataDog/monitor-app + Scenario: Create a monitor notification rule with conditional recipients returns "OK" response + Given new "CreateMonitorNotificationRule" request + And body with value {"data": {"attributes": {"filter": {"tags": ["test:{{ unique_lower }}"]}, "name": "test rule", "conditional_recipients": {"conditions": [{"scope": "transition_type:is_alert", "recipients": ["slack-test-channel", "jira-test"]}]}}, "type": "monitor-notification-rule"}} + When the request is sent + Then the response status is 200 OK + And the response "data.attributes.name" is equal to "test rule" + @skip-validation @team:DataDog/monitor-app Scenario: Create a monitor user template returns "Bad Request" response Given new "CreateMonitorUserTemplate" request @@ -255,6 +263,16 @@ Feature: Monitors Then the response status is 200 OK And the response "data.attributes.name" is equal to "updated rule" + @team:DataDog/monitor-app + Scenario: Update a monitor notification rule with conditional_recipients returns "OK" response + Given there is a valid "monitor_notification_rule" in the system + And new "UpdateMonitorNotificationRule" request + And request contains "rule_id" parameter from "monitor_notification_rule.data.id" + And body with value {"data": {"attributes": {"filter": {"tags": ["test:{{ unique_lower }}", "host:abc"]}, "name": "updated rule", "conditional_recipients": {"conditions": [{"scope": "transition_type:is_alert", "recipients": ["slack-test-channel", "jira-test"]}]}}, "id": "{{ monitor_notification_rule.data.id }}", "type": "monitor-notification-rule"}} + When the request is sent + Then the response status is 200 OK + And the response "data.attributes.name" is equal to "updated rule" + @skip-validation @team:DataDog/monitor-app Scenario: Update a monitor user template to a new version returns "Bad Request" response Given there is a valid "monitor_user_template" in the system