class LogStash::Filters::Hex

Public Instance Methods

filter(event) click to toggle source
# 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
register() click to toggle source
# File lib/logstash/filters/hex.rb, line 16
def register
end