Class: Fluent::ForwardSslOutput

Inherits:
ForwardOutput
  • Object
show all
Defined in:
lib/flydata/fluent-plugins/out_forward_ssl.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object


7
8
9
10
11
12
13
14
15
# File 'lib/flydata/fluent-plugins/out_forward_ssl.rb', line 7

def configure(conf)
  super
  conf.elements.each do |e|
    if e['ssl_port']
      node = @nodes.find {|n| n.host == e['host'] }
      node.set_ssl_port(e['ssl_port']) if node
    end
  end
end

#connect(node) ⇒ Object


48
49
50
51
52
# File 'lib/flydata/fluent-plugins/out_forward_ssl.rb', line 48

def connect(node)
  tcp_sock = TCPSocket.new(node.resolved_host, node.port)
  set_tcp_sock_opts(tcp_sock)
  tcp_sock
end

#connect_ssl(node) ⇒ Object


54
55
56
57
58
59
60
61
62
# File 'lib/flydata/fluent-plugins/out_forward_ssl.rb', line 54

def connect_ssl(node)
  tcp_sock = TCPSocket.new(node.resolved_host, node.ssl_port)
  set_tcp_sock_opts(tcp_sock)
  ssl_ctx = ssl_ctx_with_verification
  ssl_sock = OpenSSL::SSL::SSLSocket.new(tcp_sock, ssl_ctx)
  ssl_sock.sync_close = true
  ssl_sock.connect
  ssl_sock
end

#send_data(node, tag, chunk) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/flydata/fluent-plugins/out_forward_ssl.rb', line 16

def send_data(node, tag, chunk)
  sock =  connect_ssl(node)
  begin
    # Copy of ForwardOutput send_data
    # beginArray(2)
    sock.write FORWARD_HEADER

    # writeRaw(tag)
    sock.write tag.to_msgpack  # tag

    # beginRaw(size)
    sz = chunk.size
    #if sz < 32
    #  # FixRaw
    #  sock.write [0xa0 | sz].pack('C')
    #elsif sz < 65536
    #  # raw 16
    #  sock.write [0xda, sz].pack('Cn')
    #else
      # raw 32
      sock.write [0xdb, sz].pack('CN')
    #end

    # writeRawBody(packed_es)
    chunk.write_to(sock)

    node.heartbeat(false)
  ensure
    sock.close
  end
end