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
38 changes: 38 additions & 0 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29565,6 +29565,8 @@ components:
additionalProperties: false
description: Attributes of the monitor notification rule.
properties:
conditional_recipients:
$ref: '#/components/schemas/MonitorNotificationRuleConditionalRecipients'
filter:
$ref: '#/components/schemas/MonitorNotificationRuleFilter'
name:
Expand All @@ -29573,8 +29575,36 @@ components:
$ref: '#/components/schemas/MonitorNotificationRuleRecipients'
required:
- name
type: object
MonitorNotificationRuleCondition:
description: Conditions for `conditional_recipients`.
properties:
recipients:
$ref: '#/components/schemas/MonitorNotificationRuleRecipients'
scope:
$ref: '#/components/schemas/MonitorNotificationRuleScope'
required:
- scope
- recipients
type: object
MonitorNotificationRuleConditionalRecipients:
description: Use conditional recipients to define different recipients for different
situations.
properties:
conditions:
description: Conditions of the notification rule.
items:
$ref: '#/components/schemas/MonitorNotificationRuleCondition'
maxItems: 10
minItems: 1
type: array
fallback_recipients:
$ref: '#/components/schemas/MonitorNotificationRuleRecipients'
description: If none of the `conditions` applied, `fallback_recipients`
will get notified.
required:
- conditions
type: object
MonitorNotificationRuleCreateRequest:
description: Request for creating a monitor notification rule.
properties:
Expand Down Expand Up @@ -29714,6 +29744,8 @@ components:
additionalProperties: {}
description: Attributes of the monitor notification rule.
properties:
conditional_recipients:
$ref: '#/components/schemas/MonitorNotificationRuleConditionalRecipients'
created:
description: Creation time of the monitor notification rule.
example: 2020-01-02 03:04:00+00:00
Expand All @@ -29735,6 +29767,12 @@ 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
14 changes: 14 additions & 0 deletions docs/datadog_api_client.v2.model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12835,6 +12835,20 @@ datadog\_api\_client.v2.model.monitor\_notification\_rule\_attributes module
:members:
:show-inheritance:

datadog\_api\_client.v2.model.monitor\_notification\_rule\_condition module
---------------------------------------------------------------------------

.. automodule:: datadog_api_client.v2.model.monitor_notification_rule_condition
:members:
:show-inheritance:

datadog\_api\_client.v2.model.monitor\_notification\_rule\_conditional\_recipients module
-----------------------------------------------------------------------------------------

.. automodule:: datadog_api_client.v2.model.monitor_notification_rule_conditional_recipients
:members:
:show-inheritance:

datadog\_api\_client.v2.model.monitor\_notification\_rule\_create\_request module
---------------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""
Create a monitor notification rule with conditional recipients returns "OK" response
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.monitors_api import MonitorsApi
from datadog_api_client.v2.model.monitor_notification_rule_attributes import MonitorNotificationRuleAttributes
from datadog_api_client.v2.model.monitor_notification_rule_condition import MonitorNotificationRuleCondition
from datadog_api_client.v2.model.monitor_notification_rule_conditional_recipients import (
MonitorNotificationRuleConditionalRecipients,
)
from datadog_api_client.v2.model.monitor_notification_rule_create_request import MonitorNotificationRuleCreateRequest
from datadog_api_client.v2.model.monitor_notification_rule_create_request_data import (
MonitorNotificationRuleCreateRequestData,
)
from datadog_api_client.v2.model.monitor_notification_rule_filter_tags import MonitorNotificationRuleFilterTags
from datadog_api_client.v2.model.monitor_notification_rule_resource_type import MonitorNotificationRuleResourceType

body = MonitorNotificationRuleCreateRequest(
data=MonitorNotificationRuleCreateRequestData(
attributes=MonitorNotificationRuleAttributes(
filter=MonitorNotificationRuleFilterTags(
tags=[
"test:example-monitor",
],
),
name="test rule",
conditional_recipients=MonitorNotificationRuleConditionalRecipients(
conditions=[
MonitorNotificationRuleCondition(
scope="transition_type:is_alert",
recipients=[
"slack-test-channel",
"jira-test",
],
),
],
),
),
type=MonitorNotificationRuleResourceType.MONITOR_NOTIFICATION_RULE,
),
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
api_instance = MonitorsApi(api_client)
response = api_instance.create_monitor_notification_rule(body=body)

print(response)
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
Update a monitor notification rule with conditional_recipients returns "OK" response
"""

from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.monitors_api import MonitorsApi
from datadog_api_client.v2.model.monitor_notification_rule_attributes import MonitorNotificationRuleAttributes
from datadog_api_client.v2.model.monitor_notification_rule_condition import MonitorNotificationRuleCondition
from datadog_api_client.v2.model.monitor_notification_rule_conditional_recipients import (
MonitorNotificationRuleConditionalRecipients,
)
from datadog_api_client.v2.model.monitor_notification_rule_filter_tags import MonitorNotificationRuleFilterTags
from datadog_api_client.v2.model.monitor_notification_rule_resource_type import MonitorNotificationRuleResourceType
from datadog_api_client.v2.model.monitor_notification_rule_update_request import MonitorNotificationRuleUpdateRequest
from datadog_api_client.v2.model.monitor_notification_rule_update_request_data import (
MonitorNotificationRuleUpdateRequestData,
)

# there is a valid "monitor_notification_rule" in the system
MONITOR_NOTIFICATION_RULE_DATA_ID = environ["MONITOR_NOTIFICATION_RULE_DATA_ID"]

body = MonitorNotificationRuleUpdateRequest(
data=MonitorNotificationRuleUpdateRequestData(
attributes=MonitorNotificationRuleAttributes(
filter=MonitorNotificationRuleFilterTags(
tags=[
"test:example-monitor",
"host:abc",
],
),
name="updated rule",
conditional_recipients=MonitorNotificationRuleConditionalRecipients(
conditions=[
MonitorNotificationRuleCondition(
scope="transition_type:is_alert",
recipients=[
"slack-test-channel",
"jira-test",
],
),
],
),
),
id=MONITOR_NOTIFICATION_RULE_DATA_ID,
type=MonitorNotificationRuleResourceType.MONITOR_NOTIFICATION_RULE,
),
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
api_instance = MonitorsApi(api_client)
response = api_instance.update_monitor_notification_rule(rule_id=MONITOR_NOTIFICATION_RULE_DATA_ID, body=body)

print(response)
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@


if TYPE_CHECKING:
from datadog_api_client.v2.model.monitor_notification_rule_conditional_recipients import (
MonitorNotificationRuleConditionalRecipients,
)
from datadog_api_client.v2.model.monitor_notification_rule_filter import MonitorNotificationRuleFilter
from datadog_api_client.v2.model.monitor_notification_rule_filter_tags import MonitorNotificationRuleFilterTags

Expand All @@ -36,15 +39,20 @@ def additional_properties_type(_):

@cached_property
def openapi_types(_):
from datadog_api_client.v2.model.monitor_notification_rule_conditional_recipients import (
MonitorNotificationRuleConditionalRecipients,
)
from datadog_api_client.v2.model.monitor_notification_rule_filter import MonitorNotificationRuleFilter

return {
"conditional_recipients": (MonitorNotificationRuleConditionalRecipients,),
"filter": (MonitorNotificationRuleFilter,),
"name": (str,),
"recipients": ([str],),
}

attribute_map = {
"conditional_recipients": "conditional_recipients",
"filter": "filter",
"name": "name",
"recipients": "recipients",
Expand All @@ -53,25 +61,32 @@ def openapi_types(_):
def __init__(
self_,
name: str,
recipients: List[str],
conditional_recipients: Union[MonitorNotificationRuleConditionalRecipients, UnsetType] = unset,
filter: Union[MonitorNotificationRuleFilter, MonitorNotificationRuleFilterTags, UnsetType] = unset,
recipients: Union[List[str], UnsetType] = unset,
**kwargs,
):
"""
Attributes of the monitor notification rule.
:param conditional_recipients: Use conditional recipients to define different recipients for different situations.
:type conditional_recipients: MonitorNotificationRuleConditionalRecipients, optional
:param filter: Filter used to associate the notification rule with monitors.
:type filter: MonitorNotificationRuleFilter, optional
:param name: The name of the monitor notification rule.
:type name: str
:param recipients: A list of recipients to notify. Uses the same format as the monitor ``message`` field. Must not start with an '@'.
:type recipients: [str]
:type recipients: [str], optional
"""
if conditional_recipients is not unset:
kwargs["conditional_recipients"] = conditional_recipients
if filter is not unset:
kwargs["filter"] = filter
if recipients is not unset:
kwargs["recipients"] = recipients
super().__init__(kwargs)

self_.name = name
self_.recipients = recipients
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 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.
from __future__ import annotations

from typing import List

from datadog_api_client.model_utils import (
ModelNormal,
cached_property,
)


class MonitorNotificationRuleCondition(ModelNormal):
validations = {
"recipients": {
"max_items": 20,
"min_items": 1,
},
"scope": {
"max_length": 3000,
"min_length": 1,
},
}

@cached_property
def openapi_types(_):
return {
"recipients": ([str],),
"scope": (str,),
}

attribute_map = {
"recipients": "recipients",
"scope": "scope",
}

def __init__(self_, recipients: List[str], scope: str, **kwargs):
"""
Conditions for ``conditional_recipients``.
:param recipients: A list of recipients to notify. Uses the same format as the monitor ``message`` field. Must not start with an '@'.
:type recipients: [str]
:param scope: The scope to which the monitor applied.
:type scope: str
"""
super().__init__(kwargs)

self_.recipients = recipients
self_.scope = scope
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 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.
from __future__ import annotations

from typing import List, Union, TYPE_CHECKING

from datadog_api_client.model_utils import (
ModelNormal,
cached_property,
unset,
UnsetType,
)


if TYPE_CHECKING:
from datadog_api_client.v2.model.monitor_notification_rule_condition import MonitorNotificationRuleCondition


class MonitorNotificationRuleConditionalRecipients(ModelNormal):
validations = {
"conditions": {
"max_items": 10,
"min_items": 1,
},
"fallback_recipients": {
"max_items": 20,
"min_items": 1,
},
}

@cached_property
def openapi_types(_):
from datadog_api_client.v2.model.monitor_notification_rule_condition import MonitorNotificationRuleCondition

return {
"conditions": ([MonitorNotificationRuleCondition],),
"fallback_recipients": ([str],),
}

attribute_map = {
"conditions": "conditions",
"fallback_recipients": "fallback_recipients",
}

def __init__(
self_,
conditions: List[MonitorNotificationRuleCondition],
fallback_recipients: Union[List[str], UnsetType] = unset,
**kwargs,
):
"""
Use conditional recipients to define different recipients for different situations.

:param conditions: Conditions of the notification rule.
:type conditions: [MonitorNotificationRuleCondition]

:param fallback_recipients: A list of recipients to notify. Uses the same format as the monitor ``message`` field. Must not start with an '@'.
:type fallback_recipients: [str], optional
"""
if fallback_recipients is not unset:
kwargs["fallback_recipients"] = fallback_recipients
super().__init__(kwargs)

self_.conditions = conditions
Loading