37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/logstash/filters/http.rb', line 37
def filter(event)
url_for_event = event.sprintf(@url)
= sprintf_object(event, @headers)
if body_format == "json"
["content-type"] = "application/json"
else
["content-type"] = "text/plain"
end
query_sprintfed = sprintf_object(event, @query)
body_sprintfed = sprintf_object(event, @body)
if @body_format == "json" && body_sprintfed.kind_of?(Enumerable)
body_sprintfed = LogStash::Json.dump(body_sprintfed)
end
options = { :headers => , :query => query_sprintfed, :body => body_sprintfed }
@logger.debug? && @logger.debug('processing request', :url => url_for_event, :headers => , :query => query_sprintfed)
client_error = nil
begin
code, , response_body = request_http(@verb, url_for_event, options)
rescue => e
client_error = e
end
if client_error
@logger.error('error during HTTP request',
:url => url_for_event, :body => body_sprintfed,
:client_error => client_error.message)
@tag_on_request_failure.each { |tag| event.tag(tag) }
elsif !code.between?(200, 299)
@logger.error('error during HTTP request',
:url => url_for_event, :code => code,
:response => response_body)
@tag_on_request_failure.each { |tag| event.tag(tag) }
else
@logger.debug? && @logger.debug('success received',
:code => code, :body => response_body)
process_response(response_body, , event)
filter_matched(event)
end
end
|