./lib/le/host/https/tcp.rb in le-1.9.2 vs ./lib/le/host/https/tcp.rb in le-2.0
- old
+ new
@@ -5,64 +5,55 @@
# Logentries Ruby monitoring agent
# Copyright 2010,2011 Logentries, Jlizard
# Mark Lacomber <marklacomber@gmail.com>
#
-require 'uri'
+require 'socket'
+require 'openssl'
module Le
module Host
class HTTPS
+
class TCPSOCKET
- attr_accessor :sock, :conn, :key, :location
- def initialize(key, location)
+ attr_accessor :conn, :token
+ def initialize(token)
- @key = key
- @location = URI::encode(location)
+ @token = token
begin
- createSocket(@key, @location)
- rescue OpenSSL::SSL::SSLError, TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT, EOFError => e
- $stderr.puts "WARNING: #{e.class} creating the connection to Logentries. #{e.message}"
+ createSocket()
+ rescue TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT, EOFError => e
+ $stderr.puts "WARNING: #{e.class} Could not create the connection to Logentries. #{e.message}"
end
end
- def createSocket(key, location)
-
- addr = sprintf('/%s/hosts/%s/?realtime=1', key, location)
+ def createSocket()
# Open the TCP connection to the Logentries Server
- @sock = TCPSocket.new('api.logentries.com', 443)
+ @conn = TCPSocket.new('api.logentries.com', 10000)
- @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\r\n", addr)
- @conn.write(request)
-
end
def deliver(message)
if @conn == nil
begin
- createSocket(@key, @location)
- rescue OpenSSL::SSL::SSLError, TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT, EOFError => e
+ createSocket()
+ rescue TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT, EOFError => e
$stderr.puts "WARNING: #{e.class} Could not write log. No connection to Logentries #{e.message}"
return
end
end
# Sends the log to the Logentries Server
begin
- @conn.print(message + "\r\n")
- rescue OpenSSL::SSL::SSLError, TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ENOTCONN, Errno::ECONNRESET, Errno::ETIMEDOUT, EOFError => e
- $stderr.puts "WARNING: #{e.class} sending log #{e.message}"
+ @conn.puts(@token + message)
+ rescue TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ENOTCONN, Errno::ECONNRESET, Errno::ETIMEDOUT, EOFError => e
+ $stderr.puts "WARNING: #{e.class} Could not send log to Logentries #{e.message}"
begin
- createSocket(@key, @location)
- rescue OpenSSL::SSL::SSLError, TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT, EOFError => e
- $stderr.puts "WARNING: #{e.class} creating the connection to Logentries. #{e.message}"
+ createSocket()
+ rescue TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT, EOFError => e
+ $stderr.puts "WARNING: #{e.class} Could not create the connection to Logentries. #{e.message}"
end
end
end
end