le 1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/LE.gemspec +19 -0
- data/lib1.2backup/le.rb +18 -0
- data/lib1.2backup/le/host.rb +35 -0
- data/lib1.2backup/le/host/https.rb +33 -0
- data/lib1.2backup/le/host/https/tcp.rb +41 -0
- metadata +70 -0
data/LE.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
require File.expand_path(File.join(dir, 'lib1.2backup', 'le'))
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "le"
|
6
|
+
s.version = "1.4"
|
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{ LE.gemspec } + Dir["#{dir}/lib1.2backup/**/*.rb"]
|
17
|
+
s.require_paths = ["lib1.2backup"]
|
18
|
+
|
19
|
+
end
|
data/lib1.2backup/le.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#This will be the main le script
|
2
|
+
require File.join(File.dirname(__FILE__), 'le', 'host')
|
3
|
+
|
4
|
+
require 'logger'
|
5
|
+
|
6
|
+
module Le
|
7
|
+
|
8
|
+
def self.new(key, location)
|
9
|
+
|
10
|
+
host = Le::Host.new(key, location)
|
11
|
+
logger = Logger.new(host)
|
12
|
+
|
13
|
+
logger.formatter = host.formatter
|
14
|
+
|
15
|
+
logger
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#this is the client page
|
2
|
+
module Le
|
3
|
+
module Host
|
4
|
+
|
5
|
+
# Creates a new Logentries host, based on a user-key and location of destination file on logentries,
|
6
|
+
# both must be provided correctly for a connection to be made.
|
7
|
+
|
8
|
+
def self.new(key, location)
|
9
|
+
|
10
|
+
Le::Host::HTTPS.new(key, location)
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
module HelperMethods
|
15
|
+
|
16
|
+
def formatter
|
17
|
+
proc do |severity, datetime, progname, msg|
|
18
|
+
message = "#{datetime} "
|
19
|
+
message << format_message(msg, severity)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def format_message(msg_in, severity)
|
24
|
+
msg_out = ""
|
25
|
+
msg_out << "severity=#{severity}, "
|
26
|
+
|
27
|
+
msg_out << msg_in
|
28
|
+
|
29
|
+
msg_out
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
require File.join(File.dirname(__FILE__), 'host', 'https')
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'openssl'
|
3
|
+
|
4
|
+
require File.join(File.dirname(__FILE__), 'https', 'tcp')
|
5
|
+
|
6
|
+
module Le
|
7
|
+
module Host
|
8
|
+
class HTTPS
|
9
|
+
include Le::Host::HelperMethods
|
10
|
+
|
11
|
+
attr_reader :deliverer
|
12
|
+
|
13
|
+
def initialize(key, location)
|
14
|
+
|
15
|
+
@deliverer = Le::Host::HTTPS::TCPSOCKET.new(key, location)
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def write(message)
|
20
|
+
|
21
|
+
# In the Heroku environment, this puts command will write the message to standard Heroku logs also
|
22
|
+
puts message
|
23
|
+
# Deliver the message to logentries via TCP
|
24
|
+
@deliverer.deliver(message)
|
25
|
+
end
|
26
|
+
|
27
|
+
def close
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Le
|
2
|
+
module Host
|
3
|
+
class HTTPS
|
4
|
+
|
5
|
+
class TCPSOCKET
|
6
|
+
|
7
|
+
attr_accessor :sock, :conn
|
8
|
+
def initialize(key, location)
|
9
|
+
|
10
|
+
# Create the unique address comprising of user-key and location of file on logentries server
|
11
|
+
addr = sprintf('/%s/hosts/%s/?realtime=1', key, location)
|
12
|
+
|
13
|
+
# Open the TCP connection to the Logentries Server
|
14
|
+
@sock = TCPSocket.new('api.logentries.com', 443)
|
15
|
+
|
16
|
+
@conn = OpenSSL::SSL::SSLSocket.new(@sock, OpenSSL::SSL::SSLContext.new())
|
17
|
+
@conn.sync_close = true
|
18
|
+
@conn.connect
|
19
|
+
|
20
|
+
# Set up connection with Logentries API to receive messages in chunks, i.e, logs
|
21
|
+
request = sprintf("PUT %s HTTP/1.1\r\n", addr)
|
22
|
+
@conn.print(request)
|
23
|
+
@conn.print("Accept-Encoding: identity\r\n")
|
24
|
+
@conn.print("Transfer_Encoding: chunked\r\n\r\n")
|
25
|
+
end
|
26
|
+
|
27
|
+
def deliver(message)
|
28
|
+
|
29
|
+
# Sends the log to the Logentries Server
|
30
|
+
begin
|
31
|
+
@conn.print(message + "\r\n")
|
32
|
+
rescue OpenSSL::SSL::SSLError, TimeoutError, Errno::ECONNRESET, EOFError => e
|
33
|
+
$stderr.puts "WARNING: #{e.class} sending log #{message}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: le
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 7
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 4
|
9
|
+
version: "1.4"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Mark Lacomber (Logentries)
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-07-20 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
|
+
- LE.gemspec
|
32
|
+
- ./lib1.2backup/le.rb
|
33
|
+
- ./lib1.2backup/le/host.rb
|
34
|
+
- ./lib1.2backup/le/host/https.rb
|
35
|
+
- ./lib1.2backup/le/host/https/tcp.rb
|
36
|
+
homepage:
|
37
|
+
licenses: []
|
38
|
+
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
require_paths:
|
43
|
+
- lib1.2backup
|
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
|
+
|