dogapi 1.22.0 → 1.23.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.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +1 -1
  4. data/.rubocop.yml +13 -0
  5. data/.travis.yml +3 -1
  6. data/CHANGELOG.md +16 -1
  7. data/Gemfile +6 -3
  8. data/README.rdoc +1 -1
  9. data/Rakefile +8 -15
  10. data/lib/capistrano/datadog.rb +12 -12
  11. data/lib/capistrano/datadog/v2.rb +5 -5
  12. data/lib/capistrano/datadog/v3.rb +9 -4
  13. data/lib/dogapi/common.rb +43 -39
  14. data/lib/dogapi/event.rb +4 -4
  15. data/lib/dogapi/facade.rb +57 -54
  16. data/lib/dogapi/metric.rb +2 -2
  17. data/lib/dogapi/v1/alert.rb +17 -80
  18. data/lib/dogapi/v1/comment.rb +8 -39
  19. data/lib/dogapi/v1/dash.rb +20 -67
  20. data/lib/dogapi/v1/embed.rb +11 -57
  21. data/lib/dogapi/v1/event.rb +37 -72
  22. data/lib/dogapi/v1/metric.rb +17 -46
  23. data/lib/dogapi/v1/monitor.rb +54 -194
  24. data/lib/dogapi/v1/screenboard.rb +8 -77
  25. data/lib/dogapi/v1/search.rb +5 -11
  26. data/lib/dogapi/v1/service_check.rb +6 -15
  27. data/lib/dogapi/v1/snapshot.rb +10 -15
  28. data/lib/dogapi/v1/tag.rb +39 -99
  29. data/lib/dogapi/v1/user.rb +15 -69
  30. data/lib/dogapi/version.rb +1 -1
  31. data/spec/integration/alert_spec.rb +48 -0
  32. data/spec/integration/comment_spec.rb +32 -0
  33. data/spec/integration/common_spec.rb +32 -0
  34. data/spec/integration/dash_spec.rb +60 -0
  35. data/spec/integration/embed_spec.rb +43 -0
  36. data/spec/integration/event_spec.rb +73 -0
  37. data/spec/integration/metric_spec.rb +96 -0
  38. data/spec/integration/monitor_spec.rb +106 -0
  39. data/spec/integration/screenboard_spec.rb +61 -0
  40. data/spec/integration/search_spec.rb +11 -0
  41. data/spec/integration/service_check_spec.rb +12 -0
  42. data/spec/integration/snapshot_spec.rb +24 -0
  43. data/spec/integration/tag_spec.rb +66 -0
  44. data/spec/integration/user_spec.rb +46 -0
  45. data/spec/spec_helper.rb +85 -16
  46. data/spec/unit/common_spec.rb +101 -0
  47. data/spec/unit/facade_spec.rb +79 -0
  48. metadata +55 -52
  49. data/spec/alerts_spec.rb +0 -33
  50. data/spec/common_spec.rb +0 -37
  51. data/spec/facade_spec.rb +0 -166
  52. data/spec/support/cassettes/Alerts/create/returns_HTTP_code_200.yml +0 -114
  53. data/spec/support/cassettes/Alerts/create/returns_a_valid_event_ID.yml +0 -114
  54. data/spec/support/cassettes/Alerts/create/returns_the_same_query_as_sent.yml +0 -114
  55. data/spec/support/cassettes/Facade/Events/emits_aggregate_events.yml +0 -193
  56. data/spec/support/cassettes/Facade/Events/emits_events_and_retrieves_them.yml +0 -100
  57. data/spec/support/cassettes/Facade/Events/emits_events_with_specified_priority.yml +0 -98
  58. data/spec/support/cassettes/Facade/Tags/adds_updates_and_detaches_tags.yml +0 -442
  59. data/tests/test_alerts.rb +0 -38
  60. data/tests/test_base.rb +0 -30
  61. data/tests/test_client.rb +0 -23
  62. data/tests/test_comments.rb +0 -39
  63. data/tests/test_dashes.rb +0 -85
  64. data/tests/test_embed.rb +0 -194
  65. data/tests/test_monitors.rb +0 -192
  66. data/tests/test_screenboard.rb +0 -90
  67. data/tests/test_search.rb +0 -20
  68. data/tests/test_snapshot.rb +0 -28
  69. data/tests/test_users.rb +0 -65
@@ -8,255 +8,115 @@ module Dogapi
8
8
  API_VERSION = 'v1'
9
9
 
10
10
  def monitor(type, query, options = {})
11
- begin
12
- params = {
13
- :api_key => @api_key,
14
- :application_key => @application_key
15
- }
11
+ body = {
12
+ 'type' => type,
13
+ 'query' => query,
14
+ }.merge options
16
15
 
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
16
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/monitor", nil, body, true)
26
17
  end
27
18
 
28
19
  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
20
+ body = {
21
+ 'query' => query,
22
+ }.merge options
38
23
 
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
24
+ request(Net::HTTP::Put, "/api/#{API_VERSION}/monitor/#{monitor_id}", nil, body, true)
43
25
  end
44
26
 
45
27
  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]
28
+ # :group_states is an optional list of statuses to filter returned
29
+ # groups. If no value is given then no group states will be returned.
30
+ # Possible values are: "all", "ok", "warn", "alert", "no data".
31
+ extra_params = {}
32
+ extra_params[:group_states] = options[:group_states].join(',') if options[:group_states]
56
33
 
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
34
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/monitor/#{monitor_id}", extra_params, nil, false)
61
35
  end
62
36
 
63
37
  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
38
+ request(Net::HTTP::Delete, "/api/#{API_VERSION}/monitor/#{monitor_id}", nil, nil, false)
74
39
  end
75
40
 
76
41
  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
42
+ extra_params = {}
43
+ # :group_states is an optional list of statuses to filter returned
44
+ # groups. If no value is given then no group states will be returned.
45
+ # Possible values are: "all", "ok", "warn", "alert", "no data".
46
+ if options[:group_states]
47
+ extra_params[:group_states] = options[:group_states]
48
+ extra_params[:group_states] = extra_params[:group_states].join(',') if extra_params[:group_states].respond_to?(:join)
102
49
  end
103
- end
104
50
 
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
51
+ # :tags is an optional list of scope tags to filter the list of monitors
52
+ # returned. If no value is given, then all monitors, regardless of
53
+ # scope, will be returned.
54
+ if options[:tags]
55
+ extra_params[:tags] = options[:tags]
56
+ extra_params[:tags] = extra_params[:tags].join(',') if extra_params[:tags].respond_to?(:join)
115
57
  end
58
+
59
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/monitor", extra_params, nil, false)
116
60
  end
117
61
 
118
- def unmute_monitors()
119
- begin
120
- params = {
121
- :api_key => @api_key,
122
- :application_key => @application_key
123
- }
62
+ def mute_monitors
63
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/monitor/mute_all", nil, nil, false)
64
+ end
124
65
 
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
66
+ def unmute_monitors
67
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/monitor/unmute_all", nil, nil, false)
129
68
  end
130
69
 
131
70
  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
71
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/monitor/#{monitor_id}/mute", nil, options, true)
142
72
  end
143
73
 
144
74
  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
75
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/monitor/#{monitor_id}/unmute", nil, options, true)
155
76
  end
156
77
 
157
78
  #
158
79
  # DOWNTIMES
159
80
 
160
81
  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
82
+ body = {
83
+ 'scope' => scope
84
+ }.merge options
170
85
 
171
- request(Net::HTTP::Post, "/api/#{API_VERSION}/downtime", params, body, true)
172
- rescue Exception => e
173
- suppress_error_if_silent e
174
- end
86
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/downtime", nil, body, true)
175
87
  end
176
88
 
177
89
  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
90
+ request(Net::HTTP::Put, "/api/#{API_VERSION}/downtime/#{downtime_id}", nil, options, true)
188
91
  end
189
92
 
190
93
  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
94
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/downtime/#{downtime_id}", nil, nil, false)
201
95
  end
202
96
 
203
97
  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
98
+ request(Net::HTTP::Delete, "/api/#{API_VERSION}/downtime/#{downtime_id}", nil, nil, false)
214
99
  end
215
100
 
216
101
  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
102
+ extra_params = {}
103
+ if options[:current_only]
104
+ extra_params[:current_only] = options[:current_only]
105
+ options.delete :current_only
231
106
  end
107
+
108
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/downtime", extra_params, nil, false)
232
109
  end
233
110
 
234
111
  #
235
112
  # HOST MUTING
236
113
 
237
114
  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
115
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/host/#{hostname}/mute", nil, options, true)
248
116
  end
249
- def unmute_host(hostname)
250
- begin
251
- params = {
252
- :api_key => @api_key,
253
- :application_key => @application_key
254
- }
255
117
 
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
118
+ def unmute_host(hostname)
119
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/host/#{hostname}/unmute", nil, {}, true)
260
120
  end
261
121
  end
262
122
 
@@ -5,103 +5,34 @@ module Dogapi
5
5
 
6
6
  class ScreenboardService < Dogapi::APIService
7
7
 
8
- API_VERSION = "v1"
8
+ API_VERSION = 'v1'
9
9
 
10
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
11
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/screen", nil, description, true)
24
12
  end
25
13
 
26
14
  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
15
+ request(Net::HTTP::Put, "/api/#{API_VERSION}/screen/#{board_id}", nil, description, true)
40
16
  end
41
17
 
42
18
  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
19
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/screen/#{board_id}", nil, nil, false)
53
20
  end
54
21
 
55
22
  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
23
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/screen", nil, nil, false)
66
24
  end
67
25
 
68
26
  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
27
+ request(Net::HTTP::Delete, "/api/#{API_VERSION}/screen/#{board_id}", nil, nil, false)
79
28
  end
80
29
 
81
30
  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
31
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/screen/share/#{board_id}", nil, nil, false)
92
32
  end
93
33
 
94
34
  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
35
+ request(Net::HTTP::Delete, "/api/#{API_VERSION}/screen/share/#{board_id}", nil, nil, false)
105
36
  end
106
37
 
107
38
  end
@@ -5,20 +5,14 @@ module Dogapi
5
5
 
6
6
  class SearchService < Dogapi::APIService
7
7
 
8
- API_VERSION = "v1"
8
+ API_VERSION = 'v1'
9
9
 
10
10
  def search(query)
11
- begin
12
- params = {
13
- :api_key => @api_key,
14
- :application_key => @application_key,
15
- :q => query
16
- }
11
+ extra_params = {
12
+ :q => query
13
+ }
17
14
 
18
- request(Net::HTTP::Get, "/api/#{API_VERSION}/search", params, nil, false)
19
- rescue Exception => e
20
- suppress_error_if_silent e
21
- end
15
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/search", extra_params, nil, false)
22
16
  end
23
17
 
24
18
  end
@@ -8,22 +8,13 @@ module Dogapi
8
8
  API_VERSION = 'v1'
9
9
 
10
10
  def service_check(check, host, status, options = {})
11
- begin
12
- params = {
13
- :api_key => @api_key,
14
- :application_key => @application_key
15
- }
11
+ body = {
12
+ 'check' => check,
13
+ 'host_name' => host,
14
+ 'status' => status
15
+ }.merge options
16
16
 
17
- body = {
18
- 'check' => check,
19
- 'host_name' => host,
20
- 'status' => status
21
- }.merge options
22
-
23
- request(Net::HTTP::Post, "/api/#{API_VERSION}/check_run", params, body, true)
24
- rescue Exception => e
25
- suppress_error_if_silent e
26
- end
17
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/check_run", nil, body, true)
27
18
  end
28
19
 
29
20
  end