Sha256: 78b11ab643192f386878eb9ab88f0b77d3cc101e43a1634809cc1189ae00f78c

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module Le
  module Host
    class HTTPS

      class TCPSOCKET

	attr_accessor :sock, :conn
	def initialize(key, location)

          # Create the unique address comprising of user-key and location of file on logentries server
	  addr = sprintf('/%s/hosts/%s/?realtime=1', key, location)	  
	
          # Open the TCP connection to the Logentries Server
	  @sock = TCPSocket.new('api.logentries.com', 443)

	  @conn = OpenSSL::SSL::SSLSocket.new(@sock, OpenSSL::SSL::SSLContext.new())
	  @conn.sync_close = true
          @conn.connect

          # Set up connection with Logentries API to receive messages in chunks, i.e, logs
	  request = sprintf("PUT %s HTTP/1.1\r\n", addr)
          @conn.print(request)
	  @conn.print("Accept-Encoding: identity\r\n")
	  @conn.print("Transfer_Encoding: chunked\r\n\r\n")
	end
	
	def deliver(message)

          # Sends the log to the Logentries Server
          begin
	    @conn.print(message + "\r\n")
	  rescue OpenSSL::SSL::SSLError, TimeoutError, Errno::ECONNRESET, EOFError => e
	    $stderr.puts "WARNING: #{e.class} sending log #{message}"
	  end
        end
	
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
le-1.4 ./lib1.2backup/le/host/https/tcp.rb