Class: Fluent::InlineClassifierOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_inline_classifier.rb

Defined Under Namespace

Classes: Classifier, RangeClassifier

Constant Summary collapse

CLASSIFIERS =
{'range' => RangeClassifier}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInlineClassifierOutput

Returns a new instance of InlineClassifierOutput.



63
64
65
66
# File 'lib/fluent/plugin/out_inline_classifier.rb', line 63

def initialize
  super
  @classifiers = []
end

Instance Attribute Details

#classifiersObject

Returns the value of attribute classifiers.



61
62
63
# File 'lib/fluent/plugin/out_inline_classifier.rb', line 61

def classifiers
  @classifiers
end

Instance Method Details

#configure(conf) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/fluent/plugin/out_inline_classifier.rb', line 68

def configure(conf)
  super
  conf.elements.select {|element|
    element.name == 'rule'
  }.each {|element|
    klass = CLASSIFIERS[element['type']]
    key = element['key']
    element.has_key? 'store'  # To suppress unused configuration warning
    store = element.fetch('store', key + '_class')

    rules = []
    element.keys.each {|key|
      if m = /^class(\d+)$/.match(key)
        rules[m[1].to_i] = element[key].split(' ', 2)
      end
    }

    @classifiers << klass.new(key, store, rules.compact)
  }
end

#emit(tag, es, chain) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/fluent/plugin/out_inline_classifier.rb', line 98

def emit(tag, es, chain)
  tag = strip_tag_prefix(tag)
  tag = tag.length > 0 ? [@add_prefix, tag].join('.') : @add_prefix

  es.each {|time, record|
    @classifiers.each {|classifier|
      classifier.run!(record)
    }
    Fluent::Engine.emit(tag, time, record)
  }

  chain.next
end

#strip_tag_prefix(tag) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/fluent/plugin/out_inline_classifier.rb', line 89

def strip_tag_prefix(tag)
  if tag.start_with?(@remove_prefix)
    head = tag[@remove_prefix.length]
    return '' if head == nil
    return tag[@remove_prefix.length+1..-1] if head == '.'
  end
  return tag
end