wavefront-sdk 1.6.2 → 2.0.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 (81) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -0
  3. data/HISTORY.md +39 -13
  4. data/README.md +75 -28
  5. data/Rakefile +1 -1
  6. data/lib/wavefront-sdk/alert.rb +113 -17
  7. data/lib/wavefront-sdk/cloudintegration.rb +8 -8
  8. data/lib/wavefront-sdk/core/api.rb +99 -0
  9. data/lib/wavefront-sdk/core/api_caller.rb +211 -0
  10. data/lib/wavefront-sdk/{exception.rb → core/exception.rb} +11 -6
  11. data/lib/wavefront-sdk/{logger.rb → core/logger.rb} +2 -3
  12. data/lib/wavefront-sdk/{response.rb → core/response.rb} +69 -52
  13. data/lib/wavefront-sdk/credentials.rb +6 -3
  14. data/lib/wavefront-sdk/dashboard.rb +14 -14
  15. data/lib/wavefront-sdk/{constants.rb → defs/constants.rb} +1 -0
  16. data/lib/wavefront-sdk/defs/version.rb +1 -0
  17. data/lib/wavefront-sdk/derivedmetric.rb +14 -14
  18. data/lib/wavefront-sdk/distribution.rb +75 -0
  19. data/lib/wavefront-sdk/event.rb +13 -13
  20. data/lib/wavefront-sdk/externallink.rb +8 -8
  21. data/lib/wavefront-sdk/integration.rb +9 -9
  22. data/lib/wavefront-sdk/maintenancewindow.rb +54 -8
  23. data/lib/wavefront-sdk/message.rb +4 -4
  24. data/lib/wavefront-sdk/metric.rb +3 -3
  25. data/lib/wavefront-sdk/notificant.rb +9 -9
  26. data/lib/wavefront-sdk/paginator/base.rb +148 -0
  27. data/lib/wavefront-sdk/paginator/delete.rb +11 -0
  28. data/lib/wavefront-sdk/paginator/get.rb +11 -0
  29. data/lib/wavefront-sdk/paginator/post.rb +64 -0
  30. data/lib/wavefront-sdk/paginator/put.rb +11 -0
  31. data/lib/wavefront-sdk/proxy.rb +7 -7
  32. data/lib/wavefront-sdk/query.rb +4 -4
  33. data/lib/wavefront-sdk/report.rb +9 -25
  34. data/lib/wavefront-sdk/savedsearch.rb +8 -8
  35. data/lib/wavefront-sdk/search.rb +16 -13
  36. data/lib/wavefront-sdk/source.rb +14 -14
  37. data/lib/wavefront-sdk/{mixins.rb → support/mixins.rb} +8 -2
  38. data/lib/wavefront-sdk/{parse_time.rb → support/parse_time.rb} +2 -0
  39. data/lib/wavefront-sdk/types/status.rb +52 -0
  40. data/lib/wavefront-sdk/user.rb +8 -8
  41. data/lib/wavefront-sdk/validators.rb +52 -3
  42. data/lib/wavefront-sdk/webhook.rb +8 -8
  43. data/lib/wavefront-sdk/write.rb +153 -52
  44. data/lib/wavefront-sdk/writers/api.rb +38 -0
  45. data/lib/wavefront-sdk/writers/core.rb +146 -0
  46. data/lib/wavefront-sdk/writers/http.rb +42 -0
  47. data/lib/wavefront-sdk/writers/socket.rb +66 -0
  48. data/lib/wavefront-sdk/writers/summary.rb +39 -0
  49. data/lib/wavefront_sdk.rb +9 -0
  50. data/spec/spec_helper.rb +3 -0
  51. data/spec/wavefront-sdk/alert_spec.rb +6 -0
  52. data/spec/wavefront-sdk/{base_spec.rb → core/api_caller_spec.rb} +28 -41
  53. data/spec/wavefront-sdk/core/api_spec.rb +31 -0
  54. data/spec/wavefront-sdk/{logger_spec.rb → core/logger_spec.rb} +3 -3
  55. data/spec/wavefront-sdk/core/response_spec.rb +77 -0
  56. data/spec/wavefront-sdk/credentials_spec.rb +15 -10
  57. data/spec/wavefront-sdk/distribution_spec.rb +78 -0
  58. data/spec/wavefront-sdk/paginator/base_spec.rb +67 -0
  59. data/spec/wavefront-sdk/paginator/post_spec.rb +53 -0
  60. data/spec/wavefront-sdk/report_spec.rb +3 -1
  61. data/spec/wavefront-sdk/search_spec.rb +25 -0
  62. data/spec/wavefront-sdk/stdlib/array_spec.rb +2 -1
  63. data/spec/wavefront-sdk/stdlib/hash_spec.rb +6 -1
  64. data/spec/wavefront-sdk/stdlib/string_spec.rb +2 -0
  65. data/spec/wavefront-sdk/{mixins_spec.rb → support/mixins_spec.rb} +2 -2
  66. data/spec/wavefront-sdk/{parse_time_spec.rb → support/parse_time_spec.rb} +2 -2
  67. data/spec/wavefront-sdk/validators_spec.rb +64 -1
  68. data/spec/wavefront-sdk/write_spec.rb +55 -77
  69. data/spec/wavefront-sdk/writers/api_spec.rb +45 -0
  70. data/spec/wavefront-sdk/writers/core_spec.rb +49 -0
  71. data/spec/wavefront-sdk/writers/http_spec.rb +69 -0
  72. data/spec/wavefront-sdk/writers/socket_spec.rb +104 -0
  73. data/spec/wavefront-sdk/writers/summary_spec.rb +38 -0
  74. data/wavefront-sdk.gemspec +1 -1
  75. metadata +52 -24
  76. data/lib/wavefront-sdk/base.rb +0 -264
  77. data/lib/wavefront-sdk/base_write.rb +0 -185
  78. data/lib/wavefront-sdk/stdlib.rb +0 -5
  79. data/lib/wavefront-sdk/version.rb +0 -1
  80. data/spec/wavefront-sdk/base_write_spec.rb +0 -82
  81. data/spec/wavefront-sdk/response_spec.rb +0 -39
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a51f123acf9e28be6fde5916a80976858fe958f13cb7bfd2d1be6b97b201dde
4
- data.tar.gz: 2aa03e1e185c801dda9d56f9643578ba2f9692973f0bbab4dd728b93cdb44fee
3
+ metadata.gz: 78759a49a05aded24a69a8759c648c10c7e8f52857597a51ce73c3703d24b42a
4
+ data.tar.gz: cb66061865a11ecef526e726cb804ca2ab1f2a75ba72224be1c6c20ca2dabfc9
5
5
  SHA512:
6
- metadata.gz: 6b8921cec2fdf37e6451605d76895d2f538a04128c6e6217e28be58e7e0387cc95c74a37abc21f71f07bf87051ed587b0e2f10e33b703bc7c028085c383e8383
7
- data.tar.gz: 6a83ce8d88d17b4a494579bbf8a9602581a4684eeb8c29458710cba2a9d5797c693e36738c79cb852098494b7c4e9c6360158147aac6664460e826b27603e758
6
+ metadata.gz: 6be149c21dd32ce4a6f8dd56843331fe08f8b508fd0894139bf6d09279a0061fbb280553cdb35f33e546c3124f4d4ebfa4eca7bedfa26ef1489a4d5f178ca238
7
+ data.tar.gz: 41c617f4c39afd7e21965afe89521f17c2e8713c402c18259ca907b7dab09c29ba053f4497c14cbba5ec0601874a6aa37e18a81c5f26178dd85d737ef4d5df08
data/.rubocop.yml CHANGED
@@ -13,3 +13,9 @@ Metrics/ClassLength:
13
13
 
14
14
  Metrics/MethodLength:
15
15
  Max: 13
16
+
17
+ Style/DoubleNegation:
18
+ Enabled: false
19
+
20
+ Style/NumericLiterals:
21
+ Enabled: false
data/HISTORY.md CHANGED
@@ -1,10 +1,48 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.0
4
+ * Remove `#everything` method from all classes. (Breaking change.)
5
+ * Calling any method which takes the `limit` argument with `limit`
6
+ set to `:all` will automatically handle pagination, fetching all
7
+ matching objects.
8
+ * Calling with `limit` set to `:lazy` returns a lazy `Enumerable`
9
+ over which you can iterate. Every element is an object,
10
+ * Added one-word methods like `#snoozed`, `#active` and so-on to the
11
+ `Wavefront::Alert` class. These replicate the behaviour of similarly
12
+ named methods in the v1 SDK. (Though they use different underlying
13
+ API calls, as the alerts API has changed significantly.)
14
+ * Added `#pending` and `#ongoing` methods to
15
+ `Wavefront::MaintenanceWindow`.
16
+ * Added `MaintenanceWindow#summary` method, replicating the behaviour
17
+ of the `summary` v1 API call.
18
+ * Added `#ids`, `#names` and `#empty?` helper methods to
19
+ `Wavefront::Response`.
20
+ * Add `Distribution` class to help you write [Histogram
21
+ distributions](https://docs.wavefront.com/proxies_histograms.html).
22
+ * Writing points or distributions (or reporting points) shows the
23
+ wire-format point being sent if in `debug` or `verbose` mode.
24
+ * Broke up old write classes, moving the transport mechanism
25
+ into a separate class. The interface is backward-compatible,
26
+ though a new `:writer` constructor option lets you select the
27
+ transport mechanism.
28
+ * New transport mechanism class allows points to be HTTP POSTed to a
29
+ proxy rather than being written to a socket.
30
+ * The summary object returned when writing points is now a
31
+ standalone class.
32
+ * Use `wavefront` rather than `graphite_v2` as the `report` data
33
+ type.
34
+ * `Wavefront::Report` is now a shim around `Wavefront::Write`, left
35
+ in for backward-compatability. The "correct" way to send data via
36
+ the API is using `Wavefront::Write`, specifying the `:api` writer.
37
+ * `Wavefront::Credentials` object has new `all` method, which gives
38
+ a hash of proxy *and* API credentials. This is useful for passing
39
+ to `Wavefront::Write` as it means all writers will work without
40
+ modifying your code.
41
+
3
42
  ## 1.6.2 (22/08/2018)
4
43
  * Drop log priority of write class messages.
5
44
 
6
45
  ## 1.6.1 (22/08/2018)
7
-
8
46
  * Fix Ruby 2.2 bugs
9
47
  * Improve unit test separation
10
48
  * Allow updating of all external link parameters
@@ -15,27 +53,22 @@
15
53
  * Improve README.
16
54
 
17
55
  ## 1.5.0 (25/06/2018)
18
-
19
56
  * Add [derived
20
57
  metric](https://docs.wavefront.com/derived_metrics.html) support.
21
58
  * Add this changelog.
22
59
 
23
60
  ## 1.4.0 (10/04/2018)
24
-
25
61
  * Add support for [direct
26
62
  ingestion](https://docs.wavefront.com/direct_ingestion.html).
27
63
 
28
64
  ## 1.3.2 (03/04/2018)
29
-
30
65
  * Fix regression in write class.
31
66
 
32
67
  ## 1.3.1 (03/04/2018)
33
-
34
68
  * Fix Ruby 2.2 support.
35
69
  * Code tidy and linting improvements.
36
70
 
37
71
  ## 1.3.0 (29/03/2018)
38
-
39
72
  * Add support for delta metrics.
40
73
  * Add automatic pagination support for long lists of objects.
41
74
  Such lists can be treated as Ruby enumerables.
@@ -46,33 +79,26 @@
46
79
  * Support Ruby 2.5.
47
80
 
48
81
  ## 1.2.1 (12/10/2017)
49
-
50
82
  * Fix bug in relative time support.
51
83
  * Fix Ruby 2.4 support.
52
84
 
53
85
  ## 1.2.0 (12/10/2017)
54
-
55
86
  * Support relative times through mixin methods.
56
87
 
57
88
  ## 1.1.0 (09/10/2017)
58
-
59
89
  * Add support for notificant (alert target) API path.
60
90
  * Add support for integration API path.
61
91
  * Support new source description set/delete API endpoint.
62
92
 
63
93
  ## 1.0.3 (20/09/2017)
64
-
65
94
  * Gracefully handle tags with `nil` values.
66
95
  * Bump dependencies.
67
96
 
68
97
  ## 1.0.2 (04/08/2017)
69
-
70
98
  * Maintenance window bugfixes.
71
99
 
72
100
  ## 1.0.1 (31/07/2017)
73
-
74
101
  * Fix message ID validator.
75
102
 
76
103
  ## 1.0.0 (11/06/2017)
77
-
78
104
  First official release.
data/README.md CHANGED
@@ -9,7 +9,8 @@ auto-generated SDK.
9
9
  As well as complete API coverage, `wavefront-sdk` includes methods
10
10
  which facilitate various common tasks, and provides non-API
11
11
  features such as credential management, and writing points through a
12
- proxy.
12
+ proxy. It also has methods mimicking the behaviour of useful v1 API
13
+ calls which did not make it into v2.
13
14
 
14
15
  ## Installation
15
16
 
@@ -35,7 +36,7 @@ rubydoc.info](http://www.rubydoc.info/gems/wavefront-sdk/).
35
36
 
36
37
  ## Examples
37
38
 
38
- First, let's list the IDs of the users in our account. The `list()`
39
+ First, let's list the Wavefront proxies in our account. The `list()`
39
40
  method will return a `Wavefront::Response` object. This object has
40
41
  `status` and `response` methods. `status` always yields a structure
41
42
  containing `result`, `message` and `code` fields which can be
@@ -53,7 +54,7 @@ you to the same place.
53
54
  CREDS = { endpoint: 'metrics.wavefront.com',
54
55
  token: 'c7a1ff30-0dd8-fa60-e14d-f58f91bafc0e' }
55
56
 
56
- require 'wavefront-sdk/user'
57
+ require 'wavefront-sdk/proxy'
57
58
 
58
59
  # You can pass in a Ruby logger object, and tell the SDK to be
59
60
  # verbose.
@@ -62,35 +63,62 @@ require 'logger'
62
63
  log = Logger.new(STDOUT)
63
64
 
64
65
  wf = Wavefront::User.new(CREDS, verbose: true, logger: log)
66
+ proxies = wf.list
67
+
68
+ puts proxies.class
69
+ # Wavefront::Response
65
70
 
66
- # See how things went:
71
+ # See how things went. How specific do you want to be?
67
72
 
68
- p wf.status
69
- #<Wavefront::Type::Status:0x007feb99185538 @result="OK", @message="", @code=200>
73
+ puts proxies.ok?
74
+ # true
75
+ puts proxies.empty?
76
+ # false
77
+ puts proxies.status
78
+ # {:result=>"OK", :message=>"", :code=>200}
79
+ puts proxies.status.code
80
+ # 200
70
81
 
71
- # And print each user's ID
82
+ # Now print the proxy IDs
72
83
 
73
- wf.list.response.items.each { |user| puts user[:identifier] }
84
+ puts proxies.ids
85
+ # 1439acb2-ab07-4cf9-8397-2f2d758e52a0
86
+ # 87eca9df-fc47-4a24-88cf-6dd0bae245a9
87
+ # df77bd37-8f32-4e0c-b578-51eb42f22b6f
74
88
 
75
- # Now delete the user 'lolex@oldplace.com', disregarding the
76
- # response.
89
+ # Delete the first one.
77
90
 
78
- wf.delete('lolex@oldplace.com')
91
+ result = wf.delete('1439acb2-ab07-4cf9-8397-2f2d758e52a0')
92
+ puts result.ok?
93
+ # true
79
94
  ```
80
95
 
81
- All API classes expect `user` support pagination and will only
82
- return blocks of results. The `everything()` method returns a lazy
83
- enumerator to make dealing with pagination simpler.
96
+ By default (because it's the default behaviour of the API),
97
+ all API classes (except `user`) will only return blocks of results
98
+ when you ask for a list of objects.
99
+
100
+ You can set an offset and a limit when you list, but setting the
101
+ limit to the magic value `:all` will return all items, without you
102
+ having to deal with pagination.
103
+
104
+ Calling a method with the limit set to `:lazy` returns a lazy
105
+ enumerable.
84
106
 
85
107
  ```ruby
86
- Wavefront::Alert.new(c.creds).everything.each_with_index do |m, i|
87
- puts "#{i} #{m.id}"
88
- end
108
+ wf = Wavefront::Alert.new(creds.all)
109
+
110
+ # The first argument is how many object to get with each API call,
111
+ # the second gets us a lazy #Enumerable
112
+ wf.list(99, :lazy).each { |alert| puts alert.name }
113
+ # Point Rate
114
+ # Disk Error
115
+ # ...
89
116
  ```
90
117
 
91
- Retrieve a timeseries over the last 10 minutes, with one minute bucket
92
- granularity. We will describe the time as a Ruby object, but could also use
93
- an epoch timestamp. The SDK happily converts between the two.
118
+ We can easily write queries. Let's retrieve a timeseries over the
119
+ last 10 minutes, with one minute bucket granularity. We will
120
+ describe the time as a Ruby object, but could also use an epoch
121
+ timestamp. The SDK happily converts between the two.
94
122
 
95
123
 
96
124
  ```ruby
@@ -115,20 +143,39 @@ require 'wavefront-sdk/write'
115
143
 
116
144
  W_CREDS = { proxy: 'wavefront.localnet', port: 2878 }
117
145
 
118
- wf = Wavefront::Write.new(W_CREDS, debug: true)
146
+ wf = Wavefront::Write.new(W_CREDS, verbose:true)
119
147
 
120
148
  task = wf.write( [{ path: 'dev.test.sdk', value: 10 }])
121
-
122
- p task.response
123
- #{"sent"=>1, "rejected"=>0, "unsent"=>0}
124
- puts task.status.result
125
- #OK
149
+ # SDK DEBUG: Connecting to wavefront.localnet:2878.
150
+ # SDK INFO: dev.test.sdk 10 source=box
151
+ # SDK DEBUG: Closing connection to proxy.
152
+ puts task.response
153
+ # {"sent"=>1, "rejected"=>0, "unsent"=>0}
154
+ puts task.ok?
155
+ # true
126
156
  ```
127
157
 
128
158
  You can send delta metrics either by manually prefixing your metric
129
- path with a delta symbol, or by using the `write_delta()` method
159
+ path with a delta symbol, or by using the `write_delta()` method.
160
+ There is even a class to help you write Wavefront distributions.
161
+
162
+ You can also send points to a local proxy over HTTP. Just specify
163
+ `:http` as the `writer` option when you create your write object.
164
+
165
+ ```ruby
166
+ wf = Wavefront::Write.new(W_CREDS, writer: :http, verbose: true)
167
+
168
+ task = wf.write( [{ path: 'dev.test.sdk', value: 10 }])
169
+ # SDK INFO: dev.test.sdk 10 source=box
170
+ # SDK INFO: uri: POST http://wavefront.localnet:2878/
171
+ # SDK INFO: body: dev.test.sdk 10 source=box
172
+ p task.response
173
+ # {"sent"=>1, "rejected"=>0, "unsent"=>0}
174
+ puts task.ok?
175
+ # true
176
+ ```
130
177
 
131
- The SDK also provides a helper class for extracting credentials from a
178
+ The SDK provides a helper class for extracting credentials from a
132
179
  configuration file. If you don't supply a file, defaults will be
133
180
  used. You can even override things with environment variables.
134
181
 
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rubocop/rake_task'
5
5
  task default: %i[rubocop test]
6
6
 
7
7
  Rake::TestTask.new do |t|
8
- t.pattern = 'spec/wavefront-sdk/*_spec.rb'
8
+ t.pattern = 'spec/**/*_spec.rb'
9
9
  t.warning = false
10
10
  end
11
11
 
@@ -1,11 +1,12 @@
1
- require_relative 'base'
1
+ require_relative 'defs/constants'
2
+ require_relative 'core/api'
2
3
 
3
4
  module Wavefront
4
5
  #
5
6
  # View and manage alerts. Alerts are identified by their millisecond
6
7
  # epoch timestamp. Returns a Wavefront::Response::Alert object.
7
8
  #
8
- class Alert < Base
9
+ class Alert < CoreApi
9
10
  def update_keys
10
11
  %i[id name target condition displayExpression minutes
11
12
  resolveAfterMinutes severity additionalInformation]
@@ -19,7 +20,7 @@ module Wavefront
19
20
  # @return [Hash]
20
21
  #
21
22
  def list(offset = 0, limit = 100)
22
- api_get('', offset: offset, limit: limit)
23
+ api.get('', offset: offset, limit: limit)
23
24
  end
24
25
 
25
26
  # POST /api/v2/alert
@@ -32,7 +33,7 @@ module Wavefront
32
33
  #
33
34
  def create(body)
34
35
  raise ArgumentError unless body.is_a?(Hash)
35
- api_post('', body, 'application/json')
36
+ api.post('', body, 'application/json')
36
37
  end
37
38
 
38
39
  # DELETE /api/v2/alert/id
@@ -47,7 +48,7 @@ module Wavefront
47
48
  #
48
49
  def delete(id)
49
50
  wf_alert_id?(id)
50
- api_delete(id)
51
+ api.delete(id)
51
52
  end
52
53
 
53
54
  # GET /api/v2/alert/id
@@ -64,7 +65,7 @@ module Wavefront
64
65
  wf_version?(version) if version
65
66
  fragments = [id]
66
67
  fragments += ['history', version] if version
67
- api_get(fragments.uri_concat)
68
+ api.get(fragments.uri_concat)
68
69
  end
69
70
 
70
71
  # PUT /api/v2/alert/id
@@ -82,9 +83,9 @@ module Wavefront
82
83
  wf_alert_id?(id)
83
84
  raise ArgumentError unless body.is_a?(Hash)
84
85
 
85
- return api_put(id, body, 'application/json') unless modify
86
+ return api.put(id, body, 'application/json') unless modify
86
87
 
87
- api_put(id, hash_for_update(describe(id).response, body),
88
+ api.put(id, hash_for_update(describe(id).response, body),
88
89
  'application/json')
89
90
  end
90
91
 
@@ -100,7 +101,7 @@ module Wavefront
100
101
  qs[:offset] = offset if offset
101
102
  qs[:limit] = limit if limit
102
103
 
103
- api_get([id, 'history'].uri_concat, qs)
104
+ api.get([id, 'history'].uri_concat, qs)
104
105
  end
105
106
 
106
107
  # POST /api/v2/alert/id/snooze
@@ -114,7 +115,7 @@ module Wavefront
114
115
  def snooze(id, seconds = nil)
115
116
  wf_alert_id?(id)
116
117
  qs = seconds ? "?seconds=#{seconds}" : ''
117
- api_post([id, "snooze#{qs}"].uri_concat, nil)
118
+ api.post([id, "snooze#{qs}"].uri_concat, nil)
118
119
  end
119
120
 
120
121
  # GET /api/v2/alert/id/tag
@@ -125,7 +126,7 @@ module Wavefront
125
126
  #
126
127
  def tags(id)
127
128
  wf_alert_id?(id)
128
- api_get([id, 'tag'].uri_concat)
129
+ api.get([id, 'tag'].uri_concat)
129
130
  end
130
131
 
131
132
  # POST /api/v2/alert/id/tag
@@ -139,7 +140,7 @@ module Wavefront
139
140
  wf_alert_id?(id)
140
141
  tags = Array(tags)
141
142
  tags.each { |t| wf_string?(t) }
142
- api_post([id, 'tag'].uri_concat, tags.to_json, 'application/json')
143
+ api.post([id, 'tag'].uri_concat, tags.to_json, 'application/json')
143
144
  end
144
145
 
145
146
  # DELETE /api/v2/alert/id/tag/tagValue
@@ -152,7 +153,7 @@ module Wavefront
152
153
  def tag_delete(id, tag)
153
154
  wf_alert_id?(id)
154
155
  wf_string?(tag)
155
- api_delete([id, 'tag', tag].uri_concat)
156
+ api.delete([id, 'tag', tag].uri_concat)
156
157
  end
157
158
 
158
159
  # PUT /api/v2/alert/id/tag/tagValue
@@ -165,7 +166,7 @@ module Wavefront
165
166
  def tag_add(id, tag)
166
167
  wf_alert_id?(id)
167
168
  wf_string?(tag)
168
- api_put([id, 'tag', tag].uri_concat)
169
+ api.put([id, 'tag', tag].uri_concat)
169
170
  end
170
171
 
171
172
  # POST /api/v2/alert/id/undelete
@@ -176,7 +177,7 @@ module Wavefront
176
177
  #
177
178
  def undelete(id)
178
179
  wf_alert_id?(id)
179
- api_post([id, 'undelete'].uri_concat)
180
+ api.post([id, 'undelete'].uri_concat)
180
181
  end
181
182
 
182
183
  # POST /api/v2/alert/id/unsnooze
@@ -187,7 +188,7 @@ module Wavefront
187
188
  #
188
189
  def unsnooze(id)
189
190
  wf_alert_id?(id)
190
- api_post([id, 'unsnooze'].uri_concat)
191
+ api.post([id, 'unsnooze'].uri_concat)
191
192
  end
192
193
 
193
194
  # GET /api/v2/alert/summary
@@ -196,7 +197,102 @@ module Wavefront
196
197
  # @return [Wavefront::Response]
197
198
  #
198
199
  def summary
199
- api_get('summary')
200
+ api.get('summary')
201
+ end
202
+
203
+ # The following methods replicate similarly named ones in the v1
204
+ # SDK. The v2 API does not provide the level of alert-querying
205
+ # convenience v1 did, but we can still give our users those
206
+ # lovely simple methods. Note that these are constructions of
207
+ # the SDK and do not actually correspond to the underlying API.
208
+
209
+ # @return [Wavefront::Response] all currently firing alerts
210
+ #
211
+ def active
212
+ firing
213
+ end
214
+
215
+ # @return [Wavefront::Response] all alerts currently in a
216
+ # maintenance window.
217
+ #
218
+ def affected_by__maintenance
219
+ in_maintenance
220
+ end
221
+
222
+ # @return [Wavefront::Response] all alerts which have an invalid
223
+ # query.
224
+ #
225
+ def invalid
226
+ alerts_in_state(:invalid)
227
+ end
228
+
229
+ # For completeness, one-word methods like those above for all
230
+ # possible alert states.
231
+
232
+ # @return [Wavefront::Response] all alerts currently snoozed
233
+ #
234
+ def snoozed
235
+ alerts_in_state(:snoozed)
236
+ end
237
+
238
+ # @return [Wavefront::Response] all currently firing alerts.
239
+ #
240
+ def firing
241
+ alerts_in_state(:firing)
242
+ end
243
+
244
+ # @return [Wavefront::Response] all alerts currently in a
245
+ # maintenance window.
246
+ #
247
+ def in_maintenance
248
+ alerts_in_state(:in_maintenance)
249
+ end
250
+
251
+ # @return [Wavefront::Response] I honestly don't know what the
252
+ # NONE state denotes, but this will fetch alerts which have
253
+ # it.
254
+ #
255
+ def none
256
+ alerts_in_state(:none)
257
+ end
258
+
259
+ # @return [Wavefront::Response] all alerts being checked.
260
+ #
261
+ def checking
262
+ alerts_in_state(:checking)
263
+ end
264
+
265
+ # @return [Wavefront::Response] all alerts in the trash.
266
+ #
267
+ def trash
268
+ alerts_in_state(:trash)
269
+ end
270
+
271
+ # @return [Wavefront::Response] all alerts reporting NO_DATA.
272
+ #
273
+ def no_data
274
+ alerts_in_state(:no_data)
275
+ end
276
+
277
+ # @return [Wavefront::Response] all your alerts
278
+ #
279
+ def all
280
+ list(PAGE_SIZE, :all)
281
+ end
282
+
283
+ # Use a search to get all alerts in the given state. You would
284
+ # be better to use one of the wrapper methods like #firing,
285
+ # #snoozed etc, but I've left this method public in case new
286
+ # states are added before the SDK supports them.
287
+ # @param state [Symbol] state such as :firing, :snoozed etc. See
288
+ # the Alert Swagger documentation for a full list
289
+ # @return [Wavfront::Response]
290
+ #
291
+ def alerts_in_state(state)
292
+ require_relative 'search'
293
+ wfs = Wavefront::Search.new(creds, opts)
294
+ query = { key: 'status', value: state, matchingMethod: 'EXACT' }
295
+ wfs.search(:alert, query, limit: :all, offset: PAGE_SIZE)
200
296
  end
201
297
  end
202
298
  end