Skip to content
Open
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
66 changes: 66 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
21 changes: 21 additions & 0 deletions docs/datadog_api_client.v1.model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------------------------------------------

Expand Down
51 changes: 51 additions & 0 deletions examples/v1/monitors/CreateMonitor_3541766733.py
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 11 additions & 0 deletions src/datadog_api_client/v1/api/monitors_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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.

Expand All @@ -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] = {}
Expand All @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions src/datadog_api_client/v1/model/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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),
Expand All @@ -58,6 +61,7 @@ def openapi_types(_):
}

attribute_map = {
"assets": "assets",
"created": "created",
"creator": "creator",
"deleted": "deleted",
Expand Down Expand Up @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -172,6 +180,8 @@ def __init__(
:param type: The type of the monitor. For more information about ``type`` , see the `monitor options <https://docs.datadoghq.com/monitors/guide/monitor_api_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:
Expand Down
79 changes: 79 additions & 0 deletions src/datadog_api_client/v1/model/monitor_asset.py
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions src/datadog_api_client/v1/model/monitor_asset_category.py
Original file line number Diff line number Diff line change
@@ -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")
Loading