16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/logstash/filters/api_hammer_request.rb', line 16
def filter(event)
col = /[\e\[\dm]*/.source
human_request = [/\A/, /[<>]/, /\s/, /\d+/, / : /, /\w+/, / /, /[^\e]+/, / @ /, /[^\e]+/, /\z/].map(&:source).join(col)
event.cancel if event[@source] =~ /#{human_request}/
begin
parsed_message = JSON.parse(event[@source])
if @consume
bound = parsed_message['bound']
dir = role == 'inbound' ? '<' : role == 'outbound' ? '>' : '*'
status = parsed_message['response'] && parsed_message['response']['status']
request_method = parsed_message['request'] && parsed_message['request']['method']
request_uri = parsed_message['request'] && parsed_message['request']['uri']
now_s = Time.now.strftime('%Y-%m-%d %H:%M:%S %Z')
event[@source] = "#{dir} #{status} : #{request_method} #{request_uri} @ #{now_s}"
end
rescue JSON::ParserError
nil
end
if parsed_message
if parsed_message.is_a?(Hash)
event.to_hash.update(parsed_message)
if parsed_message['processing'].is_a?(Hash) && parsed_message['processing']['began_at'].is_a?(Integer)
event['@timestamp'] = Time.at(parsed_message['processing']['began_at']).utc
end
else
event['parsed_message'] = parsed_message
end
end
end
|