kapacitor-ruby 1.0.5 → 1.0.10

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
2
  SHA256:
3
- metadata.gz: b44ea41ae78d506eb56c16be57c70948724e91f5f07f6d25f1a54ccd84cfc5f7
4
- data.tar.gz: 36200bc005660d681749a7106219efeb69447429692df1c202f422eb48ff2e48
3
+ metadata.gz: bc8385ff59595cd0874e1ebc37cd0dd6ca5cb8015d9214e05ee41d44401d8761
4
+ data.tar.gz: 2b7bd54a2ae5c1e305e95245ff0b52c305c99ebce1ec4c4aa5a851472586dd62
5
5
  SHA512:
6
- metadata.gz: 5d84c1cb3ae92d8f59335dcbbd056df4a5fef42454b495e92226b8d762629a2fa88e1c82976f60dd39b275195fd0675680c80a978f85c9353838b879c56bc0f1
7
- data.tar.gz: 6eb9cd633c323513e310a059e470ee81e7426ae362fddfaab6ae5930baab2302ca7847709ac3dda15125f90895258191ca8c8805e98339405a4bdfd3080cdb6f
6
+ metadata.gz: 97cb14918feec5ce8ee40fe59492bfdb92fe50c03543a2690920316105ce8dea56b197ba7f2804ed63f776c122300ee0ba650e69cecacb9ab4f9ad9ba47fefca
7
+ data.tar.gz: d66623d57ebbf004e47dd1447f7daf4a1a244a21b722f160f8d6636718a507054a0e00975d33231caf805f0b3bfb12604e864da4fa62350660c38342b263bbac
@@ -66,7 +66,7 @@ module Kapacitor
66
66
  # @return [List[String]] List of topics
67
67
  #
68
68
  def topics()
69
- res = api_get(endpoint: "alerts/topics")['topics']
69
+ res = api_get(endpoint: "alerts/topics")
70
70
  return res['topics'].map { |v| v['id'] }
71
71
  end
72
72
 
@@ -139,7 +139,7 @@ module Kapacitor
139
139
  req['type'] = opts[:type] if opts[:type]
140
140
  req['dbrps'] = opts[:dbrps] if opts[:dbrps]
141
141
  req['script'] = opts[:script] if opts[:script]
142
- req['status'] = opts[:status] if opts[:status]
142
+ req['status'] = 'disabled'
143
143
  req['vars'] = opts[:vars] if opts[:vars]
144
144
 
145
145
  if opts[:type]
@@ -151,6 +151,11 @@ module Kapacitor
151
151
  end
152
152
 
153
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
154
159
  end
155
160
 
156
161
  # Delete a Kapacitor task
@@ -188,20 +193,17 @@ module Kapacitor
188
193
  #
189
194
  # @param id [String] Handler ID
190
195
  # @param topic [String] Topic name
191
- # @param actions [Array[Hash]] Handler actions
196
+ # @param kind [String] Kind of handler
197
+ # @param match [String] Lambda expression
198
+ # @param options [Hash] Handler options
192
199
  #
193
- def define_topic_handler(id:, topic:, actions:)
194
- req = {}
195
- req['id'] = id
196
-
197
- actions = [actions] unless actions.is_a?(Array)
198
- raise ArgumentError, "Kapacitor topic handler requires one or more actions" unless actions.size > 0
199
-
200
- actions.each do |action|
201
- raise ArgumentError, "Missing required kind attribute for action #{action}"
202
- end
203
-
204
- req['actions'] = actions
200
+ def define_topic_handler(id:, topic:, kind:, match: nil, options: {})
201
+ req = {
202
+ 'id': id,
203
+ 'kind': kind
204
+ }
205
+ req['match'] = match unless match.nil?
206
+ req['options'] = options
205
207
  api_post(endpoint: "alerts/topics/#{topic}/handlers", data: req)
206
208
  end
207
209
 
@@ -209,15 +211,17 @@ module Kapacitor
209
211
  #
210
212
  # @param id [String] Handler ID
211
213
  # @param topic [String] Topic name
212
- # @param actions [Array[Hash]] Handler actions
214
+ # @param kind [String] Kind of handler
215
+ # @param match [String] Lambda expression
216
+ # @param options [Hash] Handler options
213
217
  #
214
- def update_topic_handler(id:, topic:, actions:)
215
- req = {}
216
-
217
- actions = [actions] unless actions.is_a?(Array)
218
- raise ArgumentError, "Kapacitor topic handler requires one or more actions" unless actions.size > 0
219
-
220
- req['actions'] = actions
218
+ def update_topic_handler(id:, topic:, kind:, match: nil, options: nil)
219
+ req = {
220
+ 'id': id,
221
+ 'kind': kind
222
+ }
223
+ req['match'] = match unless match.nil?
224
+ req['options'] = options unless options.nil?
221
225
  api_put(endpoint: "alerts/topics/#{topic}/handlers/#{id}", data: req) unless req.empty?
222
226
  end
223
227
 
@@ -250,7 +254,7 @@ private
250
254
  begin
251
255
  resp = self.http.get([self.url, endpoint].join('/'), query, {'Content-type' => 'application/json', 'Accept' => 'application/json'})
252
256
  begin
253
- data = JSON.parse(resp.body) unless resp.body.blank?
257
+ data = JSON.parse(resp.body) unless resp.body.empty?
254
258
  rescue JSON::ParserError
255
259
  raise Exception, "Failed to decode response message"
256
260
  end
@@ -274,7 +278,7 @@ private
274
278
  begin
275
279
  resp = self.http.post([self.url, endpoint].join('/'), data.to_json, {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
276
280
  begin
277
- data = JSON.parse(resp.body) unless resp.body.blank?
281
+ data = JSON.parse(resp.body) unless resp.body.empty?
278
282
  rescue JSON::ParserError
279
283
  raise Exception, "Failed to decode response message"
280
284
  end
@@ -297,7 +301,7 @@ private
297
301
  begin
298
302
  resp = self.http.delete([self.url, endpoint].join('/'), {'Content-type' => 'application/json', 'Accept' => 'application/json'})
299
303
  begin
300
- data = JSON.parse(resp.body) unless resp.body.blank?
304
+ data = JSON.parse(resp.body) unless resp.body.empty?
301
305
  rescue JSON::ParserError
302
306
  raise Exception, "Failed to decode response message"
303
307
  end
@@ -321,7 +325,7 @@ private
321
325
  begin
322
326
  resp = self.http.patch([self.url, endpoint].join('/'), data.to_json, {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
323
327
  begin
324
- data = JSON.parse(resp.body) unless resp.body.blank?
328
+ data = JSON.parse(resp.body) unless resp.body.empty?
325
329
  rescue JSON::ParserError
326
330
  raise Exception, "Failed to decode response message"
327
331
  end
@@ -345,7 +349,7 @@ private
345
349
  begin
346
350
  resp = self.http.put([self.url, endpoint].join('/'), data.to_json, {'Content-Type' => 'application/json', 'Accept' => 'application/json'})
347
351
  begin
348
- data = JSON.parse(resp.body) unless resp.body.blank?
352
+ data = JSON.parse(resp.body) unless resp.body.empty?
349
353
  rescue JSON::ParserError
350
354
  raise Exception, "Failed to decode response message"
351
355
  end
@@ -3,7 +3,7 @@
3
3
  #
4
4
 
5
5
  module Kapacitor
6
- VERSION = "1.0.5"
6
+ VERSION = "1.0.10"
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.5
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matteo Cerutti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-27 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