Class: Fluent::Plugin::SstpOutput

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

Instance Method Summary collapse

Instance Method Details

#build_message(tag, time, record) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fluent/plugin/out_sstp.rb', line 32

def build_message(tag, time, record)
  # Generate the script content using the template
  rendered_script = @script_erb.result(binding)
  
  # Build the complete SSTP message
  ERB.new("<%= @request_method %> <%= @request_version %>\nSender: <%= @sender %>\nOption: <%= @option %>\nScript: <%= rendered_script %>\nCharset: UTF-8\n  EOS\n  ).result(binding).gsub(\"\\n\", \"\\r\\n\")\nend\n"

#configure(conf) ⇒ Object

Raises:

  • (Fluent::ConfigError)


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

def configure(conf)
  super
  @script_erb = ERB.new(@script_template)
  raise Fluent::ConfigError, "Unsupported request_method: #{@request_method}" unless @request_method == 'NOTIFY'
end

#post(message) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/fluent/plugin/out_sstp.rb', line 47

def post(message)
  begin
    socket = TCPSocket.new(@sstp_server, @sstp_port)
    socket.puts(message)
    socket.close
  rescue => e
    log.warn "Failed to send SSTP message: #{e.class}, '#{e.message}'"
  end
  message
end

#process(tag, es) ⇒ Object



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

def process(tag, es)
  es.each do |time, record|
    message = build_message(tag, time, record)
    post(message)
  end
end