Skip to content

Commit c660509

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add MatchingDowntime to monitor schema and with_downtimes parameter to GetMonitor (#1475)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent fa505aa commit c660509

15 files changed

+322
-17
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.6.4",
7-
"regenerated": "2023-05-23 13:54:25.080716",
8-
"spec_repo_commit": "2ccd9d0a"
7+
"regenerated": "2023-05-23 19:09:17.970557",
8+
"spec_repo_commit": "d1e6ae92"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.4",
12-
"regenerated": "2023-05-23 13:54:25.093595",
13-
"spec_repo_commit": "2ccd9d0a"
12+
"regenerated": "2023-05-23 19:09:17.983042",
13+
"spec_repo_commit": "d1e6ae92"
1414
}
1515
}
1616
}

.generator/schemas/v1/openapi.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5829,6 +5829,43 @@ components:
58295829
type: string
58305830
x-enum-varnames:
58315831
- USER_AGENT_PARSER
5832+
MatchingDowntime:
5833+
description: Object describing a downtime that matches this monitor.
5834+
properties:
5835+
end:
5836+
description: POSIX timestamp to end the downtime.
5837+
example: 1412792983
5838+
format: int64
5839+
nullable: true
5840+
type: integer
5841+
id:
5842+
description: The downtime ID.
5843+
example: 1625
5844+
format: int64
5845+
readOnly: true
5846+
type: integer
5847+
scope:
5848+
description: 'The scope(s) to which the downtime applies. Must be in `key:value`
5849+
format. For example, `host:app2`.
5850+
5851+
Provide multiple scopes as a comma-separated list like `env:dev,env:prod`.
5852+
5853+
The resulting downtime applies to sources that matches ALL provided scopes
5854+
(`env:dev` **AND** `env:prod`).'
5855+
example:
5856+
- env:staging
5857+
items:
5858+
description: A scope. For example, `"env:staging"`.
5859+
type: string
5860+
type: array
5861+
start:
5862+
description: POSIX timestamp to start the downtime.
5863+
example: 1412792983
5864+
format: int64
5865+
type: integer
5866+
required:
5867+
- id
5868+
type: object
58325869
MetricContentEncoding:
58335870
default: deflate
58345871
description: HTTP header used to compress the media-type.
@@ -6109,6 +6146,11 @@ components:
61096146
format: int64
61106147
readOnly: true
61116148
type: integer
6149+
matching_downtimes:
6150+
description: A list of active downtimes that match this monitor.
6151+
items:
6152+
$ref: '#/components/schemas/MatchingDowntime'
6153+
type: array
61126154
message:
61136155
description: A message to include with notifications for this monitor.
61146156
type: string
@@ -25354,6 +25396,13 @@ paths:
2535425396
required: false
2535525397
schema:
2535625398
type: string
25399+
- description: If this argument is set to true, then the returned data includes
25400+
all current active downtimes for the monitor.
25401+
in: query
25402+
name: with_downtimes
25403+
required: false
25404+
schema:
25405+
type: boolean
2535725406
responses:
2535825407
'200':
2535925408
content:

docs/datadog_api_client.v1.model.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,6 +1779,13 @@ logs\_user\_agent\_parser\_type
17791779
:members:
17801780
:show-inheritance:
17811781

1782+
matching\_downtime
1783+
------------------
1784+
1785+
.. automodule:: datadog_api_client.v1.model.matching_downtime
1786+
:members:
1787+
:show-inheritance:
1788+
17821789
metric\_content\_encoding
17831790
-------------------------
17841791

examples/v1/monitors/GetMonitor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
api_instance = MonitorsApi(api_client)
1515
response = api_instance.get_monitor(
1616
monitor_id=int(MONITOR_ID),
17+
with_downtimes=True,
1718
)
1819

1920
print(response)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
Get a monitor's details with downtime returns "OK" response
3+
"""
4+
5+
from os import environ
6+
from datadog_api_client import ApiClient, Configuration
7+
from datadog_api_client.v1.api.monitors_api import MonitorsApi
8+
9+
# there is a valid "monitor" in the system
10+
MONITOR_ID = environ["MONITOR_ID"]
11+
12+
configuration = Configuration()
13+
with ApiClient(configuration) as api_client:
14+
api_instance = MonitorsApi(api_client)
15+
response = api_instance.get_monitor(
16+
monitor_id=int(MONITOR_ID),
17+
with_downtimes=True,
18+
)
19+
20+
print(response)

src/datadog_api_client/v1/api/monitors_api.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ def __init__(self, api_client=None):
131131
"attribute": "group_states",
132132
"location": "query",
133133
},
134+
"with_downtimes": {
135+
"openapi_types": (bool,),
136+
"attribute": "with_downtimes",
137+
"location": "query",
138+
},
134139
},
135140
headers_map={
136141
"accept": ["application/json"],
@@ -601,6 +606,7 @@ def get_monitor(
601606
monitor_id: int,
602607
*,
603608
group_states: Union[str, UnsetType] = unset,
609+
with_downtimes: Union[bool, UnsetType] = unset,
604610
) -> Monitor:
605611
"""Get a monitor's details.
606612
@@ -610,6 +616,8 @@ def get_monitor(
610616
:type monitor_id: int
611617
:param group_states: When specified, shows additional information about the group states. Choose one or more from ``all`` , ``alert`` , ``warn`` , and ``no data``.
612618
:type group_states: str, optional
619+
:param with_downtimes: If this argument is set to true, then the returned data includes all current active downtimes for the monitor.
620+
:type with_downtimes: bool, optional
613621
:rtype: Monitor
614622
"""
615623
kwargs: Dict[str, Any] = {}
@@ -618,6 +626,9 @@ def get_monitor(
618626
if group_states is not unset:
619627
kwargs["group_states"] = group_states
620628

629+
if with_downtimes is not unset:
630+
kwargs["with_downtimes"] = with_downtimes
631+
621632
return self._get_monitor_endpoint.call_with_http_info(**kwargs)
622633

623634
def list_monitors(
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
from typing import List, Union
7+
8+
from datadog_api_client.model_utils import (
9+
ModelNormal,
10+
cached_property,
11+
none_type,
12+
unset,
13+
UnsetType,
14+
)
15+
16+
17+
class MatchingDowntime(ModelNormal):
18+
@cached_property
19+
def openapi_types(_):
20+
return {
21+
"end": (int, none_type),
22+
"id": (int,),
23+
"scope": ([str],),
24+
"start": (int,),
25+
}
26+
27+
attribute_map = {
28+
"end": "end",
29+
"id": "id",
30+
"scope": "scope",
31+
"start": "start",
32+
}
33+
read_only_vars = {
34+
"id",
35+
}
36+
37+
def __init__(
38+
self_,
39+
id: int,
40+
end: Union[int, none_type, UnsetType] = unset,
41+
scope: Union[List[str], UnsetType] = unset,
42+
start: Union[int, UnsetType] = unset,
43+
**kwargs,
44+
):
45+
"""
46+
Object describing a downtime that matches this monitor.
47+
48+
:param end: POSIX timestamp to end the downtime.
49+
:type end: int, none_type, optional
50+
51+
:param id: The downtime ID.
52+
:type id: int
53+
54+
:param scope: The scope(s) to which the downtime applies. Must be in ``key:value`` format. For example, ``host:app2``.
55+
Provide multiple scopes as a comma-separated list like ``env:dev,env:prod``.
56+
The resulting downtime applies to sources that matches ALL provided scopes ( ``env:dev`` **AND** ``env:prod`` ).
57+
:type scope: [str], optional
58+
59+
:param start: POSIX timestamp to start the downtime.
60+
:type start: int, optional
61+
"""
62+
if end is not unset:
63+
kwargs["end"] = end
64+
if scope is not unset:
65+
kwargs["scope"] = scope
66+
if start is not unset:
67+
kwargs["start"] = start
68+
super().__init__(kwargs)
69+
70+
self_.id = id

src/datadog_api_client/v1/model/monitor.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
if TYPE_CHECKING:
1919
from datadog_api_client.v1.model.creator import Creator
20+
from datadog_api_client.v1.model.matching_downtime import MatchingDowntime
2021
from datadog_api_client.v1.model.monitor_options import MonitorOptions
2122
from datadog_api_client.v1.model.monitor_overall_states import MonitorOverallStates
2223
from datadog_api_client.v1.model.monitor_state import MonitorState
@@ -34,6 +35,7 @@ class Monitor(ModelNormal):
3435
@cached_property
3536
def openapi_types(_):
3637
from datadog_api_client.v1.model.creator import Creator
38+
from datadog_api_client.v1.model.matching_downtime import MatchingDowntime
3739
from datadog_api_client.v1.model.monitor_options import MonitorOptions
3840
from datadog_api_client.v1.model.monitor_overall_states import MonitorOverallStates
3941
from datadog_api_client.v1.model.monitor_state import MonitorState
@@ -44,6 +46,7 @@ def openapi_types(_):
4446
"creator": (Creator,),
4547
"deleted": (datetime, none_type),
4648
"id": (int,),
49+
"matching_downtimes": ([MatchingDowntime],),
4750
"message": (str,),
4851
"modified": (datetime,),
4952
"multi": (bool,),
@@ -63,6 +66,7 @@ def openapi_types(_):
6366
"creator": "creator",
6467
"deleted": "deleted",
6568
"id": "id",
69+
"matching_downtimes": "matching_downtimes",
6670
"message": "message",
6771
"modified": "modified",
6872
"multi": "multi",
@@ -95,6 +99,7 @@ def __init__(
9599
creator: Union[Creator, UnsetType] = unset,
96100
deleted: Union[datetime, none_type, UnsetType] = unset,
97101
id: Union[int, UnsetType] = unset,
102+
matching_downtimes: Union[List[MatchingDowntime], UnsetType] = unset,
98103
message: Union[str, UnsetType] = unset,
99104
modified: Union[datetime, UnsetType] = unset,
100105
multi: Union[bool, UnsetType] = unset,
@@ -122,6 +127,9 @@ def __init__(
122127
:param id: ID of this monitor.
123128
:type id: int, optional
124129
130+
:param matching_downtimes: A list of active downtimes that match this monitor.
131+
:type matching_downtimes: [MatchingDowntime], optional
132+
125133
:param message: A message to include with notifications for this monitor.
126134
:type message: str, optional
127135
@@ -166,6 +174,8 @@ def __init__(
166174
kwargs["deleted"] = deleted
167175
if id is not unset:
168176
kwargs["id"] = id
177+
if matching_downtimes is not unset:
178+
kwargs["matching_downtimes"] = matching_downtimes
169179
if message is not unset:
170180
kwargs["message"] = message
171181
if modified is not unset:

src/datadog_api_client/v1/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@
282282
from datadog_api_client.v1.model.logs_url_parser_type import LogsURLParserType
283283
from datadog_api_client.v1.model.logs_user_agent_parser import LogsUserAgentParser
284284
from datadog_api_client.v1.model.logs_user_agent_parser_type import LogsUserAgentParserType
285+
from datadog_api_client.v1.model.matching_downtime import MatchingDowntime
285286
from datadog_api_client.v1.model.metric_content_encoding import MetricContentEncoding
286287
from datadog_api_client.v1.model.metric_metadata import MetricMetadata
287288
from datadog_api_client.v1.model.metric_search_response import MetricSearchResponse
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2023-01-18T18:37:19.697Z
1+
2023-05-22T17:02:26.784Z

tests/v1/cassettes/test_scenarios/test_get_a_monitors_details_returns_ok_response.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
interactions:
22
- request:
3-
body: '{"message":"some message Notify: @hipchat-channel","name":"Test-Get_a_monitor_s_details_returns_OK_response-1674067039","options":{"enable_logs_sample":true,"escalation_message":"the
3+
body: '{"message":"some message Notify: @hipchat-channel","name":"Test-Get_a_monitor_s_details_returns_OK_response-1684774946","options":{"enable_logs_sample":true,"escalation_message":"the
44
situation has escalated","evaluation_delay":700,"groupby_simple_monitor":true,"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
55
AND type:error\").index(\"main\").rollup(\"count\").by(\"source\").last(\"5m\")
6-
> 2","tags":["test:testgetamonitorsdetailsreturnsokresponse1674067039","env:ci"],"type":"log
6+
> 2","tags":["test:testgetamonitorsdetailsreturnsokresponse1684774946","env:ci"],"type":"log
77
alert"}'
88
headers:
99
accept:
@@ -14,11 +14,11 @@ interactions:
1414
uri: https://api.datadoghq.com/api/v1/monitor
1515
response:
1616
body:
17-
string: '{"id":108260305,"org_id":321813,"type":"log alert","name":"Test-Get_a_monitor_s_details_returns_OK_response-1674067039","message":"some
18-
message Notify: @hipchat-channel","tags":["test:testgetamonitorsdetailsreturnsokresponse1674067039","env:ci"],"query":"logs(\"service:foo
17+
string: '{"id":119735290,"org_id":321813,"type":"log alert","name":"Test-Get_a_monitor_s_details_returns_OK_response-1684774946","message":"some
18+
message Notify: @hipchat-channel","tags":["test:testgetamonitorsdetailsreturnsokresponse1684774946","env:ci"],"query":"logs(\"service:foo
1919
AND type:error\").index(\"main\").rollup(\"count\").by(\"source\").last(\"5m\")
2020
> 2","options":{"enable_logs_sample":true,"escalation_message":"the situation
21-
has escalated","evaluation_delay":700,"groupby_simple_monitor":true,"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,"silenced":{}},"multi":true,"created_at":1674067039000,"created":"2023-01-18T18:37:19.812019+00:00","modified":"2023-01-18T18:37:19.812019+00:00","deleted":null,"restricted_roles":null,"priority":3,"overall_state_modified":null,"overall_state":"No
21+
has escalated","evaluation_delay":700,"groupby_simple_monitor":true,"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,"silenced":{}},"multi":true,"created_at":1684774946000,"created":"2023-05-22T17:02:26.996650+00:00","modified":"2023-05-22T17:02:26.996650+00:00","deleted":null,"restricted_roles":null,"priority":3,"overall_state_modified":null,"overall_state":"No
2222
Data","creator":{"name":null,"handle":"[email protected]","email":"[email protected]","id":1445416}}
2323
2424
'
@@ -34,15 +34,15 @@ interactions:
3434
accept:
3535
- application/json
3636
method: GET
37-
uri: https://api.datadoghq.com/api/v1/monitor/108260305
37+
uri: https://api.datadoghq.com/api/v1/monitor/119735290?with_downtimes=true
3838
response:
3939
body:
40-
string: '{"id":108260305,"org_id":321813,"type":"log alert","name":"Test-Get_a_monitor_s_details_returns_OK_response-1674067039","message":"some
41-
message Notify: @hipchat-channel","tags":["test:testgetamonitorsdetailsreturnsokresponse1674067039","env:ci"],"query":"logs(\"service:foo
40+
string: '{"id":119735290,"org_id":321813,"type":"log alert","name":"Test-Get_a_monitor_s_details_returns_OK_response-1684774946","message":"some
41+
message Notify: @hipchat-channel","tags":["test:testgetamonitorsdetailsreturnsokresponse1684774946","env:ci"],"query":"logs(\"service:foo
4242
AND type:error\").index(\"main\").rollup(\"count\").by(\"source\").last(\"5m\")
4343
> 2","options":{"enable_logs_sample":true,"escalation_message":"the situation
44-
has escalated","evaluation_delay":700,"groupby_simple_monitor":true,"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,"silenced":{}},"multi":true,"created_at":1674067039000,"created":"2023-01-18T18:37:19.812019+00:00","modified":"2023-01-18T18:37:19.812019+00:00","deleted":null,"restricted_roles":null,"priority":3,"overall_state_modified":null,"overall_state":"No
45-
Data","creator":{"name":null,"handle":"[email protected]","email":"[email protected]","id":1445416}}
44+
has escalated","evaluation_delay":700,"groupby_simple_monitor":true,"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,"silenced":{}},"multi":true,"created_at":1684774946000,"created":"2023-05-22T17:02:26.996650+00:00","modified":"2023-05-22T17:02:26.996650+00:00","deleted":null,"restricted_roles":null,"priority":3,"overall_state_modified":null,"overall_state":"No
45+
Data","creator":{"name":null,"handle":"[email protected]","email":"[email protected]","id":1445416},"matching_downtimes":[]}
4646
4747
'
4848
headers:
@@ -57,10 +57,10 @@ interactions:
5757
accept:
5858
- application/json
5959
method: DELETE
60-
uri: https://api.datadoghq.com/api/v1/monitor/108260305
60+
uri: https://api.datadoghq.com/api/v1/monitor/119735290
6161
response:
6262
body:
63-
string: '{"deleted_monitor_id":108260305}
63+
string: '{"deleted_monitor_id":119735290}
6464
6565
'
6666
headers:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2023-05-22T21:15:19.763Z

0 commit comments

Comments
 (0)