Class: Fluent::WootheeFilter
- Inherits:
-
Filter
- Object
- Filter
- Fluent::WootheeFilter
- Defined in:
- lib/fluent/plugin/filter_woothee.rb
Instance Attribute Summary collapse
-
#mode ⇒ Object
Returns the value of attribute mode.
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #fast_crawler_filter_stream(tag, es) ⇒ Object
- #filter_stream(tag, es) ⇒ Object
-
#initialize ⇒ WootheeFilter
constructor
A new instance of WootheeFilter.
- #normal_filter_stream(tag, es) ⇒ Object
Constructor Details
#initialize ⇒ WootheeFilter
Returns a new instance of WootheeFilter.
25 26 27 28 |
# File 'lib/fluent/plugin/filter_woothee.rb', line 25 def initialize super require 'woothee' end |
Instance Attribute Details
#mode ⇒ Object
Returns the value of attribute mode.
15 16 17 |
# File 'lib/fluent/plugin/filter_woothee.rb', line 15 def mode @mode end |
Instance Method Details
#configure(conf) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fluent/plugin/filter_woothee.rb', line 30 def configure(conf) super if conf['type'] == 'woothee_fast_crawler_filter' or @fast_crawler_filter_mode @fast_crawler_filter_mode = true if @filter_categories.size > 0 or @drop_categories.size > 0 or @merge_agent_info raise Fluent::ConfigError, "fast_crawler_filter cannot be specified with filter/drop/merge options" end return end if @filter_categories.size > 0 and @drop_categories.size > 0 raise Fluent::ConfigError, "both of 'filter' and 'drop' categories specified" elsif @filter_categories.size > 0 unless @filter_categories.reduce(true){|r,i| r and Woothee::CATEGORY_LIST.include?(i)} raise Fluent::ConfigError, "filter_categories has invalid category name" end @mode = :filter elsif @drop_categories.size > 0 unless @drop_categories.reduce(true){|r,i| r and Woothee::CATEGORY_LIST.include?(i)} raise Fluent::ConfigError, "drop_categories has invalid category name" end @mode = :drop else @mode = :through end if @mode == :through and not @merge_agent_info raise Fluent::ConfigError, "configured not to do nothing (not to do either filter/drop nor addition of parser result)" end end |
#fast_crawler_filter_stream(tag, es) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/fluent/plugin/filter_woothee.rb', line 64 def fast_crawler_filter_stream(tag, es) new_es = Fluent::MultiEventStream.new es.each do |time,record| unless Woothee.is_crawler(record[@key_name] || '') new_es.add(time, record.dup) end end new_es end |
#filter_stream(tag, es) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/fluent/plugin/filter_woothee.rb', line 100 def filter_stream(tag, es) if @fast_crawler_filter_mode fast_crawler_filter_stream(tag, es) else normal_filter_stream(tag, es) end end |
#normal_filter_stream(tag, es) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/fluent/plugin/filter_woothee.rb', line 75 def normal_filter_stream(tag, es) new_es = Fluent::MultiEventStream.new es.each do |time,record| parsed = Woothee.parse(record[@key_name] || '') category = parsed[Woothee::ATTRIBUTE_CATEGORY] next if @mode == :filter and not @filter_categories.include?(category) next if @mode == :drop and @drop_categories.include?(category) if @merge_agent_info record = record.merge({ @out_key_name => parsed[Woothee::ATTRIBUTE_NAME], @out_key_category => parsed[Woothee::ATTRIBUTE_CATEGORY].to_s, @out_key_os => parsed[Woothee::ATTRIBUTE_OS] }) record[@out_key_os_version] = parsed[Woothee::ATTRIBUTE_OS_VERSION] if @out_key_os_version record[@out_key_version] = parsed[Woothee::ATTRIBUTE_VERSION] if @out_key_version record[@out_key_vendor] = parsed[Woothee::ATTRIBUTE_VENDOR] if @out_key_vendor end new_es.add(time, record.dup) end new_es end |