Class: LogStash::Filters::Hash_select

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/filters/hash_select.rb

Instance Method Summary collapse

Instance Method Details

#filter(event) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/logstash/filters/hash_select.rb', line 21

def filter(event)
  field = event.get(@hash_field)
  if field.is_a?(Hash)
    before = field.size
    unless @include_keys.empty?
      field = field.select { |k,v| @include_keys.include?(k) }
    end
    unless @exclude_keys.empty?
      field = field.select { |k,v| ! @exclude_keys.include?(k) }
    end
    event.set(@hash_field, field) if field.size < before
  end

  filter_matched(event)
end

#registerObject



14
15
16
17
18
# File 'lib/logstash/filters/hash_select.rb', line 14

def register
  # Use faster include method
  @include_keys = Set[*@include_keys]
  @exclude_keys = Set[*@exclude_keys]
end