wavefront-sdk 3.0.2 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.md +12 -1
  3. data/README.md +4 -0
  4. data/Rakefile +1 -0
  5. data/lib/wavefront-sdk/alert.rb +36 -49
  6. data/lib/wavefront-sdk/api_mixins/acl.rb +76 -0
  7. data/lib/wavefront-sdk/api_mixins/tag.rb +62 -0
  8. data/lib/wavefront-sdk/api_mixins/user.rb +26 -0
  9. data/lib/wavefront-sdk/apitoken.rb +49 -0
  10. data/lib/wavefront-sdk/core/exception.rb +1 -0
  11. data/lib/wavefront-sdk/dashboard.rb +6 -106
  12. data/lib/wavefront-sdk/defs/version.rb +1 -1
  13. data/lib/wavefront-sdk/derivedmetric.rb +6 -56
  14. data/lib/wavefront-sdk/event.rb +4 -50
  15. data/lib/wavefront-sdk/paginator/base.rb +8 -7
  16. data/lib/wavefront-sdk/paginator/post.rb +7 -5
  17. data/lib/wavefront-sdk/source.rb +4 -48
  18. data/lib/wavefront-sdk/user.rb +2 -2
  19. data/lib/wavefront-sdk/usergroup.rb +2 -2
  20. data/lib/wavefront-sdk/validators.rb +10 -0
  21. data/lib/wavefront-sdk/write.rb +43 -12
  22. data/lib/wavefront-sdk/writers/socket.rb +2 -2
  23. data/spec/.rubocop.yml +1 -1
  24. data/spec/spec_helper.rb +66 -0
  25. data/spec/wavefront-sdk/alert_spec.rb +14 -0
  26. data/spec/wavefront-sdk/{support → api_mixins}/user_mixins_spec.rb +2 -2
  27. data/spec/wavefront-sdk/apitoken_spec.rb +31 -0
  28. data/spec/wavefront-sdk/core/api_spec.rb +3 -5
  29. data/spec/wavefront-sdk/credentials_spec.rb +41 -37
  30. data/spec/wavefront-sdk/dashboard_spec.rb +4 -52
  31. data/spec/wavefront-sdk/distribution_spec.rb +1 -3
  32. data/spec/wavefront-sdk/metric_helper_spec.rb +6 -8
  33. data/spec/wavefront-sdk/report_spec.rb +2 -2
  34. data/spec/wavefront-sdk/stdlib/array_spec.rb +6 -6
  35. data/spec/wavefront-sdk/stdlib/hash_spec.rb +5 -5
  36. data/spec/wavefront-sdk/support/mixins_spec.rb +34 -36
  37. data/spec/wavefront-sdk/support/parse_time_spec.rb +25 -29
  38. data/spec/wavefront-sdk/usergroup_spec.rb +34 -34
  39. data/spec/wavefront-sdk/validators_spec.rb +10 -1
  40. data/spec/wavefront-sdk/write_spec.rb +71 -4
  41. data/spec/wavefront-sdk/writers/core_spec.rb +10 -10
  42. data/spec/wavefront-sdk/writers/socket_spec.rb +13 -1
  43. metadata +10 -5
  44. data/lib/wavefront-sdk/support/user_mixins.rb +0 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc630d37510f6a1606b0680c2ea50245f569ac12d2091f8551766d9f9d6021a0
4
- data.tar.gz: 8c458655085f9f1fd0ff7b1e2d4a01e4b277f29e500b8ec445705cbefa91b0c8
3
+ metadata.gz: c0d0b70537f8a1965c33603e7fa7a25493b9d9ff84d72badf3f5d587c7e51c70
4
+ data.tar.gz: add8ce51bf47032fbb1436db738f2985d2448db2c9b56767f654f816bacb30a2
5
5
  SHA512:
6
- metadata.gz: 1450041d4c7877bee9de16e4c8942a80b6bd190f876a69bcdeb2f99afb70171eaa10ebff1db13a6d3519f021e4d0127ba8f8b47942a7626ee80e92fe3185d10e
7
- data.tar.gz: 8ae22c21bd7338badc525648d8dac78b18255e1a32fa483ac188d3d4aa39e60b20d01ae93ac05ffe39ffc992c9e5c03c3e26929afd0ab669e02e980cb7d15700
6
+ metadata.gz: db92c24817827d785eb1e036be8f1398d94b1e16e2da59d1f3c7eaa65dcbc42309166c10e83d9d62468f38a6ca16ddc58d834650b66cb37034d4a09e43219894
7
+ data.tar.gz: 466acb6db568c0c1ac93b30fabe7b677b97df42657aa5414ae83c0ce2fa9b3dcfd52701c55a263dcb0bde232717bce6e324f59b17bc1a6dd7cbf9afd1188d126
data/HISTORY.md CHANGED
@@ -1,9 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.2.0 (01/05/2019)
4
+ * Add support for new `apitoken` path.
5
+ * Add support for alert ACLs
6
+ * Tag and ACL methods have been broken out into mixins which are
7
+ automatically included by classes which support them
8
+
9
+ ## 3.1.0 (23/04/2019)
10
+ * When using `Wavefront::Write`, large numbers of points are written
11
+ in chunks, rather than all at once. The chunk size can be set by
12
+ the user when instantiating the class.
13
+
3
14
  ## 3.0.2 (06/04/2019)
4
15
  * Better handling of non-existent or malformed config files.
5
16
  * Look for `~/.wavefront.conf` as well as `~/.wavefront`. Both these
6
- fixes are related to findind out that other Wavefront tooling
17
+ fixes are related to finding out that other Wavefront tooling
7
18
  creates `~/.wavefront` as a directory.
8
19
 
9
20
  ## 3.0.1 (05/04/2019)
data/README.md CHANGED
@@ -254,6 +254,10 @@ symbol, or by using the `Write#write_delta()` method. This is called in
254
254
  exactly the same way as `Write#write`, and supports all the same
255
255
  options.
256
256
 
257
+ If you try to send huge amounts of metrics in a single go,
258
+ `Wavefront::Write` will break them up into smaller API-friendly
259
+ chunks.
260
+
257
261
  #### Sending Distributions
258
262
 
259
263
  Use the `Wavefront::Distribution` class to send distributions via a
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'yard'
2
2
  require 'rake/testtask'
3
+ require 'bundler/gem_tasks'
3
4
  require 'rubocop/rake_task'
4
5
 
5
6
  task default: %i[rubocop test]
@@ -1,5 +1,7 @@
1
1
  require_relative 'defs/constants'
2
2
  require_relative 'core/api'
3
+ require_relative 'api_mixins/acl'
4
+ require_relative 'api_mixins/tag'
3
5
 
4
6
  module Wavefront
5
7
  #
@@ -7,8 +9,11 @@ module Wavefront
7
9
  # epoch timestamp. Returns a Wavefront::Response::Alert object.
8
10
  #
9
11
  class Alert < CoreApi
12
+ include Wavefront::Mixin::Acl
13
+ include Wavefront::Mixin::Tag
14
+
10
15
  def update_keys
11
- %i[id name target condition displayExpression minutes
16
+ %i[id name target condition displayExpression minutes tag
12
17
  resolveAfterMinutes severity additionalInformation]
13
18
  end
14
19
 
@@ -68,6 +73,19 @@ module Wavefront
68
73
  api.get(fragments.uri_concat)
69
74
  end
70
75
 
76
+ # Gets all the versions of the given alert
77
+ # @param id [String] ID of the alert
78
+ # @reutrn [Wavefront::Resonse] where items is an array of integers
79
+ #
80
+ def versions(id)
81
+ wf_alert_id?(id)
82
+ resp = api.get([id, 'history'].uri_concat)
83
+
84
+ versions = resp.response.items.map(&:version)
85
+ resp.response[:items] = versions
86
+ resp
87
+ end
88
+
71
89
  # PUT /api/v2/alert/id
72
90
  # Update a specific alert.
73
91
  #
@@ -89,6 +107,22 @@ module Wavefront
89
107
  'application/json')
90
108
  end
91
109
 
110
+ # POST /api/v2/alert/{id}/clone
111
+ # Clones the specified alert
112
+ # @param id [String] ID of the alert
113
+ # @param version [Integer] version of alert
114
+ # @return [Wavefront::Response]
115
+ #
116
+ def clone(id, version = nil)
117
+ wf_alert_id?(id)
118
+ wf_version?(version) if version
119
+
120
+ api.post([id, 'clone'].uri_concat,
121
+ { id: id,
122
+ name: nil,
123
+ v: version }, 'application/json')
124
+ end
125
+
92
126
  # GET /api/v2/alert/id/history
93
127
  # Get the version history of a specific alert.
94
128
  #
@@ -126,55 +160,8 @@ module Wavefront
126
160
  api.post([id, "snooze#{qs}"].uri_concat, nil)
127
161
  end
128
162
 
129
- # GET /api/v2/alert/id/tag
130
- # Get all tags associated with a specific alert.
131
- #
132
- # @param id [String] ID of the alert
133
- # @return [Wavefront::Response]
134
- #
135
- def tags(id)
136
- wf_alert_id?(id)
137
- api.get([id, 'tag'].uri_concat)
138
- end
139
-
140
- # POST /api/v2/alert/id/tag
141
- # Set all tags associated with a specific alert.
142
- #
143
- # @param id [String] ID of the alert
144
- # @param tags [Array] list of tags to set.
145
- # @return [Wavefront::Response]
146
- #
147
- def tag_set(id, tags)
148
- wf_alert_id?(id)
149
- tags = Array(tags)
150
- tags.each { |t| wf_string?(t) }
151
- api.post([id, 'tag'].uri_concat, tags.to_json, 'application/json')
152
- end
153
-
154
- # DELETE /api/v2/alert/id/tag/tagValue
155
- # Remove a tag from a specific alert.
156
- #
157
- # @param id [String] ID of the alert
158
- # @param tag [String] tag to delete
159
- # @return [Wavefront::Response]
160
- #
161
- def tag_delete(id, tag)
162
- wf_alert_id?(id)
163
- wf_string?(tag)
164
- api.delete([id, 'tag', tag].uri_concat)
165
- end
166
-
167
- # PUT /api/v2/alert/id/tag/tagValue
168
- # Add a tag to a specific alert.
169
- #
170
- # @param id [String] ID of the alert
171
- # @param tag [String] tag to set.
172
- # @return [Wavefront::Response]
173
- #
174
- def tag_add(id, tag)
163
+ def valid_id?(id)
175
164
  wf_alert_id?(id)
176
- wf_string?(tag)
177
- api.put([id, 'tag', tag].uri_concat)
178
165
  end
179
166
 
180
167
  # POST /api/v2/alert/id/undelete
@@ -0,0 +1,76 @@
1
+ module Wavefront
2
+ module Mixin
3
+ #
4
+ # ACL mixins
5
+ #
6
+ # Mix this module into class which supports ACLs, ensuring there is a
7
+ # valid_id? method to perform ID validation.
8
+ #
9
+ module Acl
10
+ # GET /api/v2/{entity}/acl
11
+ # Get list of Access Control Lists for the specified object
12
+ # @param id_list [Array[String]] array of object IDs
13
+ # @return [Wavefront::Response]
14
+ #
15
+ def acls(id_list)
16
+ id_list.each { |id| valid_id?(id) }
17
+ api.get_flat_params('acl', id: id_list)
18
+ end
19
+
20
+ # POST /api/v2/{entity}/acl/add
21
+ # Adds the specified ids to the given object's ACL
22
+ # @param id [String] ID of object
23
+ # @param view [Array[Hash]] array of entities allowed to view
24
+ # the object. Entities may be users or groups, and are
25
+ # defined as a Hash with keys :id and :name. For users the two
26
+ # will be the same, for groups, not.
27
+ # @param modify [Array[Hash]] array of entities allowed to
28
+ # view and modify the object. Same rules as @view.
29
+ # @return [Wavefront::Response]
30
+ #
31
+ def acl_add(id, view = [], modify = [])
32
+ valid_id?(id)
33
+
34
+ api.post(%w[acl add].uri_concat,
35
+ acl_body(id, view, modify),
36
+ 'application/json')
37
+ end
38
+
39
+ # POST /api/v2/{entity}/acl/remove
40
+ # Removes the specified ids from the given object's ACL
41
+ #
42
+ # Though the API method is 'remove', the acl method names have
43
+ # been chosen to correspond with the tag methods.
44
+ #
45
+ def acl_delete(id, view = [], modify = [])
46
+ valid_id?(id)
47
+
48
+ api.post(%w[acl remove].uri_concat,
49
+ acl_body(id, view, modify),
50
+ 'application/json')
51
+ end
52
+
53
+ # PUT /api/v2/{entity}/acl/set
54
+ # Set ACL for the specified object
55
+ #
56
+ def acl_set(id, view = [], modify = [])
57
+ api.put(%w[acl set].uri_concat, acl_body(id, view, modify))
58
+ end
59
+
60
+ private
61
+
62
+ def acl_body(id, view, modify)
63
+ valid_id?(id)
64
+ valid_acl_body?(view)
65
+ valid_acl_body?(modify)
66
+
67
+ [{ entityId: id, viewAcl: view, modifyAcl: modify }]
68
+ end
69
+
70
+ def valid_acl_body?(list)
71
+ return true if list.is_a?(Array) && list.all? { |h| h.is_a?(Hash) }
72
+ raise ArgumentError
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,62 @@
1
+ module Wavefront
2
+ module Mixin
3
+ #
4
+ # Tagging support.
5
+ #
6
+ # Mix this module into class which supports tags, ensuring there is a
7
+ # valid_id? method to perform ID validation.
8
+ #
9
+ module Tag
10
+ # GET /api/v2/{object}/id/tag
11
+ # Get all tags associated with a specific object.
12
+ #
13
+ # @param id [String] ID of the object
14
+ # @return [Wavefront::Response]
15
+ #
16
+ def tags(id)
17
+ valid_id?(id)
18
+ api.get([id, 'tag'].uri_concat)
19
+ end
20
+
21
+ # POST /api/v2/{object}/id/tag
22
+ # Set all tags associated with a specific object.
23
+ #
24
+ # @param id [String] ID of the object
25
+ # @param tags [Array] list of tags to set.
26
+ # @return [Wavefront::Response]
27
+ #
28
+ def tag_set(id, tags)
29
+ valid_id?(id)
30
+ tags = Array(tags)
31
+ tags.each { |t| wf_string?(t) }
32
+ api.post([id, 'tag'].uri_concat, tags.to_json, 'application/json')
33
+ end
34
+
35
+ # DELETE /api/v2/{object}/id/tag/tagValue
36
+ # Remove a tag from a specific object.
37
+ #
38
+ # @param id [String] ID of the object
39
+ # @param tag [String] tag to delete
40
+ # @return [Wavefront::Response]
41
+ #
42
+ def tag_delete(id, tag)
43
+ valid_id?(id)
44
+ wf_string?(tag)
45
+ api.delete([id, 'tag', tag].uri_concat)
46
+ end
47
+
48
+ # PUT /api/v2/{object}/id/tag/tagValue
49
+ # Add a tag to a specific object.
50
+ #
51
+ # @param id [String] ID of the object
52
+ # @param tag [String] tag to set.
53
+ # @return [Wavefront::Response]
54
+ #
55
+ def tag_add(id, tag)
56
+ valid_id?(id)
57
+ wf_string?(tag)
58
+ api.put([id, 'tag', tag].uri_concat)
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,26 @@
1
+ module Wavefront
2
+ module Mixin
3
+ #
4
+ # Things needed by User and UserGroup classes
5
+ #
6
+ module User
7
+ # Validate a list of users.
8
+ # @param list [Array[String]] list of user IDs
9
+ # @raise Wavefront::Exception::InvalidUser
10
+ #
11
+ def validate_user_list(list)
12
+ raise ArgumentError unless list.is_a?(Array)
13
+ list.each { |id| wf_user_id?(id) }
14
+ end
15
+
16
+ # Validate a list of user groups
17
+ # @param list [Array[String]] list of user group IDs
18
+ # @raise Wavefront::Exception::InvalidUserGroup
19
+ #
20
+ def validate_usergroup_list(list)
21
+ raise ArgumentError unless list.is_a?(Array)
22
+ list.each { |id| wf_usergroup_id?(id) }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,49 @@
1
+ require_relative 'core/api'
2
+
3
+ module Wavefront
4
+ #
5
+ # View and manage API tokens
6
+ #
7
+ class ApiToken < CoreApi
8
+ # GET /api/v2/apitoken
9
+ # Get all api tokens for a user
10
+ #
11
+ # @return [Wavefront::Response]
12
+ #
13
+ def list
14
+ api.get('')
15
+ end
16
+
17
+ # POST /api/v2/apitoken
18
+ # Create a new api token
19
+ #
20
+ # @return [Wavefront::Response]
21
+ #
22
+ def create
23
+ api.post('', nil, 'application/json')
24
+ end
25
+
26
+ # DELETE /api/v2/apitoken/id
27
+ # Delete the specified api token
28
+ #
29
+ # @param id [String] ID of the api token
30
+ # @return [Wavefront::Response]
31
+ #
32
+ def delete(id)
33
+ wf_apitoken_id?(id)
34
+ api.delete(id)
35
+ end
36
+
37
+ # PUT /api/v2/apitoken/id
38
+ # Update the name of the specified api token
39
+ #
40
+ # @param id [String] ID of the API token
41
+ # @param name [String] name of the API token
42
+ # @return [Wavefront::Response]
43
+
44
+ def rename(id, name)
45
+ wf_apitoken_id?(id)
46
+ api.put(id, { tokenID: id, tokenName: name }, 'application/json')
47
+ end
48
+ end
49
+ end
@@ -8,6 +8,7 @@ module Wavefront
8
8
  class EnumerableError < RuntimeError; end
9
9
  class InvalidAlertId < RuntimeError; end
10
10
  class InvalidAlertSeverity < RuntimeError; end
11
+ class InvalidApiTokenId < RuntimeError; end
11
12
  class InvalidConfigFile < RuntimeError; end
12
13
  class InvalidCloudIntegrationId < RuntimeError; end
13
14
  class InvalidDashboardId < RuntimeError; end
@@ -1,10 +1,15 @@
1
1
  require_relative 'core/api'
2
+ require_relative 'api_mixins/acl'
3
+ require_relative 'api_mixins/tag'
2
4
 
3
5
  module Wavefront
4
6
  #
5
7
  # View and manage dashboards.
6
8
  #
7
9
  class Dashboard < CoreApi
10
+ include Wavefront::Mixin::Acl
11
+ include Wavefront::Mixin::Tag
12
+
8
13
  def update_keys
9
14
  %i[id name url description sections]
10
15
  end
@@ -106,57 +111,6 @@ module Wavefront
106
111
  api.get([id, 'history'].uri_concat)
107
112
  end
108
113
 
109
- # GET /api/v2/dashboard/id/tag
110
- # Get all tags associated with a specific dashboard.
111
- #
112
- # @param id [String] ID of the dashboard
113
- # @return [Wavefront::Response]
114
- #
115
- def tags(id)
116
- wf_dashboard_id?(id)
117
- api.get([id, 'tag'].uri_concat)
118
- end
119
-
120
- # POST /api/v2/dashboard/id/tag
121
- # Set all tags associated with a specific dashboard.
122
- #
123
- # @param id [String] ID of the dashboard
124
- # @param tags [Array] list of tags to set.
125
- # @return [Wavefront::Response]
126
- #
127
- def tag_set(id, tags)
128
- wf_dashboard_id?(id)
129
- tags = Array(tags)
130
- tags.each { |t| wf_string?(t) }
131
- api.post([id, 'tag'].uri_concat, tags.to_json, 'application/json')
132
- end
133
-
134
- # DELETE /api/v2/dashboard/id/tag/tagValue
135
- # Remove a tag from a specific dashboard.
136
- #
137
- # @param id [String] ID of the dashboard
138
- # @param tag [String] tag to delete
139
- # @return [Wavefront::Response]
140
- #
141
- def tag_delete(id, tag)
142
- wf_dashboard_id?(id)
143
- wf_string?(tag)
144
- api.delete([id, 'tag', tag].uri_concat)
145
- end
146
-
147
- # PUT /api/v2/dashboard/id/tag/tagValue
148
- # Add a tag to a specific dashboard.
149
- #
150
- # @param id [String] ID of the dashboard
151
- # @param tag [String] tag to set.
152
- # @return [Wavefront::Response]
153
- #
154
- def tag_add(id, tag)
155
- wf_dashboard_id?(id)
156
- wf_string?(tag)
157
- api.put([id, 'tag', tag].uri_concat)
158
- end
159
-
160
114
  # POST /api/v2/dashboard/id/undelete
161
115
  # Move a dashboard from 'trash' back into active service.
162
116
  #
@@ -180,62 +134,8 @@ module Wavefront
180
134
  end
181
135
  alias unfavourite unfavorite
182
136
 
183
- # GET /api/v2/dashboard/acl
184
- # Get list of Access Control Lists for the specified dashboards
185
- # @param id_list [Array[String]] array of dashboard IDs
186
- # @return [Wavefront::Response]
187
- #
188
- def acls(id_list)
189
- id_list.each { |id| wf_dashboard_id?(id) }
190
- api.get_flat_params('acl', id: id_list)
191
- end
192
-
193
- # POST /api/v2/dashboard/acl/add
194
- # Adds the specified ids to the given dashboards' ACL
195
- # @param id [String] ID of dashboard
196
- # @param view [Array[Hash]] array of entities allowed to view
197
- # the dashboard. Entities may be users or groups, and are
198
- # defined as a Hash with keys :id and :name. For users the two
199
- # will be the same, for groups, not.
200
- # @param modify [Array[Hash]] array of entities allowed to
201
- # view and modify the dashboard. Same rules as @view.
202
- # @return [Wavefront::Response]
203
- #
204
- def acl_add(id, view = [], modify = [])
205
- api.post(%w[acl add].uri_concat,
206
- acl_body(id, view, modify),
207
- 'application/json')
208
- end
209
-
210
- # POST /api/v2/dashboard/acl/remove
211
- # Removes the specified ids from the given dashboards' ACL
212
- #
213
- # Though the API method is 'remove', the acl method names have
214
- # been chosen to correspond with the tag methods.
215
- #
216
- def acl_delete(id, view = [], modify = [])
217
- api.post(%w[acl remove].uri_concat,
218
- acl_body(id, view, modify),
219
- 'application/json')
220
- end
221
-
222
- # PUT /api/v2/dashboard/acl/set
223
- # Set ACL for the specified dashboards
224
- #
225
- def acl_set(id, view = [], modify = [])
226
- api.put(%w[acl set].uri_concat, acl_body(id, view, modify))
227
- end
228
-
229
- private
230
-
231
- def acl_body(id, view, modify)
137
+ def valid_id?(id)
232
138
  wf_dashboard_id?(id)
233
-
234
- raise ArgumentError unless view.is_a?(Array) && modify.is_a?(Array)
235
- raise ArgumentError unless view.all? { |h| h.is_a?(Hash) }
236
- raise ArgumentError unless modify.all? { |h| h.is_a?(Hash) }
237
-
238
- [{ entityId: id, viewAcl: view, modifyAcl: modify }]
239
139
  end
240
140
  end
241
141
  end