tcp_syslog 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ ## 1.0.3 (2011-11-26)
2
+
3
+ * Added SSL support with peer verification
4
+
1
5
  ## 1.0.2 (2011-06-29)
2
6
 
3
7
  * Relax version requirements for active_support (Yawn)
data/Rakefile CHANGED
@@ -19,7 +19,7 @@ Jeweler::Tasks.new do |gem|
19
19
  gem.description = %Q{Rails syslog logger using TCP instead of UDP}
20
20
  gem.email = "philippe.lafoucriere@gmail.com"
21
21
  gem.authors = ["Philippe Lafoucrière"]
22
- gem.version = '1.0.2'
22
+ gem.version = '1.0.3'
23
23
  # Include your dependencies below. Runtime dependencies are required when using your gem,
24
24
  # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
25
25
  # gem.add_runtime_dependency 'jabber4r', '> 0.1'
@@ -2,7 +2,7 @@ require 'socket'
2
2
  require 'syslog'
3
3
  require 'logger'
4
4
  require 'system_timer'
5
-
5
+ require 'openssl'
6
6
  # TcpSyslog is used are a dead-simple replacement for
7
7
  # syslog ruby libs. None of them is able to send logs
8
8
  # to a remote server, and even less in TCP.
@@ -69,11 +69,15 @@ class TcpSyslog < ActiveSupport::BufferedLogger
69
69
  # ** +facility+ : defaults to user
70
70
  # ** +progname+ : defaults to 'rails'
71
71
  # ** +auto_flushing+ : number of messages to buffer before flushing
72
+ # ** +ssl+ : defaults to nil
73
+ # *** +cert : "/path/to/cert"
74
+ # *** +key : "/path/to/key"
75
+ # *** +ca_file : "/path/to/ca_file"
72
76
  #
73
77
  def initialize(options = {})
74
78
  @level = LOGGER_LEVEL_MAP[options[:level]] || Logger::DEBUG
75
79
  @host = options[:host] || 'localhost'
76
- @port = options[:port] = '514'
80
+ @port = options[:port] || '514'
77
81
  @facility = options[:facility] || Syslog::LOG_USER
78
82
  @progname = options[:progname] || 'rails'
79
83
  @buffer = Hash.new { |h,k| h[k] = [] }
@@ -81,6 +85,7 @@ class TcpSyslog < ActiveSupport::BufferedLogger
81
85
  @auto_flushing = options[:auto_flushing] || 1
82
86
  @local_ip = local_ip
83
87
  @remove_ansi_colors = options[:remove_ansi_colors] || true
88
+ @ssl = options[:ssl]
84
89
  return if defined? SYSLOG
85
90
  self.class.const_set :SYSLOG, true
86
91
  end
@@ -121,11 +126,35 @@ class TcpSyslog < ActiveSupport::BufferedLogger
121
126
  end
122
127
 
123
128
  def socket
124
- @socket[Thread.current] ||= TCPSocket.new(@host, @port)
129
+ @socket[Thread.current] ||= new_socket
125
130
  end
126
131
 
132
+ def ssl?
133
+ !@ssl.nil?
134
+ end
135
+
127
136
  protected
128
-
137
+
138
+ def new_socket
139
+ ssl? ? ssl_socket : tcp_socket
140
+ end
141
+
142
+ def tcp_socket
143
+ TCPSocket.new(@host, @port)
144
+ end
145
+
146
+ def ssl_socket
147
+ ssl_context = OpenSSL::SSL::SSLContext.new
148
+ ssl_context.cert = OpenSSL::X509::Certificate.new(File.open(@ssl[:cert]))
149
+ ssl_context.key = OpenSSL::PKey::RSA.new(File.open(@ssl[:key]))
150
+ ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER
151
+ ssl_context.ca_file = @ssl[:ca_file]
152
+ ssl_socket = OpenSSL::SSL::SSLSocket.new(tcp_socket, ssl_context)
153
+ ssl_socket.sync_close = true
154
+ ssl_socket.connect
155
+ ssl_socket
156
+ end
157
+
129
158
  # Clean up messages so they're nice and pretty.
130
159
  def clean(message)
131
160
  message = message.to_s.dup
@@ -156,7 +185,7 @@ class TcpSyslog < ActiveSupport::BufferedLogger
156
185
  msg.split("\n").each do |line|
157
186
  write_on_socket(severity, line)
158
187
  end
159
- rescue Errno::ECONNREFUSED, Errno::EPIPE, Timeout::Error => e
188
+ rescue Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EPIPE, Timeout::Error, OpenSSL::SSL::SSLError => e
160
189
  # can't log anything, stop trying
161
190
  @socket[Thread.current] = nil
162
191
  end
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{tcp_syslog}
8
- s.version = "1.0.2"
7
+ s.name = "tcp_syslog"
8
+ s.version = "1.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Philippe Lafoucri\303\250re"]
12
- s.date = %q{2011-06-29}
13
- s.description = %q{Rails syslog logger using TCP instead of UDP}
14
- s.email = %q{philippe.lafoucriere@gmail.com}
12
+ s.date = "2011-11-27"
13
+ s.description = "Rails syslog logger using TCP instead of UDP"
14
+ s.email = "philippe.lafoucriere@gmail.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
17
  "README.rdoc"
@@ -29,11 +29,11 @@ Gem::Specification.new do |s|
29
29
  "test/tcp_syslog_benchmark.rb",
30
30
  "test/test_tcp_syslog.rb"
31
31
  ]
32
- s.homepage = %q{http://github.com/tech-angels/tcp_syslog}
32
+ s.homepage = "http://github.com/tech-angels/tcp_syslog"
33
33
  s.licenses = ["MIT"]
34
34
  s.require_paths = ["lib"]
35
- s.rubygems_version = %q{1.5.2}
36
- s.summary = %q{Send logs to syslog using TCP instead of UDP}
35
+ s.rubygems_version = "1.8.10"
36
+ s.summary = "Send logs to syslog using TCP instead of UDP"
37
37
  s.test_files = [
38
38
  "test/helper.rb",
39
39
  "test/tcp_syslog_benchmark.rb",
@@ -14,6 +14,7 @@ class TestTcpSyslog < ActiveSupport::TestCase
14
14
  assert_equal 'rails', @logger.progname
15
15
  assert_equal 1, @logger.auto_flushing
16
16
  assert_equal Logger::DEBUG, @logger.level
17
+ assert_equal false, @logger.ssl?
17
18
  end
18
19
 
19
20
  should "have defined debug, info, warn, error, fatal methods" do
@@ -26,16 +27,35 @@ class TestTcpSyslog < ActiveSupport::TestCase
26
27
 
27
28
  context "on add message" do
28
29
  setup do
29
- message = "This message to be sent to syslog"
30
+ @message = "This message to be sent to syslog"
31
+ end
32
+
33
+ should "have sent the message to syslog using plain TCP" do
34
+ mock.proxy(TCPSocket).new(@logger.host, @logger.port)
35
+ dont_allow(OpenSSL::SSL::SSLSocket).new
30
36
  mock.proxy(@logger).flush
31
- mock.proxy(@logger).log(Logger::INFO, message)
32
- mock.proxy(@logger).write_on_socket(Logger::INFO, message)
33
- @logger.add(Logger::INFO, message)
37
+ mock.proxy(@logger).log(Logger::INFO, @message)
38
+ mock.proxy(@logger).write_on_socket(Logger::INFO, @message)
39
+ @logger.add(Logger::INFO, @message)
40
+ RR.verify
34
41
  end
35
42
 
36
- should "have sent the message to syslog" do
43
+ should "have sent the message to syslog using SSL with peer verification" do
44
+ @logger = TcpSyslog.new(
45
+ :ssl => {
46
+ :cert => "/path/to/cert",
47
+ :key => "/path/to/key",
48
+ :ca_file => "/path/to/ca_file"
49
+ }
50
+ )
51
+ mock(@logger).ssl_socket{mock!.write(anything)}
52
+ mock.proxy(@logger).flush
53
+ mock.proxy(@logger).log(Logger::INFO, @message)
54
+ mock.proxy(@logger).write_on_socket(Logger::INFO, @message)
55
+ @logger.add(Logger::INFO, @message)
37
56
  RR.verify
38
57
  end
58
+
39
59
  end
40
60
  end
41
61
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tcp_syslog
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 2
10
- version: 1.0.2
9
+ - 3
10
+ version: 1.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Philippe Lafoucri\xC3\xA8re"
@@ -15,12 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-29 00:00:00 +02:00
19
- default_executable:
18
+ date: 2011-11-27 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
- type: :development
23
- requirement: &id001 !ruby/object:Gem::Requirement
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
22
  none: false
25
23
  requirements:
26
24
  - - ">="
@@ -29,12 +27,12 @@ dependencies:
29
27
  segments:
30
28
  - 0
31
29
  version: "0"
32
- name: shoulda
33
- version_requirements: *id001
30
+ requirement: *id001
31
+ type: :development
34
32
  prerelease: false
33
+ name: shoulda
35
34
  - !ruby/object:Gem::Dependency
36
- type: :development
37
- requirement: &id002 !ruby/object:Gem::Requirement
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
38
36
  none: false
39
37
  requirements:
40
38
  - - ~>
@@ -45,12 +43,12 @@ dependencies:
45
43
  - 6
46
44
  - 0
47
45
  version: 0.6.0
48
- name: yard
49
- version_requirements: *id002
46
+ requirement: *id002
47
+ type: :development
50
48
  prerelease: false
49
+ name: yard
51
50
  - !ruby/object:Gem::Dependency
52
- type: :development
53
- requirement: &id003 !ruby/object:Gem::Requirement
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
52
  none: false
55
53
  requirements:
56
54
  - - ~>
@@ -61,12 +59,12 @@ dependencies:
61
59
  - 0
62
60
  - 0
63
61
  version: 1.0.0
64
- name: bundler
65
- version_requirements: *id003
62
+ requirement: *id003
63
+ type: :development
66
64
  prerelease: false
65
+ name: bundler
67
66
  - !ruby/object:Gem::Dependency
68
- type: :development
69
- requirement: &id004 !ruby/object:Gem::Requirement
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
70
68
  none: false
71
69
  requirements:
72
70
  - - ~>
@@ -77,12 +75,12 @@ dependencies:
77
75
  - 5
78
76
  - 1
79
77
  version: 1.5.1
80
- name: jeweler
81
- version_requirements: *id004
78
+ requirement: *id004
79
+ type: :development
82
80
  prerelease: false
81
+ name: jeweler
83
82
  - !ruby/object:Gem::Dependency
84
- type: :development
85
- requirement: &id005 !ruby/object:Gem::Requirement
83
+ version_requirements: &id005 !ruby/object:Gem::Requirement
86
84
  none: false
87
85
  requirements:
88
86
  - - ">="
@@ -91,12 +89,12 @@ dependencies:
91
89
  segments:
92
90
  - 0
93
91
  version: "0"
94
- name: rcov
95
- version_requirements: *id005
92
+ requirement: *id005
93
+ type: :development
96
94
  prerelease: false
95
+ name: rcov
97
96
  - !ruby/object:Gem::Dependency
98
- type: :development
99
- requirement: &id006 !ruby/object:Gem::Requirement
97
+ version_requirements: &id006 !ruby/object:Gem::Requirement
100
98
  none: false
101
99
  requirements:
102
100
  - - ~>
@@ -107,12 +105,12 @@ dependencies:
107
105
  - 0
108
106
  - 0
109
107
  version: 3.0.0
110
- name: activesupport
111
- version_requirements: *id006
108
+ requirement: *id006
109
+ type: :development
112
110
  prerelease: false
111
+ name: activesupport
113
112
  - !ruby/object:Gem::Dependency
114
- type: :development
115
- requirement: &id007 !ruby/object:Gem::Requirement
113
+ version_requirements: &id007 !ruby/object:Gem::Requirement
116
114
  none: false
117
115
  requirements:
118
116
  - - ">="
@@ -121,12 +119,12 @@ dependencies:
121
119
  segments:
122
120
  - 0
123
121
  version: "0"
124
- name: rr
125
- version_requirements: *id007
122
+ requirement: *id007
123
+ type: :development
126
124
  prerelease: false
125
+ name: rr
127
126
  - !ruby/object:Gem::Dependency
128
- type: :development
129
- requirement: &id008 !ruby/object:Gem::Requirement
127
+ version_requirements: &id008 !ruby/object:Gem::Requirement
130
128
  none: false
131
129
  requirements:
132
130
  - - ">="
@@ -135,12 +133,12 @@ dependencies:
135
133
  segments:
136
134
  - 0
137
135
  version: "0"
138
- name: i18n
139
- version_requirements: *id008
136
+ requirement: *id008
137
+ type: :development
140
138
  prerelease: false
139
+ name: i18n
141
140
  - !ruby/object:Gem::Dependency
142
- type: :development
143
- requirement: &id009 !ruby/object:Gem::Requirement
141
+ version_requirements: &id009 !ruby/object:Gem::Requirement
144
142
  none: false
145
143
  requirements:
146
144
  - - ">="
@@ -149,12 +147,12 @@ dependencies:
149
147
  segments:
150
148
  - 0
151
149
  version: "0"
152
- name: SystemTimer
153
- version_requirements: *id009
150
+ requirement: *id009
151
+ type: :development
154
152
  prerelease: false
153
+ name: SystemTimer
155
154
  - !ruby/object:Gem::Dependency
156
- type: :runtime
157
- requirement: &id010 !ruby/object:Gem::Requirement
155
+ version_requirements: &id010 !ruby/object:Gem::Requirement
158
156
  none: false
159
157
  requirements:
160
158
  - - ~>
@@ -165,12 +163,12 @@ dependencies:
165
163
  - 0
166
164
  - 0
167
165
  version: 3.0.0
168
- name: activesupport
169
- version_requirements: *id010
166
+ requirement: *id010
167
+ type: :runtime
170
168
  prerelease: false
169
+ name: activesupport
171
170
  - !ruby/object:Gem::Dependency
172
- type: :runtime
173
- requirement: &id011 !ruby/object:Gem::Requirement
171
+ version_requirements: &id011 !ruby/object:Gem::Requirement
174
172
  none: false
175
173
  requirements:
176
174
  - - ">="
@@ -181,9 +179,10 @@ dependencies:
181
179
  - 2
182
180
  - 3
183
181
  version: 1.2.3
184
- name: SystemTimer
185
- version_requirements: *id011
182
+ requirement: *id011
183
+ type: :runtime
186
184
  prerelease: false
185
+ name: SystemTimer
187
186
  description: Rails syslog logger using TCP instead of UDP
188
187
  email: philippe.lafoucriere@gmail.com
189
188
  executables: []
@@ -205,7 +204,6 @@ files:
205
204
  - test/helper.rb
206
205
  - test/tcp_syslog_benchmark.rb
207
206
  - test/test_tcp_syslog.rb
208
- has_rdoc: true
209
207
  homepage: http://github.com/tech-angels/tcp_syslog
210
208
  licenses:
211
209
  - MIT
@@ -235,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
235
233
  requirements: []
236
234
 
237
235
  rubyforge_project:
238
- rubygems_version: 1.5.2
236
+ rubygems_version: 1.8.10
239
237
  signing_key:
240
238
  specification_version: 3
241
239
  summary: Send logs to syslog using TCP instead of UDP