forked from DataDog/datadogpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitors.py
More file actions
157 lines (121 loc) · 4.75 KB
/
Copy pathmonitors.py
File metadata and controls
157 lines (121 loc) · 4.75 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
# 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.resources import (
GetableAPIResource,
CreateableAPIResource,
UpdatableAPIResource,
ListableAPIResource,
DeletableAPIResource,
ActionAPIResource,
)
class Monitor(
GetableAPIResource,
CreateableAPIResource,
UpdatableAPIResource,
ListableAPIResource,
DeletableAPIResource,
ActionAPIResource,
):
"""
A wrapper around Monitor HTTP API.
"""
_resource_name = "monitor"
@classmethod
def get(cls, id, **params):
"""
Get monitor's details.
:param id: monitor to retrieve
:type id: id
:param group_states: string list indicating what, if any, group states to include
:type group_states: string list, strings are chosen from one or more \
from 'all', 'alert', 'warn', or 'no data'
:returns: Dictionary representing the API's JSON response
"""
if "group_states" in params and isinstance(params["group_states"], list):
params["group_states"] = ",".join(params["group_states"])
return super(Monitor, cls).get(id, **params)
@classmethod
def get_all(cls, **params):
"""
Get all monitor details.
:param group_states: string list indicating what, if any, group states to include
:type group_states: string list, strings are chosen from one or more \
from 'all', 'alert', 'warn', or 'no data'
:param name: name to filter the list of monitors by
:type name: string
:param tags: tags to filter the list of monitors by scope
:type tags: string list
:param monitor_tags: list indicating what service and/or custom tags, if any, \
should be used to filter the list of monitors
:type monitor_tags: string list
:returns: Dictionary representing the API's JSON response
"""
for p in ["group_states", "tags", "monitor_tags"]:
if p in params and isinstance(params[p], list):
params[p] = ",".join(params[p])
return super(Monitor, cls).get_all(**params)
@classmethod
def mute(cls, id, **body):
"""
Mute a monitor.
:param scope: scope to apply the mute
:type scope: string
:param end: timestamp for when the mute should end
:type end: POSIX timestamp
:returns: Dictionary representing the API's JSON response
"""
return super(Monitor, cls)._trigger_class_action("POST", "mute", id, **body)
@classmethod
def unmute(cls, id, **body):
"""
Unmute a monitor.
:param scope: scope to apply the unmute
:type scope: string
:param all_scopes: if True, clears mute settings for all scopes
:type all_scopes: boolean
:returns: Dictionary representing the API's JSON response
"""
return super(Monitor, cls)._trigger_class_action("POST", "unmute", id, **body)
@classmethod
def mute_all(cls):
"""
Globally mute monitors.
:returns: Dictionary representing the API's JSON response
"""
return super(Monitor, cls)._trigger_class_action("POST", "mute_all")
@classmethod
def unmute_all(cls):
"""
Cancel global monitor mute setting (does not remove mute settings for individual monitors).
:returns: Dictionary representing the API's JSON response
"""
return super(Monitor, cls)._trigger_class_action("POST", "unmute_all")
@classmethod
def search(cls, **params):
"""
Search monitors.
:returns: Dictionary representing the API's JSON response
"""
return super(Monitor, cls)._trigger_class_action("GET", "search", params=params)
@classmethod
def search_groups(cls, **params):
"""
Search monitor groups.
:returns: Dictionary representing the API's JSON response
"""
return super(Monitor, cls)._trigger_class_action("GET", "groups/search", params=params)
@classmethod
def can_delete(cls, **params):
"""
Checks if the monitors corresponding to the monitor ids can be deleted.
:returns: Dictionary representing the API's JSON response
"""
return super(Monitor, cls)._trigger_class_action("GET", "can_delete", params=params)
@classmethod
def validate(cls, **body):
"""
Checks if the monitors definition is valid.
:returns: Dictionary representing the API's JSON response
"""
return super(Monitor, cls)._trigger_class_action("POST", "validate", **body)