Class: Fluent::SstpOutput

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

Instance Method Summary collapse

Constructor Details

#initializeSstpOutput

Returns a new instance of SstpOutput.



6
7
8
# File 'lib/fluent/plugin/out_sstp.rb', line 6

def initialize
  super
end

Instance Method Details

#build_message(tag, time, record) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/fluent/plugin/out_sstp.rb', line 41

def build_message tag, time, record
  script = @script.result(binding)
  ERB.new("<%= @request_method %> <%= @request_version %>\nSender: <%= @sender %>\nScript: <%= script %>\nCharset: UTF-8\n    EOS\n  ).result(binding).gsub(\"\\n\", \"\\r\\n\")\nend\n"

#configure(conf) ⇒ Object



17
18
19
20
21
22
# File 'lib/fluent/plugin/out_sstp.rb', line 17

def configure(conf)
  super

  @script = ERB.new(@script_template)
  raise "Unsupport post_type: #{@request_method}" unless @request_method == 'NOTIFY'
end

#emit(tag, es, chain) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/fluent/plugin/out_sstp.rb', line 32

def emit(tag, es, chain)
  es.each {|time,record|
    message = build_message(tag, time, record)
    post message
  }

  chain.next
end

#post(message) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fluent/plugin/out_sstp.rb', line 52

def post(message)
  begin
    IO.popen("nc '#{@sstp_server}' '#{@sstp_port}'", 'w') do |io|
      io.puts message
    end
  rescue IOError, EOFError, SystemCallError
    # server didn't respond
    $log.warn "raises exception: #{$!.class}, '#{$!.message}'"
  end

  message
end

#shutdownObject



28
29
30
# File 'lib/fluent/plugin/out_sstp.rb', line 28

def shutdown
  super
end

#startObject



24
25
26
# File 'lib/fluent/plugin/out_sstp.rb', line 24

def start
  super
end