Skip to content

Commit b66a3ce

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

16 files changed

+335
-21
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2025-11-11T21:28:39.129Z

cassettes/features/v2/monitors/Create-a-monitor-notification-rule-with-scope-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.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2025-11-11T21:28:40.357Z

cassettes/features/v2/monitors/Update-a-monitor-notification-rule-with-scope-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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Create a monitor notification rule with scope 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::MonitorNotificationRuleFilterScope.new({
10+
scope: "test:example-monitor",
11+
}),
12+
name: "test rule",
13+
recipients: [
14+
"slack-test-channel",
15+
"jira-test",
16+
],
17+
}),
18+
type: DatadogAPIClient::V2::MonitorNotificationRuleResourceType::MONITOR_NOTIFICATION_RULE,
19+
}),
20+
})
21+
p api_instance.create_monitor_notification_rule(body)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Update a monitor notification rule with scope 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::MonitorNotificationRuleFilterScope.new({
13+
scope: "test:example-monitor",
14+
}),
15+
name: "updated rule",
16+
recipients: [
17+
"slack-test-channel",
18+
],
19+
}),
20+
id: MONITOR_NOTIFICATION_RULE_DATA_ID,
21+
type: DatadogAPIClient::V2::MonitorNotificationRuleResourceType::MONITOR_NOTIFICATION_RULE,
22+
}),
23+
})
24+
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
@@ -52,6 +52,14 @@ Feature: Monitors
5252
Then the response status is 200 OK
5353
And the response "data.attributes.name" is equal to "test rule"
5454

55+
@team:DataDog/monitor-app
56+
Scenario: Create a monitor notification rule with scope returns "OK" response
57+
Given new "CreateMonitorNotificationRule" request
58+
And body with value {"data": {"attributes": {"filter": {"scope": "test:{{ unique_lower }}"}, "name": "test rule", "recipients": ["slack-test-channel", "jira-test"]}, "type": "monitor-notification-rule"}}
59+
When the request is sent
60+
Then the response status is 200 OK
61+
And the response "data.attributes.name" is equal to "test rule"
62+
5563
@skip-validation @team:DataDog/monitor-app
5664
Scenario: Create a monitor user template returns "Bad Request" response
5765
Given new "CreateMonitorUserTemplate" request
@@ -272,6 +280,16 @@ Feature: Monitors
272280
Then the response status is 200 OK
273281
And the response "data.attributes.name" is equal to "updated rule"
274282

283+
@team:DataDog/monitor-app
284+
Scenario: Update a monitor notification rule with scope returns "OK" response
285+
Given there is a valid "monitor_notification_rule" in the system
286+
And new "UpdateMonitorNotificationRule" request
287+
And request contains "rule_id" parameter from "monitor_notification_rule.data.id"
288+
And body with value {"data": {"attributes": {"filter": {"scope": "test:{{ unique_lower }}"}, "name": "updated rule", "recipients": ["slack-test-channel"]}, "id": "{{ monitor_notification_rule.data.id }}", "type": "monitor-notification-rule"}}
289+
When the request is sent
290+
Then the response status is 200 OK
291+
And the response "data.attributes.name" is equal to "updated rule"
292+
275293
@skip-validation @team:DataDog/monitor-app
276294
Scenario: Update a monitor user template to a new version returns "Bad Request" response
277295
Given there is a valid "monitor_user_template" in the system

lib/datadog_api_client/inflector.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2981,6 +2981,7 @@ def overrides
29812981
"v2.monitor_notification_rule_create_request_data" => "MonitorNotificationRuleCreateRequestData",
29822982
"v2.monitor_notification_rule_data" => "MonitorNotificationRuleData",
29832983
"v2.monitor_notification_rule_filter" => "MonitorNotificationRuleFilter",
2984+
"v2.monitor_notification_rule_filter_scope" => "MonitorNotificationRuleFilterScope",
29842985
"v2.monitor_notification_rule_filter_tags" => "MonitorNotificationRuleFilterTags",
29852986
"v2.monitor_notification_rule_list_response" => "MonitorNotificationRuleListResponse",
29862987
"v2.monitor_notification_rule_relationships" => "MonitorNotificationRuleRelationships",

lib/datadog_api_client/v2/models/monitor_notification_rule_attributes.rb

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

24-
# Use conditional recipients to define different recipients for different situations.
24+
# Use conditional recipients to define different recipients for different situations. Cannot be used with `recipients`.
2525
attr_accessor :conditional_recipients
2626

2727
# Filter used to associate the notification rule with monitors.
@@ -30,7 +30,7 @@ class MonitorNotificationRuleAttributes
3030
# The name of the monitor notification rule.
3131
attr_reader :name
3232

33-
# A list of recipients to notify. Uses the same format as the monitor `message` field. Must not start with an '@'.
33+
# 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`.
3434
attr_reader :recipients
3535

3636
# Attribute mapping from ruby-style variable name to JSON key.

0 commit comments

Comments
 (0)