le 2.2 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/LE.gemspec +1 -1
  2. data/lib/le/host/http.rb +132 -116
  3. metadata +4 -3
data/LE.gemspec CHANGED
@@ -3,7 +3,7 @@ require File.expand_path(File.join(dir, 'lib', 'le'))
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "le"
6
- s.version = "2.2"
6
+ s.version = "2.2.1"
7
7
  s.date = Time.now
8
8
  s.summary = "Logentries plugin"
9
9
  s.description =<<EOD
data/lib/le/host/http.rb CHANGED
@@ -6,10 +6,10 @@ require 'uri'
6
6
  module Le
7
7
  module Host
8
8
  class HTTP
9
- API_SERVER = 'api.logentries.com'
10
- API_PORT = 10000
11
- API_SSL_PORT = 20000
12
- API_CERT = '-----BEGIN CERTIFICATE-----
9
+ API_SERVER = 'api.logentries.com'
10
+ API_PORT = 10000
11
+ API_SSL_PORT = 20000
12
+ API_CERT = '-----BEGIN CERTIFICATE-----
13
13
  MIIFSjCCBDKgAwIBAgIDBQMSMA0GCSqGSIb3DQEBBQUAMGExCzAJBgNVBAYTAlVT
14
14
  MRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMR0wGwYDVQQLExREb21haW4gVmFsaWRh
15
15
  dGVkIFNTTDEbMBkGA1UEAxMSR2VvVHJ1c3QgRFYgU1NMIENBMB4XDTEyMDkxMDE5
@@ -45,132 +45,148 @@ kAuBvDPPm+C0/M4RLYs=
45
45
  attr_accessor :token, :queue, :started, :thread, :conn, :local, :debug, :ssl
46
46
 
47
47
  def initialize(token, local, debug, ssl)
48
- if defined?(Rails)
49
- @logger_console = Logger.new("log/#{Rails.env}.log")
50
- else
51
- @logger_console = Logger.new(STDOUT)
52
- end
53
- @token = token
54
- @local = local
55
- @debug = debug
56
- @ssl = ssl
57
- @queue = Queue.new
58
- @started = false
59
- @thread = nil
60
-
61
- if @debug then
62
- self.init_debug
63
- end
48
+ if defined?(Rails)
49
+ @logger_console = Logger.new("log/#{Rails.env}.log")
50
+ else
51
+ @logger_console = Logger.new(STDOUT)
52
+ end
53
+ @token = token
54
+ @local = local
55
+ @debug = debug
56
+ @ssl = ssl
57
+ @queue = Queue.new
58
+ @started = false
59
+ @thread = nil
60
+
61
+ if @debug
62
+ self.init_debug
63
+ end
64
64
  end
65
65
 
66
- def init_debug
67
- filePath = "logentriesGem.log"
68
- if File.exist?('log/')
69
- filePath = "log/logentriesGem.log"
70
- end
71
- @debug_logger = Logger.new(filePath)
72
- end
66
+ def init_debug
67
+ filePath = "logentriesGem.log"
68
+ if File.exist?('log/')
69
+ filePath = "log/logentriesGem.log"
70
+ end
71
+ @debug_logger = Logger.new(filePath)
72
+ end
73
73
 
74
- def dbg(message)
75
- if @debug then
76
- @debug_logger.add(Logger::Severity::DEBUG,message)
77
- end
78
- end
74
+ def dbg(message)
75
+ if @debug
76
+ @debug_logger.add(Logger::Severity::DEBUG, message)
77
+ end
78
+ end
79
79
 
80
80
  def write(message)
81
- if @local then
82
- @logger_console.add(Logger::Severity::UNKNOWN,message)
83
- end
81
+ if @local
82
+ @logger_console.add(Logger::Severity::UNKNOWN, message)
83
+ end
84
84
 
85
- @queue << "#{@token}#{message}\n"
85
+ @queue << "#{ @token }#{ message }\n"
86
86
 
87
- if @started then
88
- check_async_thread
89
- else
90
- start_async_thread
91
- end
87
+ if @started
88
+ check_async_thread
89
+ else
90
+ start_async_thread
91
+ end
92
92
  end
93
93
 
94
- def start_async_thread
95
- @thread = Thread.new{run()}
96
- dbg "LE: Asynchronous socket writer started"
97
- @started = true
98
- end
94
+ def start_async_thread
95
+ @thread = Thread.new { run() }
96
+ dbg "LE: Asynchronous socket writer started"
97
+ @started = true
98
+ end
99
99
 
100
- def check_async_thread
101
- if not @thread.alive?
102
- @thread = Thread.new{run()}
103
- dbg "LE: Asyncrhonous socket writer restarted"
104
- end
105
- end
100
+ def check_async_thread
101
+ if not(@thread && @thread.alive?)
102
+ @thread = Thread.new { run() }
103
+ end
104
+ end
106
105
 
107
106
  def close
108
- dbg "LE: Closing asynchronous socket writer"
109
- @started = false
107
+ dbg "LE: Closing asynchronous socket writer"
108
+ @started = false
109
+ end
110
+
111
+ def openConnection
112
+ dbg "LE: Reopening connection to Logentries API server"
113
+ port = @ssl ? API_SSL_PORT : API_PORT
114
+ socket = TCPSocket.new(API_SERVER, port)
115
+ if @ssl
116
+ ssl_context = OpenSSL::SSL::SSLContext.new()
117
+ ssl_context.cert = OpenSSL::X509::Certificate.new(API_CERT)
118
+ ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context)
119
+ ssl_socket.sync_close = true
120
+ ssl_socket.connect
121
+ @conn = ssl_socket
122
+ else
123
+ @conn = socket
124
+ end
125
+ dbg "LE: Connection established"
110
126
  end
111
127
 
112
- def openConnection
113
- dbg "LE: Reopening connection to Logentries API server"
114
- if @ssl then port = API_SSL_PORT else port = API_PORT end
115
- socket = TCPSocket.new(API_SERVER, port)
116
- if @ssl then
117
- ssl_context = OpenSSL::SSL::SSLContext.new()
118
- ssl_context.cert = OpenSSL::X509::Certificate.new(API_CERT)
119
- ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context)
120
- ssl_socket.sync_close = true
121
- ssl_socket.connect
122
- @conn = ssl_socket
123
- else
124
- @conn = socket
125
- end
126
- dbg "LE: Connection established"
127
- end
128
-
129
- def reopenConnection
130
- closeConnection
131
- root_delay = 0.1
132
- while true
133
- begin
134
- openConnection
135
- break
136
- rescue TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT, EOFError => e
137
- dbg "LE: Unable to connect to Logentries"
138
- end
139
- root_delay *= 2
140
- if root_delay >= 10 then
141
- root_delay = 10
142
- end
143
- wait_for = (root_delay + rand(root_delay)).to_i
144
- dbg "LE: Waiting for " + wait_for.to_s + "ms"
145
- sleep(wait_for)
146
- end
147
- end
148
-
149
- def closeConnection
150
- if @conn != nil
151
- @conn.sysclose
152
- @conn = nil
153
- end
154
- end
155
-
156
- def run
157
- reopenConnection
158
-
159
- while true
160
- data = @queue.pop
161
- while true
162
- begin
163
- @conn.write(data)
164
- rescue TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEOUT, EOFError => e
165
- reopenConnection
166
- next
167
- end
168
- break
169
- end
170
- end
171
- dbg "LE: Closing Asyncrhonous socket writer"
172
- closeConnection
173
- end
128
+ def reopenConnection
129
+ closeConnection
130
+ root_delay = 0.1
131
+ loop do
132
+ begin
133
+ openConnection
134
+ break
135
+ rescue TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT, EOFError
136
+ dbg "LE: Unable to connect to Logentries due to timeout(#{ $! })"
137
+ rescue
138
+ dbg "LE: Got exception in reopenConnection - #{ $! }"
139
+ raise
140
+ end
141
+ root_delay *= 2
142
+ if root_delay >= 10
143
+ root_delay = 10
144
+ end
145
+ wait_for = (root_delay + rand(root_delay)).to_i
146
+ dbg "LE: Waiting for #{ wait_for }ms"
147
+ sleep(wait_for)
148
+ end
149
+ end
150
+
151
+ def closeConnection
152
+ begin
153
+ if @conn.respond_to?(:sysclose)
154
+ @conn.sysclose
155
+ elsif @conn.respond_to?(:close)
156
+ @conn.close
157
+ end
158
+ rescue
159
+ dbg "LE: couldn't close connection, close with exception - #{ $! }"
160
+ ensure
161
+ @conn = nil
162
+ end
163
+ end
164
+
165
+ def run
166
+ reopenConnection
167
+
168
+ loop do
169
+ data = @queue.pop
170
+ loop do
171
+ begin
172
+ @conn.write(data)
173
+ rescue TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEOUT, EOFError
174
+ dbg "LE: Connection timeout(#{ $! }), try to reopen connection"
175
+ reopenConnection
176
+ next
177
+ rescue
178
+ dbg("LE: Got exception in run loop - #{ $! }")
179
+ raise
180
+ end
181
+
182
+ break
183
+ end
184
+ end
185
+
186
+ dbg "LE: Closing Asyncrhonous socket writer"
187
+
188
+ closeConnection
189
+ end
174
190
  end
175
191
  end
176
192
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: le
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 2
9
- version: "2.2"
9
+ - 1
10
+ version: 2.2.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Mark Lacomber (Logentries)
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2013-08-12 00:00:00 Z
18
+ date: 2013-08-30 00:00:00 Z
18
19
  dependencies: []
19
20
 
20
21
  description: |