kapacitor-ruby 1.0.4 → 1.0.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7dfcfe3b1c67299767a2153fba38bd6f1fc30c65
4
- data.tar.gz: 4613998ffee885a48ca82a04c1be35630e287d89
2
+ SHA256:
3
+ metadata.gz: 66a4c32e20ab239f8839a7338e258289b701bdab36076321aae2469cc64b47bd
4
+ data.tar.gz: 96b339be050531f6d75c32f80700fb33621206af15fb60bc94b13a8dfa4b10c8
5
5
  SHA512:
6
- metadata.gz: 0b219dfddac5f65fdbea92d1e352b7848927262905d9e2e29e7cc518fb12be60883c9f638620d76b4f3c4fd287c152bd7bfa9887f204d457ed35326b961de43b
7
- data.tar.gz: 8be9ab1b17c1b057d8a49924c6c0dbc4b63d61fa02b6702967ffc458fc2b25f284b75fe5465ef66c605cda85fac5855f8bedab838cfa72ba961ab964afb446df
6
+ metadata.gz: 7068fa82ad380aeec545ba413825bfcbe04fa090d6ca614ce74b5a37f5bdf7480dd01c03d74ee2494e36ed2470c7a41ad2c7c1324cbada2b5fd55738b4c4a971
7
+ data.tar.gz: bc87aae7116794212f2b064a245a74eb6a5d28b6664d2f3cdf2fb75668cc22042f633ce8a675d6c28da15bcc724a6fea2221c45840c8e5a56a73d57410cd8906
@@ -13,7 +13,7 @@ module Kapacitor
13
13
  # @param url [String] Kapacitor REST API's URL (defaults to `http://localhost:9092`)
14
14
  # @param version [Integer] API version (defaults to `v1preview`)
15
15
  #
16
- def initialize(url: 'http://localhost:9092/kapacitor', version: 'v1preview')
16
+ def initialize(url: 'http://localhost:9092/kapacitor', version: 'v1')
17
17
  @http = HTTPClient.new
18
18
  @url = [url, version].join('/')
19
19
  end
@@ -61,6 +61,15 @@ module Kapacitor
61
61
  api_delete(endpoint: "templates/#{id}")
62
62
  end
63
63
 
64
+ # Retrieve Kapacitor topic
65
+ #
66
+ # @return [List[String]] List of topics
67
+ #
68
+ def topics()
69
+ res = api_get(endpoint: "alerts/topics")
70
+ return res['topics'].map { |v| v['id'] }
71
+ end
72
+
64
73
  # Retrieve Kapacitor templates
65
74
  #
66
75
  # @param offset [Integer] Offset count for paginating through templates
@@ -130,7 +139,7 @@ module Kapacitor
130
139
  req['type'] = opts[:type] if opts[:type]
131
140
  req['dbrps'] = opts[:dbrps] if opts[:dbrps]
132
141
  req['script'] = opts[:script] if opts[:script]
133
- req['status'] = opts[:status] if opts[:status]
142
+ req['status'] = 'disabled'
134
143
  req['vars'] = opts[:vars] if opts[:vars]
135
144
 
136
145
  if opts[:type]
@@ -142,6 +151,12 @@ module Kapacitor
142
151
  end
143
152
 
144
153
  api_patch(endpoint: "tasks/#{id}", data: req) unless req.empty?
154
+
155
+ if opts['status'] == 'enabled'
156
+ req['status'] = 'enabled'
157
+ api_patch(endpoint: "tasks/#{id}", data: req) unless req.empty?
158
+ end
159
+
145
160
  end
146
161
 
147
162
  # Delete a Kapacitor task
@@ -179,20 +194,17 @@ module Kapacitor
179
194
  #
180
195
  # @param id [String] Handler ID
181
196
  # @param topic [String] Topic name
182
- # @param actions [Array[Hash]] Handler actions
197
+ # @param kind [String] Kind of handler
198
+ # @param match [String] Lambda expression
199
+ # @param options [Hash] Handler options
183
200
  #
184
- def define_topic_handler(id:, topic:, actions:)
185
- req = {}
186
- req['id'] = id
187
-
188
- actions = [actions] unless actions.is_a?(Array)
189
- raise ArgumentError, "Kapacitor topic handler requires one or more actions" unless actions.size > 0
190
-
191
- actions.each do |action|
192
- raise ArgumentError, "Missing required kind attribute for action #{action}"
193
- end
194
-
195
- req['actions'] = actions
201
+ def define_topic_handler(id:, topic:, kind:, match: nil, options: {})
202
+ req = {
203
+ 'id': id,
204
+ 'kind': kind
205
+ }
206
+ req['match'] = match unless match.nil?
207
+ req['options'] = options
196
208
  api_post(endpoint: "alerts/topics/#{topic}/handlers", data: req)
197
209
  end
198
210
 
@@ -200,15 +212,17 @@ module Kapacitor
200
212
  #
201
213
  # @param id [String] Handler ID
202
214
  # @param topic [String] Topic name
203
- # @param actions [Array[Hash]] Handler actions
215
+ # @param kind [String] Kind of handler
216
+ # @param match [String] Lambda expression
217
+ # @param options [Hash] Handler options
204
218
  #
205
- def update_topic_handler(id:, topic:, actions:)
206
- req = {}
207
-
208
- actions = [actions] unless actions.is_a?(Array)
209
- raise ArgumentError, "Kapacitor topic handler requires one or more actions" unless actions.size > 0
210
-
211
- req['actions'] = actions
219
+ def update_topic_handler(id:, topic:, kind:, match: nil, options: nil)
220
+ req = {
221
+ 'id': id,
222
+ 'kind': kind
223
+ }
224
+ req['match'] = match unless match.nil?
225
+ req['options'] = options unless options.nil?
212
226
  api_put(endpoint: "alerts/topics/#{topic}/handlers/#{id}", data: req) unless req.empty?
213
227
  end
214
228
 
@@ -240,14 +254,14 @@ private
240
254
  def api_get(endpoint:, query: nil)
241
255
  begin
242
256
  resp = self.http.get([self.url, endpoint].join('/'), query, {'Content-type' => 'application/json', 'Accept' => 'application/json'})
243
- if resp.status == 200
244
- begin
245
- data = JSON.parse(resp.body)
246
- rescue JSON::ParserError
247
- raise Exception, "Failed to decode response message"
248
- end
249
- else
250
- raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason})"
257
+ begin
258
+ data = JSON.parse(resp.body) unless resp.body.empty?
259
+ rescue JSON::ParserError
260
+ raise Exception, "Failed to decode response message"
261
+ end
262
+ if resp.status != 200
263
+ error = data.include?('error') ? data['error'] : data.inspect if data
264
+ raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason}#{", Error: #{error}" if error}"
251
265
  end
252
266
  rescue
253
267
  raise Exception, "Failed to execute GET request to Kapacitor REST API (#{$!})"
@@ -264,14 +278,14 @@ private
264
278
  def api_post(endpoint:, data:)
265
279
  begin
266
280
  resp = self.http.post([self.url, endpoint].join('/'), data.to_json, {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
267
- if resp.status == 200
268
- begin
269
- data = JSON.parse(resp.body)
270
- rescue JSON::ParserError
271
- raise Exception, "Failed to decode response message"
272
- end
273
- else
274
- raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason})"
281
+ begin
282
+ data = JSON.parse(resp.body) unless resp.body.empty?
283
+ rescue JSON::ParserError
284
+ raise Exception, "Failed to decode response message"
285
+ end
286
+ if resp.status != 200
287
+ error = data.include?('error') ? data['error'] : data.inspect if data
288
+ raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason}#{", Error: #{error}" if error}"
275
289
  end
276
290
  rescue
277
291
  raise Exception, "Failed to execute POST request to Kapacitor REST API (#{$!})"
@@ -287,16 +301,14 @@ private
287
301
  def api_delete(endpoint:)
288
302
  begin
289
303
  resp = self.http.delete([self.url, endpoint].join('/'), {'Content-type' => 'application/json', 'Accept' => 'application/json'})
290
- if resp.status == 204
291
- if resp.body
292
- begin
293
- data = JSON.parse(resp.body)
294
- rescue JSON::ParserError
295
- raise Exception, "Failed to decode response message"
296
- end
297
- end
298
- else
299
- raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason})"
304
+ begin
305
+ data = JSON.parse(resp.body) unless resp.body.empty?
306
+ rescue JSON::ParserError
307
+ raise Exception, "Failed to decode response message"
308
+ end
309
+ if resp.status != 204
310
+ error = data.include?('error') ? data['error'] : data.inspect if data
311
+ raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason}#{", Error: #{error}" if error}"
300
312
  end
301
313
  rescue
302
314
  raise Exception, "Failed to execute DELETE request to Kapacitor REST API (#{$!})"
@@ -313,14 +325,14 @@ private
313
325
  def api_patch(endpoint:, data:)
314
326
  begin
315
327
  resp = self.http.patch([self.url, endpoint].join('/'), data.to_json, {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
316
- if resp.status == 200
317
- begin
318
- data = JSON.parse(resp.body)
319
- rescue JSON::ParserError
320
- raise Exception, "Failed to decode response message"
321
- end
322
- else
323
- raise Exception, "Query returned a non successful HTTP code (Code: #{resp.status}, Reason: #{resp.reason})"
328
+ begin
329
+ data = JSON.parse(resp.body) unless resp.body.empty?
330
+ rescue JSON::ParserError
331
+ raise Exception, "Failed to decode response message"
332
+ end
333
+ if resp.status != 200
334
+ error = data.include?('error') ? data['error'] : data.inspect if data
335
+ raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason}#{", Error: #{error}" if error}"
324
336
  end
325
337
  rescue
326
338
  raise Exception, "Failed to execute PATCH request to Kapacitor REST API (#{$!})"
@@ -337,14 +349,14 @@ private
337
349
  def api_put(endpoint:, data:)
338
350
  begin
339
351
  resp = self.http.put([self.url, endpoint].join('/'), data.to_json, {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
340
- if resp.status == 200
341
- begin
342
- data = JSON.parse(resp.body)
343
- rescue JSON::ParserError
344
- raise Exception, "Failed to decode response message"
345
- end
346
- else
347
- raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason})"
352
+ begin
353
+ data = JSON.parse(resp.body) unless resp.body.empty?
354
+ rescue JSON::ParserError
355
+ raise Exception, "Failed to decode response message"
356
+ end
357
+ if resp.status != 200
358
+ error = data.include?('error') ? data['error'] : data.inspect if data
359
+ raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason}#{", Error: #{error}" if error}"
348
360
  end
349
361
  rescue
350
362
  raise Exception, "Failed to execute PUT request to Kapacitor REST API (#{$!})"
@@ -3,7 +3,7 @@
3
3
  #
4
4
 
5
5
  module Kapacitor
6
- VERSION = "1.0.4"
6
+ VERSION = "1.0.9"
7
7
 
8
8
  def self.version
9
9
  VERSION
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kapacitor-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matteo Cerutti
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-08 00:00:00.000000000 Z
11
+ date: 2020-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -52,7 +52,7 @@ homepage: https://github.com/m4ce/kapacitor-ruby
52
52
  licenses:
53
53
  - Apache 2.0
54
54
  metadata: {}
55
- post_install_message:
55
+ post_install_message:
56
56
  rdoc_options: []
57
57
  require_paths:
58
58
  - lib
@@ -67,9 +67,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  requirements: []
70
- rubyforge_project:
71
- rubygems_version: 2.6.8
72
- signing_key:
70
+ rubygems_version: 3.0.1
71
+ signing_key:
73
72
  specification_version: 4
74
73
  summary: Ruby client library that allows to interact with the Kapacitor JSON REST
75
74
  API