Class: Kapacitor::Client
- Inherits:
-
Object
- Object
- Kapacitor::Client
- Defined in:
- lib/kapacitor/client.rb
Instance Attribute Summary collapse
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #define_task(id:, template_id: nil, type: nil, dbrps:, script: nil, status: 'enabled', vars: nil) ⇒ Object
- #define_template(id:, type:, script:) ⇒ Object
- #delete_task(id:) ⇒ Object
- #delete_template(id:) ⇒ Object
-
#initialize(host: 'localhost:9092', version: 'v1') ⇒ Client
constructor
A new instance of Client.
- #tasks ⇒ Object
- #templates ⇒ Object
- #update_task(id:, template_id: nil, type: nil, dbrps: nil, script: nil, status: nil, vars: nil) ⇒ Object
- #update_template(id:, type: nil, script: nil) ⇒ Object
Constructor Details
#initialize(host: 'localhost:9092', version: 'v1') ⇒ Client
Returns a new instance of Client.
14 15 16 17 |
# File 'lib/kapacitor/client.rb', line 14 def initialize(host: 'localhost:9092', version: 'v1') @uri = URI.parse("http://#{host}/kapacitor/#{version}") @http = Net::HTTP.new(@uri.host, @uri.port) end |
Instance Attribute Details
#http ⇒ Object (readonly)
Returns the value of attribute http.
12 13 14 |
# File 'lib/kapacitor/client.rb', line 12 def http @http end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
12 13 14 |
# File 'lib/kapacitor/client.rb', line 12 def uri @uri end |
Instance Method Details
#define_task(id:, template_id: nil, type: nil, dbrps:, script: nil, status: 'enabled', vars: nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/kapacitor/client.rb', line 45 def define_task(id:, template_id: nil, type: nil, dbrps: , script: nil, status: 'enabled', vars: nil) if (template_id.nil? and type.nil? and script.nil?) or (template_id and (type or script)) raise ArgumentError, "Must specify either a Template ID or a script and type" elsif template_id.nil? and (type.nil? or script.nil?) raise ArgumentError, "Must specify both task type and script when not using a Template ID" end req = { 'id' => id, 'dbrps' => dbrps, 'status' => status } if template_id req['template-id'] = template_id else req['type'] = type req['script'] = script end req['vars'] = vars if vars api_post('/tasks', req) end |
#define_template(id:, type:, script:) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/kapacitor/client.rb', line 19 def define_template(id:, type:, script:) req = { 'id' => id, 'type' => type, 'script' => script } api_post('/templates', req) end |
#delete_task(id:) ⇒ Object
82 83 84 |
# File 'lib/kapacitor/client.rb', line 82 def delete_task(id:) api_delete("/tasks/#{id}") end |
#delete_template(id:) ⇒ Object
37 38 39 |
# File 'lib/kapacitor/client.rb', line 37 def delete_template(id:) api_delete("/templates/#{id}") end |
#tasks ⇒ Object
86 87 88 |
# File 'lib/kapacitor/client.rb', line 86 def tasks api_get('/tasks')['tasks'] end |
#templates ⇒ Object
41 42 43 |
# File 'lib/kapacitor/client.rb', line 41 def templates api_get('/templates')['templates'] end |
#update_task(id:, template_id: nil, type: nil, dbrps: nil, script: nil, status: nil, vars: nil) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/kapacitor/client.rb', line 70 def update_task(id:, template_id: nil, type: nil, dbrps: nil, script: nil, status: nil, vars: nil) req = {} req['template-id'] = template_id if template_id req['type'] = type if type req['dbrps'] = dbrps if dbrps req['script'] = script if script req['status'] = status if status req['vars'] = vars if vars api_patch("/tasks/#{id}", req) unless req.empty? end |
#update_template(id:, type: nil, script: nil) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/kapacitor/client.rb', line 29 def update_template(id:, type: nil, script: nil) req = {} req['type'] = type if type req['script'] = script if script api_patch("/templates/#{id}", req) unless req.empty? end |