115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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
|
# File 'lib/logstash/outputs/http_auth.rb', line 115
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
.each do |k,v|
request.[k] = event.sprintf(v)
end
end
request["Content-Type"] = @content_type
(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
|