LeDelay 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LEDELAY.gemspec +19 -0
- data/lib2/leDelay.rb +22 -0
- data/lib2/leDelay/host.rb +32 -0
- data/lib2/leDelay/host/http.rb +30 -0
- data/lib2/leDelay/host/http/sync.rb +37 -0
- metadata +70 -0
data/LEDELAY.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
require File.expand_path(File.join(dir, 'lib2', 'leDelay'))
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "LeDelay"
|
6
|
+
s.version = "0.2"
|
7
|
+
s.date = Time.now
|
8
|
+
s.summary = "Logentries plugin"
|
9
|
+
s.description =<<EOD
|
10
|
+
|
11
|
+
EOD
|
12
|
+
|
13
|
+
s.authors = ["Mark Lacomber (Logentries)"]
|
14
|
+
s.email = "marklacomber@gmail.com"
|
15
|
+
|
16
|
+
s.files = %w{ LEDELAY.gemspec } + Dir["#{dir}/lib2/**/*.rb"]
|
17
|
+
s.require_paths = ["lib2"]
|
18
|
+
|
19
|
+
end
|
data/lib2/leDelay.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#This will be the main le script
|
2
|
+
require File.join(File.dirname(__FILE__), 'leDelay', 'host')
|
3
|
+
|
4
|
+
require 'logger'
|
5
|
+
|
6
|
+
module LeDelay
|
7
|
+
|
8
|
+
def self.new(key, location)
|
9
|
+
|
10
|
+
host = LeDelay::Host.new(key, location)
|
11
|
+
logger = Logger.new(host)
|
12
|
+
|
13
|
+
if host.respond_to?(:formatter)
|
14
|
+
logger.formatter = host.formatter
|
15
|
+
elsif client.respond_to?(:datetime_format)
|
16
|
+
logger.datetime_format = host.datetime_format
|
17
|
+
end
|
18
|
+
|
19
|
+
logger
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#this is the client page
|
2
|
+
module LeDelay
|
3
|
+
module Host
|
4
|
+
|
5
|
+
def self.new(key, location)
|
6
|
+
|
7
|
+
LeDelay::Host::HTTP.new(key, location)
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
module InstanceMethods
|
12
|
+
|
13
|
+
def formatter
|
14
|
+
proc do |severity, datetime, progname, msg|
|
15
|
+
message = "#{datetime} "
|
16
|
+
message << format_message(msg, severity)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def format_message(message_in, severity)
|
21
|
+
message_out = ""
|
22
|
+
message_out << "severity=#{severity}, "
|
23
|
+
|
24
|
+
message_out << message_in
|
25
|
+
|
26
|
+
message_out
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
require File.join(File.dirname(__FILE__), 'host', 'http')
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'openssl'
|
3
|
+
require 'delayed_job'
|
4
|
+
|
5
|
+
require File.join(File.dirname(__FILE__), 'http', 'sync')
|
6
|
+
|
7
|
+
module LeDelay
|
8
|
+
module Host
|
9
|
+
class HTTP
|
10
|
+
include LeDelay::Host::InstanceMethods
|
11
|
+
|
12
|
+
attr_reader :deliverer
|
13
|
+
|
14
|
+
def initialize(key, location)
|
15
|
+
|
16
|
+
@deliverer = LeDelay::Host::HTTP::NetHTTPProxy.new(key, location)
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def write(message)
|
21
|
+
@deliverer.deliver(message)
|
22
|
+
end
|
23
|
+
|
24
|
+
def close
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module LeDelay
|
2
|
+
module Host
|
3
|
+
class HTTP
|
4
|
+
|
5
|
+
class NetHTTPProxy
|
6
|
+
|
7
|
+
attr_accessor :sock, :conn
|
8
|
+
def initialize(key, location)
|
9
|
+
addr = sprintf('/%s/%s/?realtime=1', key, location)
|
10
|
+
|
11
|
+
@sock = TCPSocket.new('api.logentries.com', 443)
|
12
|
+
|
13
|
+
@conn = OpenSSL::SSL::SSLSocket.new(@sock, OpenSSL::SSL::SSLContext.new())
|
14
|
+
@conn.sync_close = true
|
15
|
+
@conn.connect
|
16
|
+
|
17
|
+
request = sprintf("PUT %s HTTP/1.1\r\n", addr)
|
18
|
+
@conn.print(request)
|
19
|
+
@conn.print("Accept-Encoding: identity\r\n")
|
20
|
+
@conn.print("Transfer_Encoding: chunked\r\n\r\n")
|
21
|
+
end
|
22
|
+
|
23
|
+
def deliver(message)
|
24
|
+
|
25
|
+
begin
|
26
|
+
@conn.print(message + "\r\n")
|
27
|
+
rescue TimeoutError, OpenSSL::SSL::SSLError, EOFError, Errno::ECONNRESET => e
|
28
|
+
$stderr.puts "WARNING: #{e.class} posting message #{message}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
handle_asynchronously :deliver
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: LeDelay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
version: "0.2"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Mark Lacomber (Logentries)
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-06-30 00:00:00 Z
|
18
|
+
dependencies: []
|
19
|
+
|
20
|
+
description: |
|
21
|
+
|
22
|
+
|
23
|
+
email: marklacomber@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- LEDELAY.gemspec
|
32
|
+
- ./lib2/leDelay.rb
|
33
|
+
- ./lib2/leDelay/host.rb
|
34
|
+
- ./lib2/leDelay/host/http/sync.rb
|
35
|
+
- ./lib2/leDelay/host/http.rb
|
36
|
+
homepage:
|
37
|
+
licenses: []
|
38
|
+
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
require_paths:
|
43
|
+
- lib2
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
hash: 3
|
50
|
+
segments:
|
51
|
+
- 0
|
52
|
+
version: "0"
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.8.3
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Logentries plugin
|
69
|
+
test_files: []
|
70
|
+
|