Class: Fluent::AssertOutput

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

Instance Method Summary collapse

Constructor Details

#initializeAssertOutput



13
14
15
# File 'lib/fluent/plugin/out_assert.rb', line 13

def initialize
  super
end

Instance Method Details

#configure(conf) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fluent/plugin/out_assert.rb', line 17

def configure(conf)
  super

  if @assert_fail_tag_prefix
    @assert_fail_tag_prefix_string = @assert_fail_tag_prefix + '.'
  end

  if @assert_pass_remove_tag_prefix
    assert_pass_remove_tag_prefix_string = @assert_pass_remove_tag_prefix + '.'
    @removed_length = assert_pass_remove_tag_prefix_string.length
  end

  @tests = conf.elements.select { |element|
    element.name == "test"
  }.each do |element|
    element.keys.each do |k|
      element[k]
    end
  end

  if @tests.empty?
    raise Fluent::ConfigError, "test elements is empty."
  end
end

#emit(tag, es, chain) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fluent/plugin/out_assert.rb', line 42

def emit(tag, es, chain)
  es.each do |time, record|
    chain.next

    tag =
      if assert!(record)
        tag[@removed_length..-1]
      else
        @assert_fail_tag_prefix_string + tag
      end

    Fluent::Engine.emit(tag, time, record)
  end
end