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
80
81
82
83
84
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
|
# File 'lib/logstash/filters/varnishlog.rb', line 40
def filter(event)
items = event.get("[message]").split("\n")
if request=/\*+\s+<<\s+(?<type>\w+)\s+>>\s+/.match(items[0])
event.set("type", request['type'].downcase)
end
items = items.grepv(blacklist_sections.join("|")) if blacklist_sections.any?
timestamps = items.grep(/Timestamp/)
timestamps.each do |timestamp|
if match = /-\s+Timestamp\s+(?<step>.*): (?<time_a>.*) (?<time_b>.*) (?<time_c>.*)/.match(timestamp)
event.set(normalize_fields("timestamp_" + match['step'] ), match['time_a'])
event.set(normalize_fields("timestamp_" + match['step'] + "_raw"), match['time_a'] + " " + match['time_b'] + " " + match['time_c'])
end
end
account = items.grep(/(Be|Req)Acct/)
account.each do |acct|
if acct_match = /-\s+(Be|Req)Acct\s+(?<size_a>\d+)\s+(?<size_b>\d+)\s+(?<size_c>\d+)\s+(?<size_d>\d+)\s+(?<size_e>\d+)\s+(?<size_f>\d+)/.match(acct)
event.set("bytes", acct_match['size_e'])
end
end
vcl_log = items.grep(/VCL_Log/)
log_lines = []
vcl_log.each_with_index do |log, index|
if match = /-\s+VCL_Log\s+(?<log_line>.*)/.match(log)
log_lines.push(match['log_line'])
end
if index == log_lines.size - 1
event.set(normalize_fields("VCL_Log"), log_lines)
end
end
= items.grep(/(Be)?([rR]eq|[rR]esp)Header/)
.each do ||
if match = /-+\s+(Be)?([rR]eq|[rR]esp)Header\s+(?<header_name>.*?): (?<header_value>.*)/.match()
event.set(normalize_fields(match['header_name']), match['header_value'])
end
end
if method_match = /-+\s+(Be)?([rR]eq|[rR]esp)Method\s+(?<method>.*)/.match(items.grep(/(Be)?([rR]eq|[rR]esp)Method/)[0])
event.set("http_method", method_match['method'])
end
if url_match = /-+\s+(Be)?([rR]eq|[rR]esp)URL\s+(?<url>\/.*)/.match(items.grep(/(Be)?([rR]eq|[rR]esp)URL/)[0])
event.set("url", url_match['url'])
end
if protocol_match = /-+\s+(Be)?([rR]eq|[rR]esp)Protocol\s+(?<protocol>.*)/.match(items.grep(/(Be)?([rR]eq|[rR]esp)Protocol/)[0])
event.set("protocol", protocol_match['protocol'])
end
if error_match = /-+\s+FetchError\s+(?<error>.*)/.match(items.grep(/FetchError/)[0])
event.set("FetchError", error_match['error'])
end
status_match = items.grep(/(Be)?([rR]eq|[rR]esp)Status/)
states = []
status_match.each_with_index do |status, index|
if match = /-+\s+(Be)?([rR]eq|[rR]esp)Status\s+(?<status>.*)/.match(status)
states.push(match['status'].to_i)
end
if index == status_match.size - 1
event.set("http-rc", states)
end
end
response_reason = items.grep(/(Be)?([rR]eq|[rR]esp)Reason/)
reasons = []
response_reason.each_with_index do |reason, index|
if match = /-+\s+(Be)?([rR]eq|[rR]esp)Reason\s+(?<reason>.*)/.match(reason)
reasons.push(match['reason'])
end
if index == response_reason.size - 1
event.set("reason", reasons)
end
end
if @message
event.set("message", @message)
end
filter_matched(event)
end
|