le 2.2 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LE.gemspec +1 -1
- data/lib/le/host/http.rb +132 -116
- metadata +4 -3
data/LE.gemspec
CHANGED
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
if @local
|
|
82
|
+
@logger_console.add(Logger::Severity::UNKNOWN, message)
|
|
83
|
+
end
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
@queue << "#{ @token }#{ message }\n"
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
if @started
|
|
88
|
+
check_async_thread
|
|
89
|
+
else
|
|
90
|
+
start_async_thread
|
|
91
|
+
end
|
|
92
92
|
end
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
109
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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:
|
|
4
|
+
hash: 5
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 2
|
|
8
8
|
- 2
|
|
9
|
-
|
|
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-
|
|
18
|
+
date: 2013-08-30 00:00:00 Z
|
|
18
19
|
dependencies: []
|
|
19
20
|
|
|
20
21
|
description: |
|