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
|
# File 'lib/logstash/filters/hex.rb', line 19
def filter(event)
@fields.each do |field|
next if field.nil?
value = event.get(field)
next if value.nil?
case @action
when "encode"
if @type == "string"
event.set(field, value.unpack("H*").first)
else
event.set(field, value.to_i.to_s(16))
end
when "decode"
if value =~ /^[a-f0-9]+$/i
if @type == "string"
event.set(field, [value].pack("H*"))
else
event.set(field, value.to_i(16).to_s)
end
else
end
end
end
filter_matched(event)
end
|