Class: LogStash::Outputs::HttpAuth
- Inherits:
-
Base
- Object
- Base
- LogStash::Outputs::HttpAuth
- Defined in:
- lib/logstash/outputs/http_auth.rb
Instance Method Summary collapse
Instance Method Details
#receive(event) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/logstash/outputs/http_auth.rb', line 139 def receive(event) return unless output?(event) sign_in() if @sign_in if @mapping evt = Hash.new @mapping.each do |k,v| evt[k] = event.sprintf(v) end else evt = event.to_hash end @url = URI::HTTP.build({:host => @host, :port=> @port, :path => @path}) if @url.nil? 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 set_header(request) begin if @format == "json" request.body = evt.to_json elsif @format == "message" request.body = event.sprintf(@message) else request.body = encode(evt) end response = @agent.execute(request) @signed_in = status_success?(response.status) @logger.warn("Response Status #{response.status} for request #{@http_method} to #{@url}") if !status_success?(response.status) rescue Exception => e @logger.warn("Unhandled exception", :request => request, :response => response, :exception => e, :stacktrace => e.backtrace) end end |
#register ⇒ Object
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 136 |
# File 'lib/logstash/outputs/http_auth.rb', line 97 def register require "ftw" require "uri" @agent = FTW::Agent.new 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 if !@verify_ssl # User requests that SSL certificates are not validated, so let's # override the certificate verification class << @agent def certificate_verify(host, port, verified, context) return true end end end @agent.configuration[FTW::Agent::SSL_VERSION] = @ssl_version @signed_in = false @csrf_token = nil @cookies = nil end |