diff --git a/.generator/schemas/v1/openapi.yaml b/.generator/schemas/v1/openapi.yaml index e4c9496590..4fc8dbe378 100644 --- a/.generator/schemas/v1/openapi.yaml +++ b/.generator/schemas/v1/openapi.yaml @@ -7255,6 +7255,12 @@ components: Monitor: description: Object describing a monitor. properties: + assets: + description: The list of monitor assets tied to a monitor, which represents + key links for users to take action on monitor alerts (for example, runbooks). + items: + $ref: '#/components/schemas/MonitorAsset' + type: array created: description: Timestamp of the monitor creation. format: date-time @@ -7338,6 +7344,52 @@ components: - type - query type: object + MonitorAsset: + description: 'Represents key links tied to a monitor to help users take action + on alerts. + + This feature is in Preview and only available to users with the feature enabled.' + properties: + category: + $ref: '#/components/schemas/MonitorAssetCategory' + name: + description: Name for the monitor asset + example: Monitor Runbook + type: string + resource_key: + description: Represents the identifier of the internal Datadog resource + that this asset represents. IDs in this field should be passed in as strings. + example: '12345' + type: string + resource_type: + $ref: '#/components/schemas/MonitorAssetResourceType' + url: + description: URL link for the asset. For links with an internal resource + type set, this should be the relative path to where the Datadog domain + is appended internally. For external links, this should be the full URL + path. + example: /notebooks/12345 + type: string + required: + - name + - url + - category + type: object + MonitorAssetCategory: + description: Indicates the type of asset this entity represents on a monitor. + enum: + - runbook + example: runbook + type: string + x-enum-varnames: + - RUNBOOK + MonitorAssetResourceType: + description: Type of internal Datadog resource associated with a monitor asset. + enum: + - notebook + type: string + x-enum-varnames: + - NOTEBOOK MonitorDeviceID: description: ID of the device the Synthetics monitor is running on. Same as `SyntheticsDeviceID`. @@ -8452,6 +8504,13 @@ components: MonitorUpdateRequest: description: Object describing a monitor update request. properties: + assets: + description: The list of monitor assets tied to a monitor, which represents + key links for users to take action on monitor alerts (for example, runbooks). + items: + $ref: '#/components/schemas/MonitorAsset' + nullable: true + type: array created: description: Timestamp of the monitor creation. format: date-time @@ -31584,6 +31643,13 @@ paths: required: false schema: type: boolean + - description: If this argument is set to `true`, the returned data includes + all assets tied to this monitor. + in: query + name: with_assets + required: false + schema: + type: boolean responses: '200': content: diff --git a/docs/datadog_api_client.v1.model.rst b/docs/datadog_api_client.v1.model.rst index e2f9fc1e6d..4fa189d0f2 100644 --- a/docs/datadog_api_client.v1.model.rst +++ b/docs/datadog_api_client.v1.model.rst @@ -2223,6 +2223,27 @@ datadog\_api\_client.v1.model.monitor module :members: :show-inheritance: +datadog\_api\_client.v1.model.monitor\_asset module +--------------------------------------------------- + +.. automodule:: datadog_api_client.v1.model.monitor_asset + :members: + :show-inheritance: + +datadog\_api\_client.v1.model.monitor\_asset\_category module +------------------------------------------------------------- + +.. automodule:: datadog_api_client.v1.model.monitor_asset_category + :members: + :show-inheritance: + +datadog\_api\_client.v1.model.monitor\_asset\_resource\_type module +------------------------------------------------------------------- + +.. automodule:: datadog_api_client.v1.model.monitor_asset_resource_type + :members: + :show-inheritance: + datadog\_api\_client.v1.model.monitor\_device\_id module -------------------------------------------------------- diff --git a/examples/v1/monitors/CreateMonitor_3541766733.py b/examples/v1/monitors/CreateMonitor_3541766733.py new file mode 100644 index 0000000000..7a24db2530 --- /dev/null +++ b/examples/v1/monitors/CreateMonitor_3541766733.py @@ -0,0 +1,51 @@ +""" +Create a monitor with assets returns "OK" response +""" + +from datadog_api_client import ApiClient, Configuration +from datadog_api_client.v1.api.monitors_api import MonitorsApi +from datadog_api_client.v1.model.monitor import Monitor +from datadog_api_client.v1.model.monitor_asset import MonitorAsset +from datadog_api_client.v1.model.monitor_asset_category import MonitorAssetCategory +from datadog_api_client.v1.model.monitor_asset_resource_type import MonitorAssetResourceType +from datadog_api_client.v1.model.monitor_options import MonitorOptions +from datadog_api_client.v1.model.monitor_options_scheduling_options import MonitorOptionsSchedulingOptions +from datadog_api_client.v1.model.monitor_options_scheduling_options_evaluation_window import ( + MonitorOptionsSchedulingOptionsEvaluationWindow, +) +from datadog_api_client.v1.model.monitor_thresholds import MonitorThresholds +from datadog_api_client.v1.model.monitor_type import MonitorType + +body = Monitor( + assets=[ + MonitorAsset( + category=MonitorAssetCategory.RUNBOOK, + name="Monitor Runbook", + resource_key="12345", + resource_type=MonitorAssetResourceType.NOTEBOOK, + url="/notebooks/12345", + ), + ], + name="Example-Monitor", + type=MonitorType.METRIC_ALERT, + query="avg(current_1mo):avg:system.load.5{*} > 0.5", + message="some message Notify: @hipchat-channel", + options=MonitorOptions( + thresholds=MonitorThresholds( + critical=0.5, + ), + scheduling_options=MonitorOptionsSchedulingOptions( + evaluation_window=MonitorOptionsSchedulingOptionsEvaluationWindow( + day_starts="04:00", + month_starts=1, + ), + ), + ), +) + +configuration = Configuration() +with ApiClient(configuration) as api_client: + api_instance = MonitorsApi(api_client) + response = api_instance.create_monitor(body=body) + + print(response) diff --git a/src/datadog_api_client/v1/api/monitors_api.py b/src/datadog_api_client/v1/api/monitors_api.py index 0e6ce57e08..6770dc987b 100644 --- a/src/datadog_api_client/v1/api/monitors_api.py +++ b/src/datadog_api_client/v1/api/monitors_api.py @@ -135,6 +135,11 @@ def __init__(self, api_client=None): "attribute": "with_downtimes", "location": "query", }, + "with_assets": { + "openapi_types": (bool,), + "attribute": "with_assets", + "location": "query", + }, }, headers_map={ "accept": ["application/json"], @@ -640,6 +645,7 @@ def get_monitor( *, group_states: Union[str, UnsetType] = unset, with_downtimes: Union[bool, UnsetType] = unset, + with_assets: Union[bool, UnsetType] = unset, ) -> Monitor: """Get a monitor's details. @@ -651,6 +657,8 @@ def get_monitor( :type group_states: str, optional :param with_downtimes: If this argument is set to true, then the returned data includes all current active downtimes for the monitor. :type with_downtimes: bool, optional + :param with_assets: If this argument is set to ``true`` , the returned data includes all assets tied to this monitor. + :type with_assets: bool, optional :rtype: Monitor """ kwargs: Dict[str, Any] = {} @@ -662,6 +670,9 @@ def get_monitor( if with_downtimes is not unset: kwargs["with_downtimes"] = with_downtimes + if with_assets is not unset: + kwargs["with_assets"] = with_assets + return self._get_monitor_endpoint.call_with_http_info(**kwargs) def list_monitors( diff --git a/src/datadog_api_client/v1/model/monitor.py b/src/datadog_api_client/v1/model/monitor.py index ca835aaf03..7f30443f1e 100644 --- a/src/datadog_api_client/v1/model/monitor.py +++ b/src/datadog_api_client/v1/model/monitor.py @@ -16,6 +16,7 @@ if TYPE_CHECKING: + from datadog_api_client.v1.model.monitor_asset import MonitorAsset from datadog_api_client.v1.model.creator import Creator from datadog_api_client.v1.model.monitor_draft_status import MonitorDraftStatus from datadog_api_client.v1.model.matching_downtime import MatchingDowntime @@ -28,6 +29,7 @@ class Monitor(ModelNormal): @cached_property def openapi_types(_): + from datadog_api_client.v1.model.monitor_asset import MonitorAsset from datadog_api_client.v1.model.creator import Creator from datadog_api_client.v1.model.monitor_draft_status import MonitorDraftStatus from datadog_api_client.v1.model.matching_downtime import MatchingDowntime @@ -37,6 +39,7 @@ def openapi_types(_): from datadog_api_client.v1.model.monitor_type import MonitorType return { + "assets": ([MonitorAsset],), "created": (datetime,), "creator": (Creator,), "deleted": (datetime, none_type), @@ -58,6 +61,7 @@ def openapi_types(_): } attribute_map = { + "assets": "assets", "created": "created", "creator": "creator", "deleted": "deleted", @@ -92,6 +96,7 @@ def __init__( self_, query: str, type: MonitorType, + assets: Union[List[MonitorAsset], UnsetType] = unset, created: Union[datetime, UnsetType] = unset, creator: Union[Creator, UnsetType] = unset, deleted: Union[datetime, none_type, UnsetType] = unset, @@ -113,6 +118,9 @@ def __init__( """ Object describing a monitor. + :param assets: The list of monitor assets tied to a monitor, which represents key links for users to take action on monitor alerts (for example, runbooks). + :type assets: [MonitorAsset], optional + :param created: Timestamp of the monitor creation. :type created: datetime, optional @@ -172,6 +180,8 @@ def __init__( :param type: The type of the monitor. For more information about ``type`` , see the `monitor options `_ docs. :type type: MonitorType """ + if assets is not unset: + kwargs["assets"] = assets if created is not unset: kwargs["created"] = created if creator is not unset: diff --git a/src/datadog_api_client/v1/model/monitor_asset.py b/src/datadog_api_client/v1/model/monitor_asset.py new file mode 100644 index 0000000000..8c5c75cb58 --- /dev/null +++ b/src/datadog_api_client/v1/model/monitor_asset.py @@ -0,0 +1,79 @@ +# 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 Union, TYPE_CHECKING + +from datadog_api_client.model_utils import ( + ModelNormal, + cached_property, + unset, + UnsetType, +) + + +if TYPE_CHECKING: + from datadog_api_client.v1.model.monitor_asset_category import MonitorAssetCategory + from datadog_api_client.v1.model.monitor_asset_resource_type import MonitorAssetResourceType + + +class MonitorAsset(ModelNormal): + @cached_property + def openapi_types(_): + from datadog_api_client.v1.model.monitor_asset_category import MonitorAssetCategory + from datadog_api_client.v1.model.monitor_asset_resource_type import MonitorAssetResourceType + + return { + "category": (MonitorAssetCategory,), + "name": (str,), + "resource_key": (str,), + "resource_type": (MonitorAssetResourceType,), + "url": (str,), + } + + attribute_map = { + "category": "category", + "name": "name", + "resource_key": "resource_key", + "resource_type": "resource_type", + "url": "url", + } + + def __init__( + self_, + category: MonitorAssetCategory, + name: str, + url: str, + resource_key: Union[str, UnsetType] = unset, + resource_type: Union[MonitorAssetResourceType, UnsetType] = unset, + **kwargs, + ): + """ + Represents key links tied to a monitor to help users take action on alerts. + This feature is in Preview and only available to users with the feature enabled. + + :param category: Indicates the type of asset this entity represents on a monitor. + :type category: MonitorAssetCategory + + :param name: Name for the monitor asset + :type name: str + + :param resource_key: Represents the identifier of the internal Datadog resource that this asset represents. IDs in this field should be passed in as strings. + :type resource_key: str, optional + + :param resource_type: Type of internal Datadog resource associated with a monitor asset. + :type resource_type: MonitorAssetResourceType, optional + + :param url: URL link for the asset. For links with an internal resource type set, this should be the relative path to where the Datadog domain is appended internally. For external links, this should be the full URL path. + :type url: str + """ + if resource_key is not unset: + kwargs["resource_key"] = resource_key + if resource_type is not unset: + kwargs["resource_type"] = resource_type + super().__init__(kwargs) + + self_.category = category + self_.name = name + self_.url = url diff --git a/src/datadog_api_client/v1/model/monitor_asset_category.py b/src/datadog_api_client/v1/model/monitor_asset_category.py new file mode 100644 index 0000000000..9d0363ac31 --- /dev/null +++ b/src/datadog_api_client/v1/model/monitor_asset_category.py @@ -0,0 +1,35 @@ +# 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 datadog_api_client.model_utils import ( + ModelSimple, + cached_property, +) + +from typing import ClassVar + + +class MonitorAssetCategory(ModelSimple): + """ + Indicates the type of asset this entity represents on a monitor. + + :param value: If omitted defaults to "runbook". Must be one of ["runbook"]. + :type value: str + """ + + allowed_values = { + "runbook", + } + RUNBOOK: ClassVar["MonitorAssetCategory"] + + @cached_property + def openapi_types(_): + return { + "value": (str,), + } + + +MonitorAssetCategory.RUNBOOK = MonitorAssetCategory("runbook") diff --git a/src/datadog_api_client/v1/model/monitor_asset_resource_type.py b/src/datadog_api_client/v1/model/monitor_asset_resource_type.py new file mode 100644 index 0000000000..04ce28a715 --- /dev/null +++ b/src/datadog_api_client/v1/model/monitor_asset_resource_type.py @@ -0,0 +1,35 @@ +# 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 datadog_api_client.model_utils import ( + ModelSimple, + cached_property, +) + +from typing import ClassVar + + +class MonitorAssetResourceType(ModelSimple): + """ + Type of internal Datadog resource associated with a monitor asset. + + :param value: If omitted defaults to "notebook". Must be one of ["notebook"]. + :type value: str + """ + + allowed_values = { + "notebook", + } + NOTEBOOK: ClassVar["MonitorAssetResourceType"] + + @cached_property + def openapi_types(_): + return { + "value": (str,), + } + + +MonitorAssetResourceType.NOTEBOOK = MonitorAssetResourceType("notebook") diff --git a/src/datadog_api_client/v1/model/monitor_update_request.py b/src/datadog_api_client/v1/model/monitor_update_request.py index 59a99f7cd5..b9289ea5dc 100644 --- a/src/datadog_api_client/v1/model/monitor_update_request.py +++ b/src/datadog_api_client/v1/model/monitor_update_request.py @@ -16,6 +16,7 @@ if TYPE_CHECKING: + from datadog_api_client.v1.model.monitor_asset import MonitorAsset from datadog_api_client.v1.model.creator import Creator from datadog_api_client.v1.model.monitor_draft_status import MonitorDraftStatus from datadog_api_client.v1.model.monitor_options import MonitorOptions @@ -27,6 +28,7 @@ class MonitorUpdateRequest(ModelNormal): @cached_property def openapi_types(_): + from datadog_api_client.v1.model.monitor_asset import MonitorAsset from datadog_api_client.v1.model.creator import Creator from datadog_api_client.v1.model.monitor_draft_status import MonitorDraftStatus from datadog_api_client.v1.model.monitor_options import MonitorOptions @@ -35,6 +37,7 @@ def openapi_types(_): from datadog_api_client.v1.model.monitor_type import MonitorType return { + "assets": ([MonitorAsset], none_type), "created": (datetime,), "creator": (Creator,), "deleted": (datetime, none_type), @@ -55,6 +58,7 @@ def openapi_types(_): } attribute_map = { + "assets": "assets", "created": "created", "creator": "creator", "deleted": "deleted", @@ -86,6 +90,7 @@ def openapi_types(_): def __init__( self_, + assets: Union[List[MonitorAsset], none_type, UnsetType] = unset, created: Union[datetime, UnsetType] = unset, creator: Union[Creator, UnsetType] = unset, deleted: Union[datetime, none_type, UnsetType] = unset, @@ -108,6 +113,9 @@ def __init__( """ Object describing a monitor update request. + :param assets: The list of monitor assets tied to a monitor, which represents key links for users to take action on monitor alerts (for example, runbooks). + :type assets: [MonitorAsset], none_type, optional + :param created: Timestamp of the monitor creation. :type created: datetime, optional @@ -164,6 +172,8 @@ def __init__( :param type: The type of the monitor. For more information about ``type`` , see the `monitor options `_ docs. :type type: MonitorType, optional """ + if assets is not unset: + kwargs["assets"] = assets if created is not unset: kwargs["created"] = created if creator is not unset: diff --git a/src/datadog_api_client/v1/models/__init__.py b/src/datadog_api_client/v1/models/__init__.py index 001e6874d8..a2083acba6 100644 --- a/src/datadog_api_client/v1/models/__init__.py +++ b/src/datadog_api_client/v1/models/__init__.py @@ -353,6 +353,9 @@ from datadog_api_client.v1.model.metrics_query_response import MetricsQueryResponse from datadog_api_client.v1.model.metrics_query_unit import MetricsQueryUnit from datadog_api_client.v1.model.monitor import Monitor +from datadog_api_client.v1.model.monitor_asset import MonitorAsset +from datadog_api_client.v1.model.monitor_asset_category import MonitorAssetCategory +from datadog_api_client.v1.model.monitor_asset_resource_type import MonitorAssetResourceType from datadog_api_client.v1.model.monitor_device_id import MonitorDeviceID from datadog_api_client.v1.model.monitor_draft_status import MonitorDraftStatus from datadog_api_client.v1.model.monitor_formula_and_function_cost_aggregator import ( @@ -1435,6 +1438,9 @@ "MetricsQueryResponse", "MetricsQueryUnit", "Monitor", + "MonitorAsset", + "MonitorAssetCategory", + "MonitorAssetResourceType", "MonitorDeviceID", "MonitorDraftStatus", "MonitorFormulaAndFunctionCostAggregator", diff --git a/tests/v1/cassettes/test_scenarios/test_check_if_a_monitor_can_be_deleted_returns_ok_response.frozen b/tests/v1/cassettes/test_scenarios/test_check_if_a_monitor_can_be_deleted_returns_ok_response.frozen index 2dbbd94e28..9dda83bd1c 100644 --- a/tests/v1/cassettes/test_scenarios/test_check_if_a_monitor_can_be_deleted_returns_ok_response.frozen +++ b/tests/v1/cassettes/test_scenarios/test_check_if_a_monitor_can_be_deleted_returns_ok_response.frozen @@ -1 +1 @@ -2024-10-10T16:41:03.364Z \ No newline at end of file +2025-11-21T18:03:25.715Z \ No newline at end of file diff --git a/tests/v1/cassettes/test_scenarios/test_check_if_a_monitor_can_be_deleted_returns_ok_response.yaml b/tests/v1/cassettes/test_scenarios/test_check_if_a_monitor_can_be_deleted_returns_ok_response.yaml index 066a7254ef..ff2ec22804 100644 --- a/tests/v1/cassettes/test_scenarios/test_check_if_a_monitor_can_be_deleted_returns_ok_response.yaml +++ b/tests/v1/cassettes/test_scenarios/test_check_if_a_monitor_can_be_deleted_returns_ok_response.yaml @@ -1,9 +1,9 @@ interactions: - request: - body: '{"message":"some message Notify: @hipchat-channel","name":"Test-Check_if_a_monitor_can_be_deleted_returns_OK_response-1728578463","options":{"enable_logs_sample":true,"escalation_message":"the + body: '{"message":"some message Notify: @hipchat-channel","name":"Test-Check_if_a_monitor_can_be_deleted_returns_OK_response-1763748205","options":{"enable_logs_sample":true,"escalation_message":"the situation has escalated","evaluation_delay":700,"include_tags":true,"locked":false,"new_host_delay":600,"no_data_timeframe":null,"notification_preset_name":"hide_handles","notify_audit":false,"notify_no_data":false,"on_missing_data":"show_and_notify_no_data","renotify_interval":60,"require_full_window":true,"thresholds":{"critical":2,"warning":1},"timeout_h":24},"priority":3,"query":"logs(\"service:foo AND type:error\").index(\"main\").rollup(\"count\").by(\"source\").last(\"5m\") - > 2","tags":["test:testcheckifamonitorcanbedeletedreturnsokresponse1728578463","env:ci"],"type":"log + > 2","tags":["test:testcheckifamonitorcanbedeletedreturnsokresponse1763748205","env:ci"],"type":"log alert"}' headers: accept: @@ -14,12 +14,12 @@ interactions: uri: https://api.datadoghq.com/api/v1/monitor response: body: - string: '{"id":155845287,"org_id":321813,"type":"log alert","name":"Test-Check_if_a_monitor_can_be_deleted_returns_OK_response-1728578463","message":"some - message Notify: @hipchat-channel","tags":["test:testcheckifamonitorcanbedeletedreturnsokresponse1728578463","env:ci"],"query":"logs(\"service:foo + string: '{"id":238669218,"org_id":197728,"type":"log alert","name":"Test-Check_if_a_monitor_can_be_deleted_returns_OK_response-1763748205","message":"some + message Notify: @hipchat-channel","tags":["test:testcheckifamonitorcanbedeletedreturnsokresponse1763748205","env:ci"],"query":"logs(\"service:foo AND type:error\").index(\"main\").rollup(\"count\").by(\"source\").last(\"5m\") > 2","options":{"enable_logs_sample":true,"escalation_message":"the situation - has escalated","evaluation_delay":700,"include_tags":true,"locked":false,"new_host_delay":600,"no_data_timeframe":null,"notification_preset_name":"hide_handles","notify_audit":false,"notify_no_data":false,"on_missing_data":"show_and_notify_no_data","renotify_interval":60,"require_full_window":true,"thresholds":{"critical":2.0,"warning":1.0},"timeout_h":24,"groupby_simple_monitor":false,"silenced":{}},"multi":true,"created_at":1728578463000,"created":"2024-10-10T16:41:03.666877+00:00","modified":"2024-10-10T16:41:03.666877+00:00","deleted":null,"restricted_roles":null,"priority":3,"restriction_policy":null,"overall_state_modified":null,"overall_state":"No - Data","creator":{"name":null,"handle":"frog@datadoghq.com","email":"frog@datadoghq.com","id":1445416}} + has escalated","evaluation_delay":700,"include_tags":true,"locked":false,"new_host_delay":600,"no_data_timeframe":null,"notification_preset_name":"hide_handles","notify_audit":false,"notify_no_data":false,"on_missing_data":"show_and_notify_no_data","renotify_interval":60,"require_full_window":true,"thresholds":{"critical":2.0,"warning":1.0},"timeout_h":24,"groupby_simple_monitor":false,"silenced":{}},"multi":true,"created_at":1763748206000,"created":"2025-11-21T18:03:26.123200+00:00","modified":"2025-11-21T18:03:26.123200+00:00","deleted":null,"priority":3,"restricted_roles":null,"restriction_policy":null,"draft_status":"published","assets":[],"overall_state_modified":null,"overall_state":"No + Data","creator":{"name":"Kevin Pombo","handle":"kevin.pombo@datadoghq.com","email":"kevin.pombo@datadoghq.com","id":25712273}} ' headers: @@ -34,10 +34,10 @@ interactions: accept: - application/json method: GET - uri: https://api.datadoghq.com/api/v1/monitor/can_delete?monitor_ids=155845287 + uri: https://api.datadoghq.com/api/v1/monitor/can_delete?monitor_ids=238669218 response: body: - string: '{"data":{"ok":[155845287]},"errors":null} + string: '{"data":{"ok":[238669218]},"errors":null} ' headers: @@ -52,10 +52,10 @@ interactions: accept: - application/json method: DELETE - uri: https://api.datadoghq.com/api/v1/monitor/155845287 + uri: https://api.datadoghq.com/api/v1/monitor/238669218 response: body: - string: '{"deleted_monitor_id":155845287} + string: '{"deleted_monitor_id":238669218} ' headers: diff --git a/tests/v1/cassettes/test_scenarios/test_create_a_monitor_with_assets_returns_ok_response.frozen b/tests/v1/cassettes/test_scenarios/test_create_a_monitor_with_assets_returns_ok_response.frozen new file mode 100644 index 0000000000..12b1e5fed0 --- /dev/null +++ b/tests/v1/cassettes/test_scenarios/test_create_a_monitor_with_assets_returns_ok_response.frozen @@ -0,0 +1 @@ +2025-11-21T19:04:55.769Z \ No newline at end of file diff --git a/tests/v1/cassettes/test_scenarios/test_create_a_monitor_with_assets_returns_ok_response.yaml b/tests/v1/cassettes/test_scenarios/test_create_a_monitor_with_assets_returns_ok_response.yaml new file mode 100644 index 0000000000..59aa7f8cad --- /dev/null +++ b/tests/v1/cassettes/test_scenarios/test_create_a_monitor_with_assets_returns_ok_response.yaml @@ -0,0 +1,46 @@ +interactions: +- request: + body: '{"assets":[{"category":"runbook","name":"Monitor Runbook","resource_key":"12345","resource_type":"notebook","url":"/notebooks/12345"}],"message":"some + message Notify: @hipchat-channel","name":"Test-Create_a_monitor_with_assets_returns_OK_response-1763751895","options":{"scheduling_options":{"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5}},"query":"avg(current_1mo):avg:system.load.5{*} + > 0.5","type":"metric alert"}' + headers: + accept: + - application/json + content-type: + - application/json + method: POST + uri: https://api.datadoghq.com/api/v1/monitor + response: + body: + string: '{"id":238681257,"org_id":321813,"type":"query alert","name":"Test-Create_a_monitor_with_assets_returns_OK_response-1763751895","message":"some + message Notify: @hipchat-channel","tags":[],"query":"avg(current_1mo):avg:system.load.5{*} + > 0.5","options":{"scheduling_options":{"evaluation_window":{"day_starts":"04:00","month_starts":1}},"thresholds":{"critical":0.5},"notify_no_data":false,"notify_audit":false,"new_host_delay":300,"include_tags":true,"silenced":{}},"multi":false,"created_at":1763751896000,"created":"2025-11-21T19:04:56.060346+00:00","modified":"2025-11-21T19:04:56.060346+00:00","deleted":null,"priority":null,"restricted_roles":null,"restriction_policy":null,"draft_status":"published","assets":[{"monitor_id":238681257,"name":"Monitor + Runbook","category":"runbook","url":"/notebooks/12345","template_variables":{},"options":{},"resource_key":"12345","resource_type":"notebook"}],"overall_state_modified":null,"overall_state":"No + Data","creator":{"name":"CI Account","handle":"9919ec9b-ebc7-49ee-8dc8-03626e717cca","email":"team-intg-tools-libs-spam@datadoghq.com","id":2320499}} + + ' + headers: + content-type: + - application/json + status: + code: 200 + message: OK +- request: + body: null + headers: + accept: + - application/json + method: DELETE + uri: https://api.datadoghq.com/api/v1/monitor/238681257 + response: + body: + string: '{"deleted_monitor_id":238681257} + + ' + headers: + content-type: + - application/json + status: + code: 200 + message: OK +version: 1 diff --git a/tests/v1/features/monitors.feature b/tests/v1/features/monitors.feature index 64e72f698b..75a681927b 100644 --- a/tests/v1/features/monitors.feature +++ b/tests/v1/features/monitors.feature @@ -131,6 +131,18 @@ Feature: Monitors And the response "type" is equal to "log alert" And the response "query" is equal to "logs(\"service:foo AND type:error\").index(\"main\").rollup(\"count\").by(\"source\").last(\"5m\") > 2" + @team:DataDog/monitor-app + Scenario: Create a monitor with assets returns "OK" response + Given new "CreateMonitor" request + And body with value {"assets": [{"category": "runbook", "name": "Monitor Runbook", "resource_key": "12345", "resource_type": "notebook", "url": "/notebooks/12345"}], "name": "{{ unique }}", "type": "metric alert", "query": "avg(current_1mo):avg:system.load.5{*} > 0.5", "message": "some message Notify: @hipchat-channel", "options":{"thresholds":{"critical":0.5}, "scheduling_options":{"evaluation_window":{"day_starts":"04:00", "month_starts":1}}}} + When the request is sent + Then the response status is 200 OK + And the response "assets[0].category" is equal to "runbook" + And the response "assets[0].name" is equal to "Monitor Runbook" + And the response "assets[0].resource_key" is equal to "12345" + And the response "assets[0].resource_type" is equal to "notebook" + And the response "assets[0].url" is equal to "/notebooks/12345" + @team:DataDog/monitor-app Scenario: Create an Error Tracking monitor returns "OK" response Given new "CreateMonitor" request @@ -169,7 +181,7 @@ Feature: Monitors Scenario: Edit a monitor returns "Bad Request" response Given new "UpdateMonitor" request And request contains "monitor_id" parameter from "REPLACE.ME" - And body with value {"draft_status": "published", "options": {"evaluation_delay": null, "include_tags": true, "min_failure_duration": 0, "min_location_failed": 1, "new_group_delay": null, "new_host_delay": 300, "no_data_timeframe": null, "notification_preset_name": "show_all", "notify_audit": false, "notify_by": [], "on_missing_data": "default", "renotify_interval": null, "renotify_occurrences": null, "renotify_statuses": ["alert"], "scheduling_options": {"custom_schedule": {"recurrences": [{"rrule": "FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR", "start": "2023-08-31T16:30:00", "timezone": "Europe/Paris"}]}, "evaluation_window": {"day_starts": "04:00", "hour_starts": 0, "month_starts": 1, "timezone": "Europe/Paris"}}, "synthetics_check_id": null, "threshold_windows": {"recovery_window": null, "trigger_window": null}, "thresholds": {"critical_recovery": null, "ok": null, "unknown": null, "warning": null, "warning_recovery": null}, "timeout_h": null, "variables": [{"compute": {"aggregation": "avg", "interval": 60000, "metric": "@duration"}, "data_source": "rum", "group_by": [{"facet": "status", "limit": 10, "sort": {"aggregation": "avg", "order": "desc"}}], "indexes": ["days-3", "days-7"], "name": "query_errors", "search": {"query": "service:query"}}]}, "priority": null, "restricted_roles": [], "tags": [], "type": "query alert"} + And body with value {"assets": [{"category": "runbook", "name": "Monitor Runbook", "resource_key": "12345", "resource_type": "notebook", "url": "/notebooks/12345"}], "draft_status": "published", "options": {"evaluation_delay": null, "include_tags": true, "min_failure_duration": 0, "min_location_failed": 1, "new_group_delay": null, "new_host_delay": 300, "no_data_timeframe": null, "notification_preset_name": "show_all", "notify_audit": false, "notify_by": [], "on_missing_data": "default", "renotify_interval": null, "renotify_occurrences": null, "renotify_statuses": ["alert"], "scheduling_options": {"custom_schedule": {"recurrences": [{"rrule": "FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR", "start": "2023-08-31T16:30:00", "timezone": "Europe/Paris"}]}, "evaluation_window": {"day_starts": "04:00", "hour_starts": 0, "month_starts": 1, "timezone": "Europe/Paris"}}, "synthetics_check_id": null, "threshold_windows": {"recovery_window": null, "trigger_window": null}, "thresholds": {"critical_recovery": null, "ok": null, "unknown": null, "warning": null, "warning_recovery": null}, "timeout_h": null, "variables": [{"compute": {"aggregation": "avg", "interval": 60000, "metric": "@duration"}, "data_source": "rum", "group_by": [{"facet": "status", "limit": 10, "sort": {"aggregation": "avg", "order": "desc"}}], "indexes": ["days-3", "days-7"], "name": "query_errors", "search": {"query": "service:query"}}]}, "priority": null, "restricted_roles": [], "tags": [], "type": "query alert"} When the request is sent Then the response status is 400 Bad Request