kapacitor-ruby 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
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: b44ea41ae78d506eb56c16be57c70948724e91f5f07f6d25f1a54ccd84cfc5f7
4
+ data.tar.gz: 36200bc005660d681749a7106219efeb69447429692df1c202f422eb48ff2e48
5
5
  SHA512:
6
- metadata.gz: 0b219dfddac5f65fdbea92d1e352b7848927262905d9e2e29e7cc518fb12be60883c9f638620d76b4f3c4fd287c152bd7bfa9887f204d457ed35326b961de43b
7
- data.tar.gz: 8be9ab1b17c1b057d8a49924c6c0dbc4b63d61fa02b6702967ffc458fc2b25f284b75fe5465ef66c605cda85fac5855f8bedab838cfa72ba961ab964afb446df
6
+ metadata.gz: 5d84c1cb3ae92d8f59335dcbbd056df4a5fef42454b495e92226b8d762629a2fa88e1c82976f60dd39b275195fd0675680c80a978f85c9353838b879c56bc0f1
7
+ data.tar.gz: 6eb9cd633c323513e310a059e470ee81e7426ae362fddfaab6ae5930baab2302ca7847709ac3dda15125f90895258191ca8c8805e98339405a4bdfd3080cdb6f
@@ -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")['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
@@ -240,14 +249,14 @@ private
240
249
  def api_get(endpoint:, query: nil)
241
250
  begin
242
251
  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})"
252
+ begin
253
+ data = JSON.parse(resp.body) unless resp.body.blank?
254
+ rescue JSON::ParserError
255
+ raise Exception, "Failed to decode response message"
256
+ end
257
+ if resp.status != 200
258
+ error = data.include?('error') ? data['error'] : data.inspect if data
259
+ raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason}#{", Error: #{error}" if error}"
251
260
  end
252
261
  rescue
253
262
  raise Exception, "Failed to execute GET request to Kapacitor REST API (#{$!})"
@@ -264,14 +273,14 @@ private
264
273
  def api_post(endpoint:, data:)
265
274
  begin
266
275
  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})"
276
+ begin
277
+ data = JSON.parse(resp.body) unless resp.body.blank?
278
+ rescue JSON::ParserError
279
+ raise Exception, "Failed to decode response message"
280
+ end
281
+ if resp.status != 200
282
+ error = data.include?('error') ? data['error'] : data.inspect if data
283
+ raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason}#{", Error: #{error}" if error}"
275
284
  end
276
285
  rescue
277
286
  raise Exception, "Failed to execute POST request to Kapacitor REST API (#{$!})"
@@ -287,16 +296,14 @@ private
287
296
  def api_delete(endpoint:)
288
297
  begin
289
298
  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})"
299
+ begin
300
+ data = JSON.parse(resp.body) unless resp.body.blank?
301
+ rescue JSON::ParserError
302
+ raise Exception, "Failed to decode response message"
303
+ end
304
+ if resp.status != 204
305
+ error = data.include?('error') ? data['error'] : data.inspect if data
306
+ raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason}#{", Error: #{error}" if error}"
300
307
  end
301
308
  rescue
302
309
  raise Exception, "Failed to execute DELETE request to Kapacitor REST API (#{$!})"
@@ -313,14 +320,14 @@ private
313
320
  def api_patch(endpoint:, data:)
314
321
  begin
315
322
  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})"
323
+ begin
324
+ data = JSON.parse(resp.body) unless resp.body.blank?
325
+ rescue JSON::ParserError
326
+ raise Exception, "Failed to decode response message"
327
+ end
328
+ if resp.status != 200
329
+ error = data.include?('error') ? data['error'] : data.inspect if data
330
+ raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason}#{", Error: #{error}" if error}"
324
331
  end
325
332
  rescue
326
333
  raise Exception, "Failed to execute PATCH request to Kapacitor REST API (#{$!})"
@@ -337,14 +344,14 @@ private
337
344
  def api_put(endpoint:, data:)
338
345
  begin
339
346
  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})"
347
+ begin
348
+ data = JSON.parse(resp.body) unless resp.body.blank?
349
+ rescue JSON::ParserError
350
+ raise Exception, "Failed to decode response message"
351
+ end
352
+ if resp.status != 200
353
+ error = data.include?('error') ? data['error'] : data.inspect if data
354
+ raise Exception, "Query returned a non successful HTTP code (Status: #{resp.status}, Reason: #{resp.reason}#{", Error: #{error}" if error}"
348
355
  end
349
356
  rescue
350
357
  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.5"
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.5
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-11-27 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