Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32305,15 +32305,23 @@ components:
properties:
recipients:
$ref: '#/components/schemas/MonitorNotificationRuleRecipients'
description: A list of recipients to notify. Uses the same format as the
monitor `message` field. Must not start with an '@'.
scope:
$ref: '#/components/schemas/MonitorNotificationRuleScope'
$ref: '#/components/schemas/MonitorNotificationRuleConditionScope'
required:
- scope
- recipients
type: object
MonitorNotificationRuleConditionScope:
description: The scope to which the monitor applied.
example: transition_type:alert
maxLength: 3000
minLength: 1
type: string
MonitorNotificationRuleConditionalRecipients:
description: Use conditional recipients to define different recipients for different
situations.
situations. Cannot be used with `recipients`.
properties:
conditions:
description: Conditions of the notification rule.
Expand Down Expand Up @@ -32363,12 +32371,30 @@ components:
description: Filter used to associate the notification rule with monitors.
oneOf:
- $ref: '#/components/schemas/MonitorNotificationRuleFilterTags'
- $ref: '#/components/schemas/MonitorNotificationRuleFilterScope'
MonitorNotificationRuleFilterScope:
additionalProperties: false
description: Filter monitor notifications. A monitor notification must match
the scope.
properties:
scope:
description: A scope composed of one or several key:value pairs, which can
be used to filter monitor notifications on monitor and group tags.
example: service:(foo OR bar) AND team:test NOT environment:staging
maxLength: 3000
minLength: 1
type: string
required:
- scope
type: object
MonitorNotificationRuleFilterTags:
additionalProperties: false
description: Filter monitors by tags. Monitors must match all tags.
description: Filter monitor notifications by tags. A monitor notification must
match all tags.
properties:
tags:
description: A list of monitor tags.
description: A list of tags (key:value pairs), which can be used to filter
monitor notifications on monitor and group tags.
example:
- team:product
- host:abc
Expand Down Expand Up @@ -32408,7 +32434,7 @@ components:
type: string
MonitorNotificationRuleRecipients:
description: A list of recipients to notify. Uses the same format as the monitor
`message` field. Must not start with an '@'.
`message` field. Must not start with an '@'. Cannot be used with `conditional_recipients`.
example:
- slack-test-channel
- jira-test
Expand Down Expand Up @@ -32491,12 +32517,6 @@ 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:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Create a monitor notification rule with scope 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::MonitorNotificationRuleCreateRequest;
use datadog_api_client::datadogV2::model::MonitorNotificationRuleCreateRequestData;
use datadog_api_client::datadogV2::model::MonitorNotificationRuleFilter;
use datadog_api_client::datadogV2::model::MonitorNotificationRuleFilterScope;
use datadog_api_client::datadogV2::model::MonitorNotificationRuleResourceType;

#[tokio::main]
async fn main() {
let body = MonitorNotificationRuleCreateRequest::new(
MonitorNotificationRuleCreateRequestData::new(
MonitorNotificationRuleAttributes::new("test rule".to_string())
.filter(
MonitorNotificationRuleFilter::MonitorNotificationRuleFilterScope(Box::new(
MonitorNotificationRuleFilterScope::new("test:example-monitor".to_string()),
)),
)
.recipients(vec![
"slack-test-channel".to_string(),
"jira-test".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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Update a monitor notification rule with scope 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::MonitorNotificationRuleFilter;
use datadog_api_client::datadogV2::model::MonitorNotificationRuleFilterScope;
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())
.filter(
MonitorNotificationRuleFilter::MonitorNotificationRuleFilterScope(Box::new(
MonitorNotificationRuleFilterScope::new("test:example-monitor".to_string()),
)),
)
.recipients(vec!["slack-test-channel".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());
}
}
2 changes: 2 additions & 0 deletions src/datadogV2/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3688,6 +3688,8 @@ 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_scope;
pub use self::model_monitor_notification_rule_filter_scope::MonitorNotificationRuleFilterScope;
pub mod model_monitor_notification_rule_filter;
pub use self::model_monitor_notification_rule_filter::MonitorNotificationRuleFilter;
pub mod model_monitor_notification_rule_relationships;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ 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.
/// Use conditional recipients to define different recipients for different situations. Cannot be used with `recipients`.
#[serde(rename = "conditional_recipients")]
pub conditional_recipients:
Option<crate::datadogV2::model::MonitorNotificationRuleConditionalRecipients>,
Expand All @@ -21,7 +21,7 @@ pub struct MonitorNotificationRuleAttributes {
/// The name of the monitor notification rule.
#[serde(rename = "name")]
pub name: String,
/// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'.
/// 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`.
#[serde(rename = "recipients")]
pub recipients: Option<Vec<String>>,
#[serde(skip)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::fmt::{self, Formatter};
#[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 '@'.
/// 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`.
#[serde(rename = "recipients")]
pub recipients: Vec<String>,
/// The scope to which the monitor applied.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ 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.
/// Use conditional recipients to define different recipients for different situations. Cannot be used with `recipients`.
#[non_exhaustive]
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct MonitorNotificationRuleConditionalRecipients {
/// Conditions of the notification rule.
#[serde(rename = "conditions")]
pub conditions: Vec<crate::datadogV2::model::MonitorNotificationRuleCondition>,
/// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'.
/// 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`.
#[serde(rename = "fallback_recipients")]
pub fallback_recipients: Option<Vec<String>>,
#[serde(flatten)]
Expand Down
11 changes: 11 additions & 0 deletions src/datadogV2/model/model_monitor_notification_rule_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pub enum MonitorNotificationRuleFilter {
MonitorNotificationRuleFilterTags(
Box<crate::datadogV2::model::MonitorNotificationRuleFilterTags>,
),
MonitorNotificationRuleFilterScope(
Box<crate::datadogV2::model::MonitorNotificationRuleFilterScope>,
),
UnparsedObject(crate::datadog::UnparsedObject),
}

Expand All @@ -28,6 +31,14 @@ impl<'de> Deserialize<'de> for MonitorNotificationRuleFilter {
return Ok(MonitorNotificationRuleFilter::MonitorNotificationRuleFilterTags(_v));
}
}
if let Ok(_v) = serde_json::from_value::<
Box<crate::datadogV2::model::MonitorNotificationRuleFilterScope>,
>(value.clone())
{
if !_v._unparsed {
return Ok(MonitorNotificationRuleFilter::MonitorNotificationRuleFilterScope(_v));
}
}

return Ok(MonitorNotificationRuleFilter::UnparsedObject(
crate::datadog::UnparsedObject { value },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// 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};

/// Filter monitor notifications. A monitor notification must match the scope.
#[non_exhaustive]
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct MonitorNotificationRuleFilterScope {
/// A scope composed of one or several key:value pairs, which can be used to filter monitor notifications on monitor and group tags.
#[serde(rename = "scope")]
pub scope: String,
#[serde(skip)]
#[serde(default)]
pub(crate) _unparsed: bool,
}

impl MonitorNotificationRuleFilterScope {
pub fn new(scope: String) -> MonitorNotificationRuleFilterScope {
MonitorNotificationRuleFilterScope {
scope,
_unparsed: false,
}
}
}

impl<'de> Deserialize<'de> for MonitorNotificationRuleFilterScope {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct MonitorNotificationRuleFilterScopeVisitor;
impl<'a> Visitor<'a> for MonitorNotificationRuleFilterScopeVisitor {
type Value = MonitorNotificationRuleFilterScope;

fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("a mapping")
}

fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
where
M: MapAccess<'a>,
{
let mut scope: Option<String> = None;
let mut _unparsed = false;

while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
match k.as_str() {
"scope" => {
scope = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
&_ => {
return Err(serde::de::Error::custom(
"Additional properties not allowed",
));
}
}
}
let scope = scope.ok_or_else(|| M::Error::missing_field("scope"))?;

let content = MonitorNotificationRuleFilterScope { scope, _unparsed };

Ok(content)
}
}

deserializer.deserialize_any(MonitorNotificationRuleFilterScopeVisitor)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use serde::{Deserialize, Deserializer, Serialize};
use serde_with::skip_serializing_none;
use std::fmt::{self, Formatter};

/// Filter monitors by tags. Monitors must match all tags.
/// Filter monitor notifications by tags. A monitor notification must match all tags.
#[non_exhaustive]
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct MonitorNotificationRuleFilterTags {
/// A list of monitor tags.
/// A list of tags (key:value pairs), which can be used to filter monitor notifications on monitor and group tags.
#[serde(rename = "tags")]
pub tags: Vec<String>,
#[serde(skip)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ 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.
/// Use conditional recipients to define different recipients for different situations. Cannot be used with `recipients`.
#[serde(rename = "conditional_recipients")]
pub conditional_recipients:
Option<crate::datadogV2::model::MonitorNotificationRuleConditionalRecipients>,
Expand All @@ -27,7 +27,7 @@ pub struct MonitorNotificationRuleResponseAttributes {
/// The name of the monitor notification rule.
#[serde(rename = "name")]
pub name: Option<String>,
/// A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'.
/// 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`.
#[serde(rename = "recipients")]
pub recipients: Option<Vec<String>>,
#[serde(flatten)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2025-11-11T21:28:39.129Z
Loading