forked from DataDog/datadogpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsynthetics.py
More file actions
214 lines (148 loc) · 5.99 KB
/
Copy pathsynthetics.py
File metadata and controls
214 lines (148 loc) · 5.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# Unless explicitly stated otherwise all files in this repository are licensed under the BSD-3-Clause License.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2015-Present Datadog, Inc
from datadog.api.exceptions import ApiError
from datadog.api.resources import (
CreateableAPIResource,
GetableAPIResource,
ActionAPIResource,
UpdatableAPISyntheticsResource,
UpdatableAPISyntheticsSubResource,
ActionAPISyntheticsResource,
)
class Synthetics(
ActionAPIResource,
ActionAPISyntheticsResource,
CreateableAPIResource,
GetableAPIResource,
UpdatableAPISyntheticsResource,
UpdatableAPISyntheticsSubResource,
):
"""
A wrapper around Sythetics HTTP API.
"""
_resource_name = "synthetics"
_sub_resource_name = "status"
@classmethod
def get_test(cls, id, **params):
"""
Get test's details.
:param id: public id of the test to retrieve
:type id: string
:returns: Dictionary representing the API's JSON response
"""
# API path = "synthetics/tests/<public_test_id>
name = "tests"
return super(Synthetics, cls)._trigger_synthetics_class_action("GET", id=id, name=name, params=params)
@classmethod
def get_all_tests(cls, **params):
"""
Get all tests' details.
:returns: Dictionary representing the API's JSON response
"""
for p in ["locations", "tags"]:
if p in params and isinstance(params[p], list):
params[p] = ",".join(params[p])
# API path = "synthetics/tests"
return super(Synthetics, cls).get(id="tests", params=params)
@classmethod
def get_devices(cls, **params):
"""
Get a list of devices for browser checks
:returns: Dictionary representing the API's JSON response
"""
# API path = "synthetics/browser/devices"
name = "browser/devices"
return super(Synthetics, cls)._trigger_synthetics_class_action("GET", name=name, params=params)
@classmethod
def get_locations(cls, **params):
"""
Get a list of all available locations
:return: Dictionary representing the API's JSON response
"""
name = "locations"
# API path = "synthetics/locations
return super(Synthetics, cls)._trigger_synthetics_class_action("GET", name=name, params=params)
@classmethod
def get_results(cls, id, **params):
"""
Get the most recent results for a test
:param id: public id of the test to retrieve results for
:type id: id
:return: Dictionary representing the API's JSON response
"""
# API path = "synthetics/tests/<public_test_id>/results
path = "tests/{}/results".format(id)
return super(Synthetics, cls)._trigger_synthetics_class_action("GET", path, params=params)
@classmethod
def get_result(cls, id, result_id, **params):
"""
Get a specific result for a given test.
:param id: public ID of the test to retrieve the most recent result for
:type id: id
:param result_id: result ID of the test to retrieve the most recent result for
:type result_id: id
:returns: Dictionary representing the API's JSON response
"""
# API path = "synthetics/tests/results/<result_id>
path = "tests/{}/results/{}".format(id, result_id)
return super(Synthetics, cls)._trigger_synthetics_class_action("GET", path, params=params)
@classmethod
def create_test(cls, **params):
"""
Create a test
:param name: A unique name for the test
:type name: string
:param type: The type of test. Valid values are api and browser
:type type: string
:param subtype: required for SSL test - For a SSL API test, specify ssl as the value.
:Otherwise, you should omit this argument.
:type subtype: string
:param config: The test configuration, contains the request specification and the assertions.
:type config: dict
:param options: List of options to customize the test
:type options: dict
:param message: A description of the test
:type message: string
:param locations: A list of the locations to send the tests from
:type locations: list
:param tags: A list of tags used to filter the test
:type tags: list
:return: Dictionary representing the API's JSON response
"""
# API path = "synthetics/tests"
return super(Synthetics, cls).create(id="tests", **params)
@classmethod
def edit_test(cls, id, **params):
"""
Edit a test
:param id: Public id of the test to edit
:type id: string
:return: Dictionary representing the API's JSON response
"""
# API path = "synthetics/tests/<public_test_id>"
return super(Synthetics, cls).update_synthetics(id=id, **params)
@classmethod
def start_or_pause_test(cls, id, **body):
"""
Pause a given test
:param id: public id of the test to pause
:type id: string
:param new_status: mew status for the test
:type id: string
:returns: Dictionary representing the API's JSON response
"""
# API path = "synthetics/tests/<public_test_id>/status"
return super(Synthetics, cls).update_synthetics_items(id=id, **body)
@classmethod
def delete_test(cls, **body):
"""
Delete a test
:param public_ids: list of public IDs to delete corresponding tests
:type public_ids: list of strings
:return: Dictionary representing the API's JSON response
"""
if not isinstance(body["public_ids"], list):
raise ApiError("Parameter 'public_ids' must be a list")
# API path = "synthetics/tests/delete
return super(Synthetics, cls)._trigger_action("POST", name="synthetics", id="tests/delete", **body)