Sha256: 40c0696c95b6cd2fcd456dd1f6219198e4834410da8c87531bc31c10216d27f8

Contents?: true

Size: 983 Bytes

Versions: 9

Compression:

Stored size: 983 Bytes

Contents

# {
#   "scan": {
#     "field": "",
#     "pattern": "",
#     "target": ""
#   }
# }
module Anschel
  class Filter
    def scan conf, log
      field   = conf.delete :field
      pattern = Regexp.new conf.delete(:pattern)
      target  = conf.delete :target

      raise 'Missing required "field" for "scan" filter' if field.nil?
      raise 'Missing required "pattern" for "scan" filter' if pattern.nil?
      raise 'Missing required "target" for "convert" filter' if target.nil?

      field  = field.to_sym
      target = target.to_sym


      log.debug event: 'compiled-filter', filter: 'scan', \
        field: field, pattern: pattern, target: target

      lambda do |event|
        return event unless event.has_key? field
        results = event[field].scan(pattern).flatten.uniq

        if results.empty?
          event
        else
          event[target] ||= []
          event[target]  += results
          filtered event, conf
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
anschel-0.6.1 lib/anschel/filter/scan.rb
anschel-0.6.0 lib/anschel/filter/scan.rb
anschel-0.5.0 lib/anschel/filter/scan.rb
anschel-0.4.1 lib/anschel/filter/scan.rb
anschel-0.4.0 lib/anschel/filter/scan.rb
anschel-0.3.2 lib/anschel/filter/scan.rb
anschel-0.3.1 lib/anschel/filter/scan.rb
anschel-0.3.0 lib/anschel/filter/scan.rb
anschel-0.2.0 lib/anschel/filter/scan.rb