Class: Reacter::HttpAdapter
- Defined in:
- lib/reacter/adapters/http.rb
Defined Under Namespace
Classes: HttpHandler
Instance Attribute Summary
Attributes inherited from Adapter
Instance Method Summary collapse
- #connect(args = {}) ⇒ Object
- #disconnect ⇒ Object
- #poll(&block) ⇒ Object
- #send(message, format = nil) ⇒ Object
Methods inherited from Adapter
create, #disable, #enabled?, #initialize
Constructor Details
This class inherits a constructor from Reacter::Adapter
Instance Method Details
#connect(args = {}) ⇒ Object
42 43 44 45 |
# File 'lib/reacter/adapters/http.rb', line 42 def connect(args={}) @addr = @config.get(:address, '0.0.0.0') @port = @config.get(:port, 8080).to_i end |
#disconnect ⇒ Object
86 87 88 |
# File 'lib/reacter/adapters/http.rb', line 86 def disconnect() raise AdapterConnectionClosed end |
#poll(&block) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/reacter/adapters/http.rb', line 58 def poll(&block) @server = EM.start_server(@addr, @port, HttpHandler, proc{|data| if data case data[:method] when :GET x, op, source, metric, value = data[:path].split('/') if op == 'observe' or op.empty? = Message.parse([{ :source => (source || data[:query]['source']), :metric => (metric || data[:query]['metric']), :value => (value || data[:query]['value'].to_f), :time => (data[:query]['time'] || (Time.now.to_i * 1000)), :attributes => data[:query].reject{|k,v| %w{source metric value time}.include?(k) } }.compact]) end when :POST, :PUT = Message.parse(data[:body].gsub("\n",'')) end end block.call() if and not .empty? }) end |
#send(message, format = nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/reacter/adapters/http.rb', line 47 def send(, format=nil) # TODO: implement this for relay support # support: method # output format # destination URI (host port path querystring) # HTTPS # authentication (basic, SSL client cert) # timeout # end |