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 +4 -4
- data/lib/kapacitor/client.rb +32 -28
- data/lib/kapacitor/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc8385ff59595cd0874e1ebc37cd0dd6ca5cb8015d9214e05ee41d44401d8761
|
4
|
+
data.tar.gz: 2b7bd54a2ae5c1e305e95245ff0b52c305c99ebce1ec4c4aa5a851472586dd62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97cb14918feec5ce8ee40fe59492bfdb92fe50c03543a2690920316105ce8dea56b197ba7f2804ed63f776c122300ee0ba650e69cecacb9ab4f9ad9ba47fefca
|
7
|
+
data.tar.gz: d66623d57ebbf004e47dd1447f7daf4a1a244a21b722f160f8d6636718a507054a0e00975d33231caf805f0b3bfb12604e864da4fa62350660c38342b263bbac
|
data/lib/kapacitor/client.rb
CHANGED
@@ -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")
|
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'] =
|
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
|
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:,
|
194
|
-
req = {
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
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
|
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:,
|
215
|
-
req = {
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
req['
|
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.
|
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.
|
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.
|
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.
|
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.
|
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
|
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.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
|
+
date: 2020-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|