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 +5 -5
- data/lib/kapacitor/client.rb +50 -43
- data/lib/kapacitor/version.rb +1 -1
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b44ea41ae78d506eb56c16be57c70948724e91f5f07f6d25f1a54ccd84cfc5f7
|
4
|
+
data.tar.gz: 36200bc005660d681749a7106219efeb69447429692df1c202f422eb48ff2e48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d84c1cb3ae92d8f59335dcbbd056df4a5fef42454b495e92226b8d762629a2fa88e1c82976f60dd39b275195fd0675680c80a978f85c9353838b879c56bc0f1
|
7
|
+
data.tar.gz: 6eb9cd633c323513e310a059e470ee81e7426ae362fddfaab6ae5930baab2302ca7847709ac3dda15125f90895258191ca8c8805e98339405a4bdfd3080cdb6f
|
data/lib/kapacitor/client.rb
CHANGED
@@ -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: '
|
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
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
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
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
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
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
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
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
raise Exception, "Query returned a non successful HTTP code (
|
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
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
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 (#{$!})"
|
data/lib/kapacitor/version.rb
CHANGED
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
|
+
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:
|
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
|
-
|
71
|
-
|
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
|