Skip to content

Commit 651b5c0

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add conditional recipients to notification rule (#2688)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent cb79f27 commit 651b5c0

13 files changed

+594
-10
lines changed

.generator/schemas/v2/openapi.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29565,6 +29565,8 @@ components:
2956529565
additionalProperties: false
2956629566
description: Attributes of the monitor notification rule.
2956729567
properties:
29568+
conditional_recipients:
29569+
$ref: '#/components/schemas/MonitorNotificationRuleConditionalRecipients'
2956829570
filter:
2956929571
$ref: '#/components/schemas/MonitorNotificationRuleFilter'
2957029572
name:
@@ -29573,8 +29575,36 @@ components:
2957329575
$ref: '#/components/schemas/MonitorNotificationRuleRecipients'
2957429576
required:
2957529577
- name
29578+
type: object
29579+
MonitorNotificationRuleCondition:
29580+
description: Conditions for `conditional_recipients`.
29581+
properties:
29582+
recipients:
29583+
$ref: '#/components/schemas/MonitorNotificationRuleRecipients'
29584+
scope:
29585+
$ref: '#/components/schemas/MonitorNotificationRuleScope'
29586+
required:
29587+
- scope
2957629588
- recipients
2957729589
type: object
29590+
MonitorNotificationRuleConditionalRecipients:
29591+
description: Use conditional recipients to define different recipients for different
29592+
situations.
29593+
properties:
29594+
conditions:
29595+
description: Conditions of the notification rule.
29596+
items:
29597+
$ref: '#/components/schemas/MonitorNotificationRuleCondition'
29598+
maxItems: 10
29599+
minItems: 1
29600+
type: array
29601+
fallback_recipients:
29602+
$ref: '#/components/schemas/MonitorNotificationRuleRecipients'
29603+
description: If none of the `conditions` applied, `fallback_recipients`
29604+
will get notified.
29605+
required:
29606+
- conditions
29607+
type: object
2957829608
MonitorNotificationRuleCreateRequest:
2957929609
description: Request for creating a monitor notification rule.
2958029610
properties:
@@ -29714,6 +29744,8 @@ components:
2971429744
additionalProperties: {}
2971529745
description: Attributes of the monitor notification rule.
2971629746
properties:
29747+
conditional_recipients:
29748+
$ref: '#/components/schemas/MonitorNotificationRuleConditionalRecipients'
2971729749
created:
2971829750
description: Creation time of the monitor notification rule.
2971929751
example: 2020-01-02 03:04:00+00:00
@@ -29735,6 +29767,12 @@ components:
2973529767
description: An object related to a monitor notification rule.
2973629768
oneOf:
2973729769
- $ref: '#/components/schemas/User'
29770+
MonitorNotificationRuleScope:
29771+
description: The scope to which the monitor applied.
29772+
example: transition_type:alert
29773+
maxLength: 3000
29774+
minLength: 1
29775+
type: string
2973829776
MonitorNotificationRuleUpdateRequest:
2973929777
description: Request for updating a monitor notification rule.
2974029778
properties:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2025-09-26T01:50:59.027Z

cassettes/features/v2/monitors/Create-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.yml

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2025-09-26T01:51:00.504Z

cassettes/features/v2/monitors/Update-a-monitor-notification-rule-with-conditional-recipients-returns-OK-response.yml

Lines changed: 74 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Create a monitor notification rule with conditional recipients returns "OK" response
2+
3+
require "datadog_api_client"
4+
api_instance = DatadogAPIClient::V2::MonitorsAPI.new
5+
6+
body = DatadogAPIClient::V2::MonitorNotificationRuleCreateRequest.new({
7+
data: DatadogAPIClient::V2::MonitorNotificationRuleCreateRequestData.new({
8+
attributes: DatadogAPIClient::V2::MonitorNotificationRuleAttributes.new({
9+
filter: DatadogAPIClient::V2::MonitorNotificationRuleFilterTags.new({
10+
tags: [
11+
"test:example-monitor",
12+
],
13+
}),
14+
name: "test rule",
15+
conditional_recipients: DatadogAPIClient::V2::MonitorNotificationRuleConditionalRecipients.new({
16+
conditions: [
17+
DatadogAPIClient::V2::MonitorNotificationRuleCondition.new({
18+
scope: "transition_type:is_alert",
19+
recipients: [
20+
"slack-test-channel",
21+
"jira-test",
22+
],
23+
}),
24+
],
25+
}),
26+
}),
27+
type: DatadogAPIClient::V2::MonitorNotificationRuleResourceType::MONITOR_NOTIFICATION_RULE,
28+
}),
29+
})
30+
p api_instance.create_monitor_notification_rule(body)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Update a monitor notification rule with conditional_recipients returns "OK" response
2+
3+
require "datadog_api_client"
4+
api_instance = DatadogAPIClient::V2::MonitorsAPI.new
5+
6+
# there is a valid "monitor_notification_rule" in the system
7+
MONITOR_NOTIFICATION_RULE_DATA_ID = ENV["MONITOR_NOTIFICATION_RULE_DATA_ID"]
8+
9+
body = DatadogAPIClient::V2::MonitorNotificationRuleUpdateRequest.new({
10+
data: DatadogAPIClient::V2::MonitorNotificationRuleUpdateRequestData.new({
11+
attributes: DatadogAPIClient::V2::MonitorNotificationRuleAttributes.new({
12+
filter: DatadogAPIClient::V2::MonitorNotificationRuleFilterTags.new({
13+
tags: [
14+
"test:example-monitor",
15+
"host:abc",
16+
],
17+
}),
18+
name: "updated rule",
19+
conditional_recipients: DatadogAPIClient::V2::MonitorNotificationRuleConditionalRecipients.new({
20+
conditions: [
21+
DatadogAPIClient::V2::MonitorNotificationRuleCondition.new({
22+
scope: "transition_type:is_alert",
23+
recipients: [
24+
"slack-test-channel",
25+
"jira-test",
26+
],
27+
}),
28+
],
29+
}),
30+
}),
31+
id: MONITOR_NOTIFICATION_RULE_DATA_ID,
32+
type: DatadogAPIClient::V2::MonitorNotificationRuleResourceType::MONITOR_NOTIFICATION_RULE,
33+
}),
34+
})
35+
p api_instance.update_monitor_notification_rule(MONITOR_NOTIFICATION_RULE_DATA_ID, body)

features/v2/monitors.feature

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ Feature: Monitors
4444
Then the response status is 200 OK
4545
And the response "data.attributes.name" is equal to "test rule"
4646

47+
@team:DataDog/monitor-app
48+
Scenario: Create a monitor notification rule with conditional recipients returns "OK" response
49+
Given new "CreateMonitorNotificationRule" request
50+
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"}}
51+
When the request is sent
52+
Then the response status is 200 OK
53+
And the response "data.attributes.name" is equal to "test rule"
54+
4755
@skip-validation @team:DataDog/monitor-app
4856
Scenario: Create a monitor user template returns "Bad Request" response
4957
Given new "CreateMonitorUserTemplate" request
@@ -255,6 +263,16 @@ Feature: Monitors
255263
Then the response status is 200 OK
256264
And the response "data.attributes.name" is equal to "updated rule"
257265

266+
@team:DataDog/monitor-app
267+
Scenario: Update a monitor notification rule with conditional_recipients returns "OK" response
268+
Given there is a valid "monitor_notification_rule" in the system
269+
And new "UpdateMonitorNotificationRule" request
270+
And request contains "rule_id" parameter from "monitor_notification_rule.data.id"
271+
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"}}
272+
When the request is sent
273+
Then the response status is 200 OK
274+
And the response "data.attributes.name" is equal to "updated rule"
275+
258276
@skip-validation @team:DataDog/monitor-app
259277
Scenario: Update a monitor user template to a new version returns "Bad Request" response
260278
Given there is a valid "monitor_user_template" in the system

lib/datadog_api_client/inflector.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2759,6 +2759,8 @@ def overrides
27592759
"v2.monitor_downtime_match_response_attributes" => "MonitorDowntimeMatchResponseAttributes",
27602760
"v2.monitor_downtime_match_response_data" => "MonitorDowntimeMatchResponseData",
27612761
"v2.monitor_notification_rule_attributes" => "MonitorNotificationRuleAttributes",
2762+
"v2.monitor_notification_rule_condition" => "MonitorNotificationRuleCondition",
2763+
"v2.monitor_notification_rule_conditional_recipients" => "MonitorNotificationRuleConditionalRecipients",
27622764
"v2.monitor_notification_rule_create_request" => "MonitorNotificationRuleCreateRequest",
27632765
"v2.monitor_notification_rule_create_request_data" => "MonitorNotificationRuleCreateRequestData",
27642766
"v2.monitor_notification_rule_data" => "MonitorNotificationRuleData",

lib/datadog_api_client/v2/models/monitor_notification_rule_attributes.rb

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ module DatadogAPIClient::V2
2121
class MonitorNotificationRuleAttributes
2222
include BaseGenericModel
2323

24+
# Use conditional recipients to define different recipients for different situations.
25+
attr_accessor :conditional_recipients
26+
2427
# Filter used to associate the notification rule with monitors.
2528
attr_accessor :filter
2629

@@ -34,6 +37,7 @@ class MonitorNotificationRuleAttributes
3437
# @!visibility private
3538
def self.attribute_map
3639
{
40+
:'conditional_recipients' => :'conditional_recipients',
3741
:'filter' => :'filter',
3842
:'name' => :'name',
3943
:'recipients' => :'recipients'
@@ -44,6 +48,7 @@ def self.attribute_map
4448
# @!visibility private
4549
def self.openapi_types
4650
{
51+
:'conditional_recipients' => :'MonitorNotificationRuleConditionalRecipients',
4752
:'filter' => :'MonitorNotificationRuleFilter',
4853
:'name' => :'String',
4954
:'recipients' => :'Array<String>'
@@ -66,6 +71,10 @@ def initialize(attributes = {})
6671
h[k.to_sym] = v
6772
}
6873

74+
if attributes.key?(:'conditional_recipients')
75+
self.conditional_recipients = attributes[:'conditional_recipients']
76+
end
77+
6978
if attributes.key?(:'filter')
7079
self.filter = attributes[:'filter']
7180
end
@@ -88,9 +97,8 @@ def valid?
8897
return false if @name.nil?
8998
return false if @name.to_s.length > 1000
9099
return false if @name.to_s.length < 1
91-
return false if @recipients.nil?
92-
return false if @recipients.length > 20
93-
return false if @recipients.length < 1
100+
return false if !@recipients.nil? && @recipients.length > 20
101+
return false if !@recipients.nil? && @recipients.length < 1
94102
true
95103
end
96104

@@ -114,13 +122,10 @@ def name=(name)
114122
# @param recipients [Object] Object to be assigned
115123
# @!visibility private
116124
def recipients=(recipients)
117-
if recipients.nil?
118-
fail ArgumentError, 'invalid value for "recipients", recipients cannot be nil.'
119-
end
120-
if recipients.length > 20
125+
if !recipients.nil? && recipients.length > 20
121126
fail ArgumentError, 'invalid value for "recipients", number of items must be less than or equal to 20.'
122127
end
123-
if recipients.length < 1
128+
if !recipients.nil? && recipients.length < 1
124129
fail ArgumentError, 'invalid value for "recipients", number of items must be greater than or equal to 1.'
125130
end
126131
@recipients = recipients
@@ -132,6 +137,7 @@ def recipients=(recipients)
132137
def ==(o)
133138
return true if self.equal?(o)
134139
self.class == o.class &&
140+
conditional_recipients == o.conditional_recipients &&
135141
filter == o.filter &&
136142
name == o.name &&
137143
recipients == o.recipients
@@ -141,7 +147,7 @@ def ==(o)
141147
# @return [Integer] Hash code
142148
# @!visibility private
143149
def hash
144-
[filter, name, recipients].hash
150+
[conditional_recipients, filter, name, recipients].hash
145151
end
146152
end
147153
end

0 commit comments

Comments
 (0)