dogapi-demo 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.tailor +106 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.md +157 -0
- data/Gemfile +16 -0
- data/LICENSE +25 -0
- data/README.rdoc +143 -0
- data/Rakefile +50 -0
- data/dogapi-demo.gemspec +32 -0
- data/examples/Capfile +19 -0
- data/examples/custom_event.rb +37 -0
- data/examples/custom_metric.rb +35 -0
- data/lib/capistrano/README.md +13 -0
- data/lib/capistrano/datadog.rb +125 -0
- data/lib/capistrano/datadog/v2.rb +74 -0
- data/lib/capistrano/datadog/v3.rb +64 -0
- data/lib/dogapi-demo.rb +5 -0
- data/lib/dogapi-demo/common.rb +168 -0
- data/lib/dogapi-demo/event.rb +129 -0
- data/lib/dogapi-demo/facade.rb +475 -0
- data/lib/dogapi-demo/metric.rb +34 -0
- data/lib/dogapi-demo/v1.rb +13 -0
- data/lib/dogapi-demo/v1/alert.rb +112 -0
- data/lib/dogapi-demo/v1/comment.rb +62 -0
- data/lib/dogapi-demo/v1/dash.rb +94 -0
- data/lib/dogapi-demo/v1/embed.rb +106 -0
- data/lib/dogapi-demo/v1/event.rb +101 -0
- data/lib/dogapi-demo/v1/metric.rb +118 -0
- data/lib/dogapi-demo/v1/monitor.rb +264 -0
- data/lib/dogapi-demo/v1/screenboard.rb +110 -0
- data/lib/dogapi-demo/v1/search.rb +27 -0
- data/lib/dogapi-demo/v1/service_check.rb +32 -0
- data/lib/dogapi-demo/v1/snapshot.rb +30 -0
- data/lib/dogapi-demo/v1/tag.rb +141 -0
- data/lib/dogapi-demo/v1/user.rb +113 -0
- data/lib/dogapi-demo/version.rb +3 -0
- data/spec/alerts_spec.rb +33 -0
- data/spec/common_spec.rb +37 -0
- data/spec/facade_spec.rb +166 -0
- data/spec/spec_helper.rb +30 -0
- data/spec/support/cassettes/Alerts/create/returns_HTTP_code_200.yml +114 -0
- data/spec/support/cassettes/Alerts/create/returns_a_valid_event_ID.yml +114 -0
- data/spec/support/cassettes/Alerts/create/returns_the_same_query_as_sent.yml +114 -0
- data/spec/support/cassettes/Facade/Events/emits_aggregate_events.yml +193 -0
- data/spec/support/cassettes/Facade/Events/emits_events_and_retrieves_them.yml +100 -0
- data/spec/support/cassettes/Facade/Events/emits_events_with_specified_priority.yml +98 -0
- data/spec/support/cassettes/Facade/Tags/adds_updates_and_detaches_tags.yml +442 -0
- data/tests/test_alerts.rb +38 -0
- data/tests/test_base.rb +30 -0
- data/tests/test_client.rb +23 -0
- data/tests/test_comments.rb +39 -0
- data/tests/test_dashes.rb +85 -0
- data/tests/test_embed.rb +194 -0
- data/tests/test_monitors.rb +192 -0
- data/tests/test_screenboard.rb +90 -0
- data/tests/test_search.rb +20 -0
- data/tests/test_snapshot.rb +28 -0
- data/tests/test_users.rb +65 -0
- metadata +178 -0
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'dogapi-demo'
|
2
|
+
|
3
|
+
module DogapiDemo
|
4
|
+
class V1 # for namespacing
|
5
|
+
|
6
|
+
# Event-specific client affording more granular control than the simple DogapiDemo::Client
|
7
|
+
class MetricService < DogapiDemo::APIService
|
8
|
+
|
9
|
+
API_VERSION = "v1"
|
10
|
+
|
11
|
+
def get(query, from, to)
|
12
|
+
begin
|
13
|
+
params = {
|
14
|
+
:api_key => @api_key,
|
15
|
+
:application_key => @application_key,
|
16
|
+
|
17
|
+
from: from.to_i,
|
18
|
+
to: to.to_i,
|
19
|
+
query: query
|
20
|
+
}
|
21
|
+
request(Net::HTTP::Get, '/api/' + API_VERSION + '/query', params, nil, false)
|
22
|
+
rescue Exception => e
|
23
|
+
if @silent
|
24
|
+
warn e
|
25
|
+
return -1, {}
|
26
|
+
else
|
27
|
+
raise e
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def upload(metrics)
|
33
|
+
begin
|
34
|
+
params = {
|
35
|
+
:api_key => @api_key
|
36
|
+
}
|
37
|
+
body = {
|
38
|
+
:series => metrics
|
39
|
+
}
|
40
|
+
request(Net::HTTP::Post, '/api/' + API_VERSION + '/series', params, body, true)
|
41
|
+
rescue Exception => e
|
42
|
+
if @silent
|
43
|
+
warn e
|
44
|
+
return -1, {}
|
45
|
+
else
|
46
|
+
raise e
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def submit_to_api(metric, points, scope, options = {})
|
52
|
+
payload = self.make_metric_payload(metric, points, scope, options)
|
53
|
+
self.upload([payload])
|
54
|
+
end
|
55
|
+
|
56
|
+
def submit_to_buffer(metric, points, scope, options = {})
|
57
|
+
payload = self.make_metric_payload(metric, points, scope, options)
|
58
|
+
@buffer << payload
|
59
|
+
return 200, {}
|
60
|
+
end
|
61
|
+
|
62
|
+
def flush_buffer()
|
63
|
+
payload = @buffer
|
64
|
+
@buffer = nil
|
65
|
+
self.upload(payload)
|
66
|
+
end
|
67
|
+
|
68
|
+
def submit(*args)
|
69
|
+
if @buffer
|
70
|
+
submit_to_buffer(*args)
|
71
|
+
else
|
72
|
+
submit_to_api(*args)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def switch_to_batched()
|
77
|
+
@buffer = Array.new
|
78
|
+
end
|
79
|
+
|
80
|
+
def switch_to_single()
|
81
|
+
@buffer = nil
|
82
|
+
end
|
83
|
+
|
84
|
+
def make_metric_payload(metric, points, scope, options)
|
85
|
+
begin
|
86
|
+
typ = options[:type] || "gauge"
|
87
|
+
|
88
|
+
if typ != "gauge" && typ != "counter"
|
89
|
+
raise ArgumentError, "metric type must be gauge or counter"
|
90
|
+
end
|
91
|
+
|
92
|
+
metric_payload = {
|
93
|
+
:metric => metric,
|
94
|
+
:points => points,
|
95
|
+
:type => typ,
|
96
|
+
:host => scope.host,
|
97
|
+
:device => scope.device
|
98
|
+
}
|
99
|
+
|
100
|
+
# Add tags if there are any
|
101
|
+
if not options[:tags].nil?
|
102
|
+
metric_payload[:tags] = options[:tags]
|
103
|
+
end
|
104
|
+
|
105
|
+
return metric_payload
|
106
|
+
rescue Exception => e
|
107
|
+
if @silent
|
108
|
+
warn e
|
109
|
+
return -1, {}
|
110
|
+
else
|
111
|
+
raise e
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,264 @@
|
|
1
|
+
require 'dogapi-demo'
|
2
|
+
|
3
|
+
module DogapiDemo
|
4
|
+
class V1 # for namespacing
|
5
|
+
|
6
|
+
class MonitorService < DogapiDemo::APIService
|
7
|
+
|
8
|
+
API_VERSION = 'v1'
|
9
|
+
|
10
|
+
def monitor(type, query, options = {})
|
11
|
+
begin
|
12
|
+
params = {
|
13
|
+
:api_key => @api_key,
|
14
|
+
:application_key => @application_key
|
15
|
+
}
|
16
|
+
|
17
|
+
body = {
|
18
|
+
'type' => type,
|
19
|
+
'query' => query,
|
20
|
+
}.merge options
|
21
|
+
|
22
|
+
request(Net::HTTP::Post, "/api/#{API_VERSION}/monitor", params, body, true)
|
23
|
+
rescue Exception => e
|
24
|
+
suppress_error_if_silent e
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def update_monitor(monitor_id, query, options)
|
29
|
+
begin
|
30
|
+
params = {
|
31
|
+
:api_key => @api_key,
|
32
|
+
:application_key => @application_key
|
33
|
+
}
|
34
|
+
|
35
|
+
body = {
|
36
|
+
'query' => query,
|
37
|
+
}.merge options
|
38
|
+
|
39
|
+
request(Net::HTTP::Put, "/api/#{API_VERSION}/monitor/#{monitor_id}", params, body, true)
|
40
|
+
rescue Exception => e
|
41
|
+
suppress_error_if_silent e
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_monitor(monitor_id, options = {})
|
46
|
+
begin
|
47
|
+
params = {
|
48
|
+
:api_key => @api_key,
|
49
|
+
:application_key => @application_key
|
50
|
+
}
|
51
|
+
|
52
|
+
# :group_states is an optional list of statuses to filter returned
|
53
|
+
# groups. If no value is given then no group states will be returned.
|
54
|
+
# Possible values are: "all", "ok", "warn", "alert", "no data".
|
55
|
+
params[:group_states] = options[:group_states].join(',') if options[:group_states]
|
56
|
+
|
57
|
+
request(Net::HTTP::Get, "/api/#{API_VERSION}/monitor/#{monitor_id}", params, nil, false)
|
58
|
+
rescue Exception => e
|
59
|
+
suppress_error_if_silent e
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def delete_monitor(monitor_id)
|
64
|
+
begin
|
65
|
+
params = {
|
66
|
+
:api_key => @api_key,
|
67
|
+
:application_key => @application_key
|
68
|
+
}
|
69
|
+
|
70
|
+
request(Net::HTTP::Delete, "/api/#{API_VERSION}/monitor/#{monitor_id}", params, nil, false)
|
71
|
+
rescue Exception => e
|
72
|
+
suppress_error_if_silent e
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def get_all_monitors(options = {})
|
77
|
+
begin
|
78
|
+
params = {
|
79
|
+
:api_key => @api_key,
|
80
|
+
:application_key => @application_key
|
81
|
+
}
|
82
|
+
|
83
|
+
# :group_states is an optional list of statuses to filter returned
|
84
|
+
# groups. If no value is given then no group states will be returned.
|
85
|
+
# Possible values are: "all", "ok", "warn", "alert", "no data".
|
86
|
+
if options[:group_states]
|
87
|
+
params[:group_states] = options[:group_states]
|
88
|
+
params[:group_states] = params[:group_states].join(',') if params[:group_states].respond_to?(:join)
|
89
|
+
end
|
90
|
+
|
91
|
+
# :tags is an optional list of scope tags to filter the list of monitors
|
92
|
+
# returned. If no value is given, then all monitors, regardless of
|
93
|
+
# scope, will be returned.
|
94
|
+
if options[:tags]
|
95
|
+
params[:tags] = options[:tags]
|
96
|
+
params[:tags] = params[:tags].join(',') if params[:tags].respond_to?(:join)
|
97
|
+
end
|
98
|
+
|
99
|
+
request(Net::HTTP::Get, "/api/#{API_VERSION}/monitor", params, nil, false)
|
100
|
+
rescue Exception => e
|
101
|
+
suppress_error_if_silent e
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def mute_monitors()
|
106
|
+
begin
|
107
|
+
params = {
|
108
|
+
:api_key => @api_key,
|
109
|
+
:application_key => @application_key
|
110
|
+
}
|
111
|
+
|
112
|
+
request(Net::HTTP::Post, "/api/#{API_VERSION}/monitor/mute_all", params, nil, false)
|
113
|
+
rescue Exception => e
|
114
|
+
suppress_error_if_silent e
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def unmute_monitors()
|
119
|
+
begin
|
120
|
+
params = {
|
121
|
+
:api_key => @api_key,
|
122
|
+
:application_key => @application_key
|
123
|
+
}
|
124
|
+
|
125
|
+
request(Net::HTTP::Post, "/api/#{API_VERSION}/monitor/unmute_all", params, nil, false)
|
126
|
+
rescue Exception => e
|
127
|
+
suppress_error_if_silent e
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def mute_monitor(monitor_id, options = {})
|
132
|
+
begin
|
133
|
+
params = {
|
134
|
+
:api_key => @api_key,
|
135
|
+
:application_key => @application_key
|
136
|
+
}
|
137
|
+
|
138
|
+
request(Net::HTTP::Post, "/api/#{API_VERSION}/monitor/#{monitor_id}/mute", params, options, true)
|
139
|
+
rescue Exception => e
|
140
|
+
suppress_error_if_silent e
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def unmute_monitor(monitor_id, options = {})
|
145
|
+
begin
|
146
|
+
params = {
|
147
|
+
:api_key => @api_key,
|
148
|
+
:application_key => @application_key
|
149
|
+
}
|
150
|
+
|
151
|
+
request(Net::HTTP::Post, "/api/#{API_VERSION}/monitor/#{monitor_id}/unmute", params, options, true)
|
152
|
+
rescue Exception => e
|
153
|
+
suppress_error_if_silent e
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
#
|
158
|
+
# DOWNTIMES
|
159
|
+
|
160
|
+
def schedule_downtime(scope, options = {})
|
161
|
+
begin
|
162
|
+
params = {
|
163
|
+
:api_key => @api_key,
|
164
|
+
:application_key => @application_key
|
165
|
+
}
|
166
|
+
|
167
|
+
body = {
|
168
|
+
'scope' => scope
|
169
|
+
}.merge options
|
170
|
+
|
171
|
+
request(Net::HTTP::Post, "/api/#{API_VERSION}/downtime", params, body, true)
|
172
|
+
rescue Exception => e
|
173
|
+
suppress_error_if_silent e
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def update_downtime(downtime_id, options = {})
|
178
|
+
begin
|
179
|
+
params = {
|
180
|
+
:api_key => @api_key,
|
181
|
+
:application_key => @application_key
|
182
|
+
}
|
183
|
+
|
184
|
+
request(Net::HTTP::Put, "/api/#{API_VERSION}/downtime/#{downtime_id}", params, options, true)
|
185
|
+
rescue Exception => e
|
186
|
+
suppress_error_if_silent e
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def get_downtime(downtime_id)
|
191
|
+
begin
|
192
|
+
params = {
|
193
|
+
:api_key => @api_key,
|
194
|
+
:application_key => @application_key
|
195
|
+
}
|
196
|
+
|
197
|
+
request(Net::HTTP::Get, "/api/#{API_VERSION}/downtime/#{downtime_id}", params, nil, false)
|
198
|
+
rescue Exception => e
|
199
|
+
suppress_error_if_silent e
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def cancel_downtime(downtime_id)
|
204
|
+
begin
|
205
|
+
params = {
|
206
|
+
:api_key => @api_key,
|
207
|
+
:application_key => @application_key
|
208
|
+
}
|
209
|
+
|
210
|
+
request(Net::HTTP::Delete, "/api/#{API_VERSION}/downtime/#{downtime_id}", params, nil, false)
|
211
|
+
rescue Exception => e
|
212
|
+
suppress_error_if_silent e
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def get_all_downtimes(options = {})
|
217
|
+
begin
|
218
|
+
params = {
|
219
|
+
:api_key => @api_key,
|
220
|
+
:application_key => @application_key
|
221
|
+
}
|
222
|
+
|
223
|
+
if options[:current_only]
|
224
|
+
params[:current_only] = options[:current_only]
|
225
|
+
options.delete :current_only
|
226
|
+
end
|
227
|
+
|
228
|
+
request(Net::HTTP::Get, "/api/#{API_VERSION}/downtime", params, nil, false)
|
229
|
+
rescue Exception => e
|
230
|
+
suppress_error_if_silent e
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
#
|
235
|
+
# HOST MUTING
|
236
|
+
|
237
|
+
def mute_host(hostname, options = {})
|
238
|
+
begin
|
239
|
+
params = {
|
240
|
+
:api_key => @api_key,
|
241
|
+
:application_key => @application_key
|
242
|
+
}
|
243
|
+
|
244
|
+
request(Net::HTTP::Post, "/api/#{API_VERSION}/host/#{hostname}/mute", params, options, true)
|
245
|
+
rescue Exception => e
|
246
|
+
suppress_error_if_silent e
|
247
|
+
end
|
248
|
+
end
|
249
|
+
def unmute_host(hostname)
|
250
|
+
begin
|
251
|
+
params = {
|
252
|
+
:api_key => @api_key,
|
253
|
+
:application_key => @application_key
|
254
|
+
}
|
255
|
+
|
256
|
+
request(Net::HTTP::Post, "/api/#{API_VERSION}/host/#{hostname}/unmute", params, nil, true)
|
257
|
+
rescue Exception => e
|
258
|
+
suppress_error_if_silent e
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
end
|
264
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'dogapi-demo'
|
2
|
+
|
3
|
+
module DogapiDemo
|
4
|
+
class V1 # for namespacing
|
5
|
+
|
6
|
+
class ScreenboardService < DogapiDemo::APIService
|
7
|
+
|
8
|
+
API_VERSION = "v1"
|
9
|
+
|
10
|
+
def create_screenboard(description)
|
11
|
+
|
12
|
+
begin
|
13
|
+
params = {
|
14
|
+
:api_key => @api_key,
|
15
|
+
:application_key => @application_key
|
16
|
+
}
|
17
|
+
|
18
|
+
body = description
|
19
|
+
|
20
|
+
request(Net::HTTP::Post, "/api/#{API_VERSION}/screen", params, description, true)
|
21
|
+
rescue Exception => e
|
22
|
+
suppress_error_if_silent e
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def update_screenboard(board_id, description)
|
27
|
+
|
28
|
+
begin
|
29
|
+
params = {
|
30
|
+
:api_key => @api_key,
|
31
|
+
:application_key => @application_key
|
32
|
+
}
|
33
|
+
|
34
|
+
body = description
|
35
|
+
|
36
|
+
request(Net::HTTP::Put, "/api/#{API_VERSION}/screen/#{board_id}", params, body, true)
|
37
|
+
rescue Exception => e
|
38
|
+
suppress_error_if_silent e
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_screenboard(board_id)
|
43
|
+
begin
|
44
|
+
params = {
|
45
|
+
:api_key => @api_key,
|
46
|
+
:application_key => @application_key
|
47
|
+
}
|
48
|
+
|
49
|
+
request(Net::HTTP::Get, "/api/#{API_VERSION}/screen/#{board_id}", params, nil, false)
|
50
|
+
rescue Exception => e
|
51
|
+
suppress_error_if_silent e
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_all_screenboards()
|
56
|
+
begin
|
57
|
+
params = {
|
58
|
+
:api_key => @api_key,
|
59
|
+
:application_key => @application_key
|
60
|
+
}
|
61
|
+
|
62
|
+
request(Net::HTTP::Get, "/api/#{API_VERSION}/screen", params, nil, false)
|
63
|
+
rescue Exception => e
|
64
|
+
suppress_error_if_silent e
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def delete_screenboard(board_id)
|
69
|
+
begin
|
70
|
+
params = {
|
71
|
+
:api_key => @api_key,
|
72
|
+
:application_key => @application_key
|
73
|
+
}
|
74
|
+
|
75
|
+
request(Net::HTTP::Delete, "/api/#{API_VERSION}/screen/#{board_id}", params, nil, false)
|
76
|
+
rescue Exception => e
|
77
|
+
suppress_error_if_silent e
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def share_screenboard(board_id)
|
82
|
+
begin
|
83
|
+
params = {
|
84
|
+
:api_key => @api_key,
|
85
|
+
:application_key => @application_key
|
86
|
+
}
|
87
|
+
|
88
|
+
request(Net::HTTP::Get, "/api/#{API_VERSION}/screen/share/#{board_id}", params, nil, false)
|
89
|
+
rescue Exception => e
|
90
|
+
suppress_error_if_silent e
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def revoke_screenboard(board_id)
|
95
|
+
begin
|
96
|
+
params = {
|
97
|
+
:api_key => @api_key,
|
98
|
+
:application_key => @application_key
|
99
|
+
}
|
100
|
+
|
101
|
+
request(Net::HTTP::Delete, "/api/#{API_VERSION}/screen/share/#{board_id}", params, nil, false)
|
102
|
+
rescue Exception => e
|
103
|
+
suppress_error_if_silent e
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|