Skip to content

Commit f59ccb4

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

17 files changed

+316
-23
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:

docs/datadog_api_client.v2.model.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14298,6 +14298,13 @@ datadog\_api\_client.v2.model.monitor\_notification\_rule\_filter module
1429814298
:members:
1429914299
:show-inheritance:
1430014300

14301+
datadog\_api\_client.v2.model.monitor\_notification\_rule\_filter\_scope module
14302+
-------------------------------------------------------------------------------
14303+
14304+
.. automodule:: datadog_api_client.v2.model.monitor_notification_rule_filter_scope
14305+
:members:
14306+
:show-inheritance:
14307+
1430114308
datadog\_api\_client.v2.model.monitor\_notification\_rule\_filter\_tags module
1430214309
------------------------------------------------------------------------------
1430314310

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
Create a monitor notification rule with scope returns "OK" response
3+
"""
4+
5+
from datadog_api_client import ApiClient, Configuration
6+
from datadog_api_client.v2.api.monitors_api import MonitorsApi
7+
from datadog_api_client.v2.model.monitor_notification_rule_attributes import MonitorNotificationRuleAttributes
8+
from datadog_api_client.v2.model.monitor_notification_rule_create_request import MonitorNotificationRuleCreateRequest
9+
from datadog_api_client.v2.model.monitor_notification_rule_create_request_data import (
10+
MonitorNotificationRuleCreateRequestData,
11+
)
12+
from datadog_api_client.v2.model.monitor_notification_rule_filter_scope import MonitorNotificationRuleFilterScope
13+
from datadog_api_client.v2.model.monitor_notification_rule_resource_type import MonitorNotificationRuleResourceType
14+
15+
body = MonitorNotificationRuleCreateRequest(
16+
data=MonitorNotificationRuleCreateRequestData(
17+
attributes=MonitorNotificationRuleAttributes(
18+
filter=MonitorNotificationRuleFilterScope(
19+
scope="test:example-monitor",
20+
),
21+
name="test rule",
22+
recipients=[
23+
"slack-test-channel",
24+
"jira-test",
25+
],
26+
),
27+
type=MonitorNotificationRuleResourceType.MONITOR_NOTIFICATION_RULE,
28+
),
29+
)
30+
31+
configuration = Configuration()
32+
with ApiClient(configuration) as api_client:
33+
api_instance = MonitorsApi(api_client)
34+
response = api_instance.create_monitor_notification_rule(body=body)
35+
36+
print(response)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
Update a monitor notification rule with scope returns "OK" response
3+
"""
4+
5+
from os import environ
6+
from datadog_api_client import ApiClient, Configuration
7+
from datadog_api_client.v2.api.monitors_api import MonitorsApi
8+
from datadog_api_client.v2.model.monitor_notification_rule_attributes import MonitorNotificationRuleAttributes
9+
from datadog_api_client.v2.model.monitor_notification_rule_filter_scope import MonitorNotificationRuleFilterScope
10+
from datadog_api_client.v2.model.monitor_notification_rule_resource_type import MonitorNotificationRuleResourceType
11+
from datadog_api_client.v2.model.monitor_notification_rule_update_request import MonitorNotificationRuleUpdateRequest
12+
from datadog_api_client.v2.model.monitor_notification_rule_update_request_data import (
13+
MonitorNotificationRuleUpdateRequestData,
14+
)
15+
16+
# there is a valid "monitor_notification_rule" in the system
17+
MONITOR_NOTIFICATION_RULE_DATA_ID = environ["MONITOR_NOTIFICATION_RULE_DATA_ID"]
18+
19+
body = MonitorNotificationRuleUpdateRequest(
20+
data=MonitorNotificationRuleUpdateRequestData(
21+
attributes=MonitorNotificationRuleAttributes(
22+
filter=MonitorNotificationRuleFilterScope(
23+
scope="test:example-monitor",
24+
),
25+
name="updated rule",
26+
recipients=[
27+
"slack-test-channel",
28+
],
29+
),
30+
id=MONITOR_NOTIFICATION_RULE_DATA_ID,
31+
type=MonitorNotificationRuleResourceType.MONITOR_NOTIFICATION_RULE,
32+
),
33+
)
34+
35+
configuration = Configuration()
36+
with ApiClient(configuration) as api_client:
37+
api_instance = MonitorsApi(api_client)
38+
response = api_instance.update_monitor_notification_rule(rule_id=MONITOR_NOTIFICATION_RULE_DATA_ID, body=body)
39+
40+
print(response)

src/datadog_api_client/v2/model/monitor_notification_rule_attributes.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
)
2020
from datadog_api_client.v2.model.monitor_notification_rule_filter import MonitorNotificationRuleFilter
2121
from datadog_api_client.v2.model.monitor_notification_rule_filter_tags import MonitorNotificationRuleFilterTags
22+
from datadog_api_client.v2.model.monitor_notification_rule_filter_scope import MonitorNotificationRuleFilterScope
2223

2324

2425
class MonitorNotificationRuleAttributes(ModelNormal):
@@ -62,14 +63,19 @@ def __init__(
6263
self_,
6364
name: str,
6465
conditional_recipients: Union[MonitorNotificationRuleConditionalRecipients, UnsetType] = unset,
65-
filter: Union[MonitorNotificationRuleFilter, MonitorNotificationRuleFilterTags, UnsetType] = unset,
66+
filter: Union[
67+
MonitorNotificationRuleFilter,
68+
MonitorNotificationRuleFilterTags,
69+
MonitorNotificationRuleFilterScope,
70+
UnsetType,
71+
] = unset,
6672
recipients: Union[List[str], UnsetType] = unset,
6773
**kwargs,
6874
):
6975
"""
7076
Attributes of the monitor notification rule.
7177
72-
:param conditional_recipients: Use conditional recipients to define different recipients for different situations.
78+
:param conditional_recipients: Use conditional recipients to define different recipients for different situations. Cannot be used with ``recipients``.
7379
:type conditional_recipients: MonitorNotificationRuleConditionalRecipients, optional
7480
7581
:param filter: Filter used to associate the notification rule with monitors.
@@ -78,7 +84,7 @@ def __init__(
7884
:param name: The name of the monitor notification rule.
7985
:type name: str
8086
81-
:param recipients: A list of recipients to notify. Uses the same format as the monitor ``message`` field. Must not start with an '@'.
87+
:param recipients: 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``.
8288
:type recipients: [str], optional
8389
"""
8490
if conditional_recipients is not unset:

src/datadog_api_client/v2/model/monitor_notification_rule_condition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __init__(self_, recipients: List[str], scope: str, **kwargs):
3939
"""
4040
Conditions for ``conditional_recipients``.
4141
42-
:param recipients: A list of recipients to notify. Uses the same format as the monitor ``message`` field. Must not start with an '@'.
42+
:param recipients: 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``.
4343
:type recipients: [str]
4444
4545
:param scope: The scope to which the monitor applied.

src/datadog_api_client/v2/model/monitor_notification_rule_conditional_recipients.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ def __init__(
5050
**kwargs,
5151
):
5252
"""
53-
Use conditional recipients to define different recipients for different situations.
53+
Use conditional recipients to define different recipients for different situations. Cannot be used with ``recipients``.
5454
5555
:param conditions: Conditions of the notification rule.
5656
:type conditions: [MonitorNotificationRuleCondition]
5757
58-
:param fallback_recipients: A list of recipients to notify. Uses the same format as the monitor ``message`` field. Must not start with an '@'.
58+
:param fallback_recipients: 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``.
5959
:type fallback_recipients: [str], optional
6060
"""
6161
if fallback_recipients is not unset:

src/datadog_api_client/v2/model/monitor_notification_rule_filter.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ def __init__(self, **kwargs):
1515
"""
1616
Filter used to associate the notification rule with monitors.
1717
18-
:param tags: A list of monitor tags.
18+
:param tags: A list of tags (key:value pairs), which can be used to filter monitor notifications on monitor and group tags.
1919
:type tags: [str]
20+
21+
:param scope: A scope composed of one or several key:value pairs, which can be used to filter monitor notifications on monitor and group tags.
22+
:type scope: str
2023
"""
2124
super().__init__(kwargs)
2225

@@ -30,9 +33,13 @@ def _composed_schemas(_):
3033
# classes don't exist yet because their module has not finished
3134
# loading
3235
from datadog_api_client.v2.model.monitor_notification_rule_filter_tags import MonitorNotificationRuleFilterTags
36+
from datadog_api_client.v2.model.monitor_notification_rule_filter_scope import (
37+
MonitorNotificationRuleFilterScope,
38+
)
3339

3440
return {
3541
"oneOf": [
3642
MonitorNotificationRuleFilterTags,
43+
MonitorNotificationRuleFilterScope,
3744
],
3845
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
from __future__ import annotations
5+
6+
7+
from datadog_api_client.model_utils import (
8+
ModelNormal,
9+
cached_property,
10+
)
11+
12+
13+
class MonitorNotificationRuleFilterScope(ModelNormal):
14+
validations = {
15+
"scope": {
16+
"max_length": 3000,
17+
"min_length": 1,
18+
},
19+
}
20+
21+
@cached_property
22+
def additional_properties_type(_):
23+
return None
24+
25+
@cached_property
26+
def openapi_types(_):
27+
return {
28+
"scope": (str,),
29+
}
30+
31+
attribute_map = {
32+
"scope": "scope",
33+
}
34+
35+
def __init__(self_, scope: str, **kwargs):
36+
"""
37+
Filter monitor notifications. A monitor notification must match the scope.
38+
39+
:param scope: A scope composed of one or several key:value pairs, which can be used to filter monitor notifications on monitor and group tags.
40+
:type scope: str
41+
"""
42+
super().__init__(kwargs)
43+
44+
self_.scope = scope

src/datadog_api_client/v2/model/monitor_notification_rule_filter_tags.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ def openapi_types(_):
3535

3636
def __init__(self_, tags: List[str], **kwargs):
3737
"""
38-
Filter monitors by tags. Monitors must match all tags.
38+
Filter monitor notifications by tags. A monitor notification must match all tags.
3939
40-
:param tags: A list of monitor tags.
40+
:param tags: A list of tags (key:value pairs), which can be used to filter monitor notifications on monitor and group tags.
4141
:type tags: [str]
4242
"""
4343
super().__init__(kwargs)

0 commit comments

Comments
 (0)