Class: LogStash::Outputs::Http
- Defined in:
- lib/logstash/outputs/http.rb
Constant Summary
Constants included from Config::Mixin
Instance Attribute Summary
Attributes included from Config::Mixin
Attributes inherited from Plugin
Instance Method Summary collapse
Methods inherited from Base
#handle, #handle_worker, #initialize, #worker_setup, #workers_not_supported
Methods included from Config::Mixin
Methods inherited from Plugin
#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #teardown, #terminating?, #to_s
Constructor Details
This class inherits a constructor from LogStash::Outputs::Base
Instance Method Details
#encode(hash) ⇒ Object
def receive
137 138 139 140 141 |
# File 'lib/logstash/outputs/http.rb', line 137 def encode(hash) return hash.collect do |key, value| CGI.escape(key) + "=" + CGI.escape(value) end.join("&") end |
#receive(event) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/logstash/outputs/http.rb', line 85 def receive(event) return unless output?(event) if @mapping evt = Hash.new @mapping.each do |k,v| evt[k] = event.sprintf(v) end else evt = event.to_hash end case @http_method when "put" request = @agent.put(event.sprintf(@url)) when "post" request = @agent.post(event.sprintf(@url)) else @logger.error("Unknown verb:", :verb => @http_method) end if @headers @headers.each do |k,v| request.headers[k] = event.sprintf(v) end end request["Content-Type"] = @content_type begin if @format == "json" request.body = evt.to_json elsif @format == "message" request.body = event.sprintf(@message) else request.body = encode(evt) end #puts "#{request.port} / #{request.protocol}" #puts request #puts #puts request.body response = @agent.execute(request) # Consume body to let this connection be reused rbody = "" response.read_body { |c| rbody << c } #puts rbody rescue Exception => e @logger.warn("Unhandled exception", :request => request, :response => response, :exception => e, :stacktrace => e.backtrace) end end |
#register ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/logstash/outputs/http.rb', line 59 def register require "ftw" require "uri" @agent = FTW::Agent.new # TODO(sissel): SSL verify mode? if @content_type.nil? case @format when "form" ; @content_type = "application/x-www-form-urlencoded" when "json" ; @content_type = "application/json" end end if @format == "message" if @message.nil? raise "message must be set if message format is used" end if @content_type.nil? raise "content_type must be set if message format is used" end unless @mapping.nil? @logger.warn "mapping is not supported and will be ignored if message format is used" end end end |