Skip to content

Commit 8037d5a

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add filter.scope to Monitor Notification Rules (#1022)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent 2a3879e commit 8037d5a

16 files changed

+389
-20
lines changed

.generator/schemas/v2/openapi.yaml

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32691,15 +32691,23 @@ components:
3269132691
properties:
3269232692
recipients:
3269332693
$ref: '#/components/schemas/MonitorNotificationRuleRecipients'
32694+
description: A list of recipients to notify. Uses the same format as the
32695+
monitor `message` field. Must not start with an '@'.
3269432696
scope:
32695-
$ref: '#/components/schemas/MonitorNotificationRuleScope'
32697+
$ref: '#/components/schemas/MonitorNotificationRuleConditionScope'
3269632698
required:
3269732699
- scope
3269832700
- recipients
3269932701
type: object
32702+
MonitorNotificationRuleConditionScope:
32703+
description: The scope to which the monitor applied.
32704+
example: transition_type:alert
32705+
maxLength: 3000
32706+
minLength: 1
32707+
type: string
3270032708
MonitorNotificationRuleConditionalRecipients:
3270132709
description: Use conditional recipients to define different recipients for different
32702-
situations.
32710+
situations. Cannot be used with `recipients`.
3270332711
properties:
3270432712
conditions:
3270532713
description: Conditions of the notification rule.
@@ -32749,12 +32757,30 @@ components:
3274932757
description: Filter used to associate the notification rule with monitors.
3275032758
oneOf:
3275132759
- $ref: '#/components/schemas/MonitorNotificationRuleFilterTags'
32760+
- $ref: '#/components/schemas/MonitorNotificationRuleFilterScope'
32761+
MonitorNotificationRuleFilterScope:
32762+
additionalProperties: false
32763+
description: Filter monitor notifications. A monitor notification must match
32764+
the scope.
32765+
properties:
32766+
scope:
32767+
description: A scope composed of one or several key:value pairs, which can
32768+
be used to filter monitor notifications on monitor and group tags.
32769+
example: service:(foo OR bar) AND team:test NOT environment:staging
32770+
maxLength: 3000
32771+
minLength: 1
32772+
type: string
32773+
required:
32774+
- scope
32775+
type: object
3275232776
MonitorNotificationRuleFilterTags:
3275332777
additionalProperties: false
32754-
description: Filter monitors by tags. Monitors must match all tags.
32778+
description: Filter monitor notifications by tags. A monitor notification must
32779+
match all tags.
3275532780
properties:
3275632781
tags:
32757-
description: A list of monitor tags.
32782+
description: A list of tags (key:value pairs), which can be used to filter
32783+
monitor notifications on monitor and group tags.
3275832784
example:
3275932785
- team:product
3276032786
- host:abc
@@ -32794,7 +32820,7 @@ components:
3279432820
type: string
3279532821
MonitorNotificationRuleRecipients:
3279632822
description: A list of recipients to notify. Uses the same format as the monitor
32797-
`message` field. Must not start with an '@'.
32823+
`message` field. Must not start with an '@'. Cannot be used with `conditional_recipients`.
3279832824
example:
3279932825
- slack-test-channel
3280032826
- jira-test
@@ -32877,12 +32903,6 @@ components:
3287732903
description: An object related to a monitor notification rule.
3287832904
oneOf:
3287932905
- $ref: '#/components/schemas/User'
32880-
MonitorNotificationRuleScope:
32881-
description: The scope to which the monitor applied.
32882-
example: transition_type:alert
32883-
maxLength: 3000
32884-
minLength: 1
32885-
type: string
3288632906
MonitorNotificationRuleUpdateRequest:
3288732907
description: Request for updating a monitor notification rule.
3288832908
properties:
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Create a monitor notification rule with scope returns "OK" response
2+
use datadog_api_client::datadog;
3+
use datadog_api_client::datadogV2::api_monitors::MonitorsAPI;
4+
use datadog_api_client::datadogV2::model::MonitorNotificationRuleAttributes;
5+
use datadog_api_client::datadogV2::model::MonitorNotificationRuleCreateRequest;
6+
use datadog_api_client::datadogV2::model::MonitorNotificationRuleCreateRequestData;
7+
use datadog_api_client::datadogV2::model::MonitorNotificationRuleFilter;
8+
use datadog_api_client::datadogV2::model::MonitorNotificationRuleFilterScope;
9+
use datadog_api_client::datadogV2::model::MonitorNotificationRuleResourceType;
10+
11+
#[tokio::main]
12+
async fn main() {
13+
let body = MonitorNotificationRuleCreateRequest::new(
14+
MonitorNotificationRuleCreateRequestData::new(
15+
MonitorNotificationRuleAttributes::new("test rule".to_string())
16+
.filter(
17+
MonitorNotificationRuleFilter::MonitorNotificationRuleFilterScope(Box::new(
18+
MonitorNotificationRuleFilterScope::new("test:example-monitor".to_string()),
19+
)),
20+
)
21+
.recipients(vec![
22+
"slack-test-channel".to_string(),
23+
"jira-test".to_string(),
24+
]),
25+
)
26+
.type_(MonitorNotificationRuleResourceType::MONITOR_NOTIFICATION_RULE),
27+
);
28+
let configuration = datadog::Configuration::new();
29+
let api = MonitorsAPI::with_config(configuration);
30+
let resp = api.create_monitor_notification_rule(body).await;
31+
if let Ok(value) = resp {
32+
println!("{:#?}", value);
33+
} else {
34+
println!("{:#?}", resp.unwrap_err());
35+
}
36+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Update a monitor notification rule with scope returns "OK" response
2+
use datadog_api_client::datadog;
3+
use datadog_api_client::datadogV2::api_monitors::MonitorsAPI;
4+
use datadog_api_client::datadogV2::model::MonitorNotificationRuleAttributes;
5+
use datadog_api_client::datadogV2::model::MonitorNotificationRuleFilter;
6+
use datadog_api_client::datadogV2::model::MonitorNotificationRuleFilterScope;
7+
use datadog_api_client::datadogV2::model::MonitorNotificationRuleResourceType;
8+
use datadog_api_client::datadogV2::model::MonitorNotificationRuleUpdateRequest;
9+
use datadog_api_client::datadogV2::model::MonitorNotificationRuleUpdateRequestData;
10+
11+
#[tokio::main]
12+
async fn main() {
13+
// there is a valid "monitor_notification_rule" in the system
14+
let monitor_notification_rule_data_id =
15+
std::env::var("MONITOR_NOTIFICATION_RULE_DATA_ID").unwrap();
16+
let body = MonitorNotificationRuleUpdateRequest::new(
17+
MonitorNotificationRuleUpdateRequestData::new(
18+
MonitorNotificationRuleAttributes::new("updated rule".to_string())
19+
.filter(
20+
MonitorNotificationRuleFilter::MonitorNotificationRuleFilterScope(Box::new(
21+
MonitorNotificationRuleFilterScope::new("test:example-monitor".to_string()),
22+
)),
23+
)
24+
.recipients(vec!["slack-test-channel".to_string()]),
25+
monitor_notification_rule_data_id.clone(),
26+
)
27+
.type_(MonitorNotificationRuleResourceType::MONITOR_NOTIFICATION_RULE),
28+
);
29+
let configuration = datadog::Configuration::new();
30+
let api = MonitorsAPI::with_config(configuration);
31+
let resp = api
32+
.update_monitor_notification_rule(monitor_notification_rule_data_id.clone(), body)
33+
.await;
34+
if let Ok(value) = resp {
35+
println!("{:#?}", value);
36+
} else {
37+
println!("{:#?}", resp.unwrap_err());
38+
}
39+
}

src/datadogV2/model/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3750,6 +3750,8 @@ pub mod model_monitor_notification_rule_condition;
37503750
pub use self::model_monitor_notification_rule_condition::MonitorNotificationRuleCondition;
37513751
pub mod model_monitor_notification_rule_filter_tags;
37523752
pub use self::model_monitor_notification_rule_filter_tags::MonitorNotificationRuleFilterTags;
3753+
pub mod model_monitor_notification_rule_filter_scope;
3754+
pub use self::model_monitor_notification_rule_filter_scope::MonitorNotificationRuleFilterScope;
37533755
pub mod model_monitor_notification_rule_filter;
37543756
pub use self::model_monitor_notification_rule_filter::MonitorNotificationRuleFilter;
37553757
pub mod model_monitor_notification_rule_relationships;

src/datadogV2/model/model_monitor_notification_rule_attributes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::fmt::{self, Formatter};
1111
#[skip_serializing_none]
1212
#[derive(Clone, Debug, PartialEq, Serialize)]
1313
pub struct MonitorNotificationRuleAttributes {
14-
/// Use conditional recipients to define different recipients for different situations.
14+
/// Use conditional recipients to define different recipients for different situations. Cannot be used with `recipients`.
1515
#[serde(rename = "conditional_recipients")]
1616
pub conditional_recipients:
1717
Option<crate::datadogV2::model::MonitorNotificationRuleConditionalRecipients>,
@@ -21,7 +21,7 @@ pub struct MonitorNotificationRuleAttributes {
2121
/// The name of the monitor notification rule.
2222
#[serde(rename = "name")]
2323
pub name: String,
24-
/// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'.
24+
/// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'. Cannot be used with `conditional_recipients`.
2525
#[serde(rename = "recipients")]
2626
pub recipients: Option<Vec<String>>,
2727
#[serde(skip)]

src/datadogV2/model/model_monitor_notification_rule_condition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::fmt::{self, Formatter};
1111
#[skip_serializing_none]
1212
#[derive(Clone, Debug, PartialEq, Serialize)]
1313
pub struct MonitorNotificationRuleCondition {
14-
/// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'.
14+
/// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'. Cannot be used with `conditional_recipients`.
1515
#[serde(rename = "recipients")]
1616
pub recipients: Vec<String>,
1717
/// The scope to which the monitor applied.

src/datadogV2/model/model_monitor_notification_rule_conditional_recipients.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ use serde::{Deserialize, Deserializer, Serialize};
66
use serde_with::skip_serializing_none;
77
use std::fmt::{self, Formatter};
88

9-
/// Use conditional recipients to define different recipients for different situations.
9+
/// Use conditional recipients to define different recipients for different situations. Cannot be used with `recipients`.
1010
#[non_exhaustive]
1111
#[skip_serializing_none]
1212
#[derive(Clone, Debug, PartialEq, Serialize)]
1313
pub struct MonitorNotificationRuleConditionalRecipients {
1414
/// Conditions of the notification rule.
1515
#[serde(rename = "conditions")]
1616
pub conditions: Vec<crate::datadogV2::model::MonitorNotificationRuleCondition>,
17-
/// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'.
17+
/// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'. Cannot be used with `conditional_recipients`.
1818
#[serde(rename = "fallback_recipients")]
1919
pub fallback_recipients: Option<Vec<String>>,
2020
#[serde(flatten)]

src/datadogV2/model/model_monitor_notification_rule_filter.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ pub enum MonitorNotificationRuleFilter {
1111
MonitorNotificationRuleFilterTags(
1212
Box<crate::datadogV2::model::MonitorNotificationRuleFilterTags>,
1313
),
14+
MonitorNotificationRuleFilterScope(
15+
Box<crate::datadogV2::model::MonitorNotificationRuleFilterScope>,
16+
),
1417
UnparsedObject(crate::datadog::UnparsedObject),
1518
}
1619

@@ -28,6 +31,14 @@ impl<'de> Deserialize<'de> for MonitorNotificationRuleFilter {
2831
return Ok(MonitorNotificationRuleFilter::MonitorNotificationRuleFilterTags(_v));
2932
}
3033
}
34+
if let Ok(_v) = serde_json::from_value::<
35+
Box<crate::datadogV2::model::MonitorNotificationRuleFilterScope>,
36+
>(value.clone())
37+
{
38+
if !_v._unparsed {
39+
return Ok(MonitorNotificationRuleFilter::MonitorNotificationRuleFilterScope(_v));
40+
}
41+
}
3142

3243
return Ok(MonitorNotificationRuleFilter::UnparsedObject(
3344
crate::datadog::UnparsedObject { value },
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
3+
// Copyright 2019-Present Datadog, Inc.
4+
use serde::de::{Error, MapAccess, Visitor};
5+
use serde::{Deserialize, Deserializer, Serialize};
6+
use serde_with::skip_serializing_none;
7+
use std::fmt::{self, Formatter};
8+
9+
/// Filter monitor notifications. A monitor notification must match the scope.
10+
#[non_exhaustive]
11+
#[skip_serializing_none]
12+
#[derive(Clone, Debug, PartialEq, Serialize)]
13+
pub struct MonitorNotificationRuleFilterScope {
14+
/// A scope composed of one or several key:value pairs, which can be used to filter monitor notifications on monitor and group tags.
15+
#[serde(rename = "scope")]
16+
pub scope: String,
17+
#[serde(skip)]
18+
#[serde(default)]
19+
pub(crate) _unparsed: bool,
20+
}
21+
22+
impl MonitorNotificationRuleFilterScope {
23+
pub fn new(scope: String) -> MonitorNotificationRuleFilterScope {
24+
MonitorNotificationRuleFilterScope {
25+
scope,
26+
_unparsed: false,
27+
}
28+
}
29+
}
30+
31+
impl<'de> Deserialize<'de> for MonitorNotificationRuleFilterScope {
32+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
33+
where
34+
D: Deserializer<'de>,
35+
{
36+
struct MonitorNotificationRuleFilterScopeVisitor;
37+
impl<'a> Visitor<'a> for MonitorNotificationRuleFilterScopeVisitor {
38+
type Value = MonitorNotificationRuleFilterScope;
39+
40+
fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
41+
f.write_str("a mapping")
42+
}
43+
44+
fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
45+
where
46+
M: MapAccess<'a>,
47+
{
48+
let mut scope: Option<String> = None;
49+
let mut _unparsed = false;
50+
51+
while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
52+
match k.as_str() {
53+
"scope" => {
54+
scope = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
55+
}
56+
&_ => {
57+
return Err(serde::de::Error::custom(
58+
"Additional properties not allowed",
59+
));
60+
}
61+
}
62+
}
63+
let scope = scope.ok_or_else(|| M::Error::missing_field("scope"))?;
64+
65+
let content = MonitorNotificationRuleFilterScope { scope, _unparsed };
66+
67+
Ok(content)
68+
}
69+
}
70+
71+
deserializer.deserialize_any(MonitorNotificationRuleFilterScopeVisitor)
72+
}
73+
}

src/datadogV2/model/model_monitor_notification_rule_filter_tags.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use serde::{Deserialize, Deserializer, Serialize};
66
use serde_with::skip_serializing_none;
77
use std::fmt::{self, Formatter};
88

9-
/// Filter monitors by tags. Monitors must match all tags.
9+
/// Filter monitor notifications by tags. A monitor notification must match all tags.
1010
#[non_exhaustive]
1111
#[skip_serializing_none]
1212
#[derive(Clone, Debug, PartialEq, Serialize)]
1313
pub struct MonitorNotificationRuleFilterTags {
14-
/// A list of monitor tags.
14+
/// A list of tags (key:value pairs), which can be used to filter monitor notifications on monitor and group tags.
1515
#[serde(rename = "tags")]
1616
pub tags: Vec<String>,
1717
#[serde(skip)]

0 commit comments

Comments
 (0)