remote_syslog_sender 1.1.2 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ca5b6ec6c42fc7554d4d3318c6f267d1a3f8a508
4
- data.tar.gz: cdb652566a198fa60e5a54487e4ea8e371c07011
2
+ SHA256:
3
+ metadata.gz: 5f790e1aed9473d0578f52ec35947fd78d1ab614670513efe787ec79ac4cf42b
4
+ data.tar.gz: f65e0ced0294ecbe1533fe04a4b2054e9f976230e74fd813ca30733dd2fbea9e
5
5
  SHA512:
6
- metadata.gz: d8fe3ae5a16f8695e96cde2d60166013ab09037e8a4e671217123aa1cee487b7d170c84b814b43a2fd4f476d05502d4e807099fb12875278c6b39d8acaed0bdf
7
- data.tar.gz: 5ad178f44071790a783d33869c578c3a02218a6200d805c2cce3558a431375fcef924f1bdb2193eb26ffe5ce56355b8283c874faf29a946cf0927b8c21d631e6
6
+ metadata.gz: ef23aa24b79470f4c0e5fb51be9b90e1801c1513b85494d7d63facd4abc47fc109f4e5a34366b96eaf45c729895a904f8767da718e53676a734e723c1ebd8720
7
+ data.tar.gz: 4128b921473bf397d423a08f99895a3e2d77a7c1dc158b9e9c8b3b2f85fe85b34bc983a18fbaaf1b492d0ecb8946d24853974659b90cc8af7569f114bbba69c1
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Remote Syslog Sender
2
2
 
3
- This gem is syslog sender that is extracted from (papertrail/remote_syslog_logger)[https://github.com/papertrail/remote_syslog_logger]
3
+ This gem is syslog sender that is extracted from [papertrail/remote_syslog_logger](https://github.com/papertrail/remote_syslog_logger)
4
4
 
5
5
  This can send message to remote syslog server via UDP, TCP, TCP+TLS.
6
6
  (Original does not support TCP, TCP+TLS protocol).
@@ -48,8 +48,11 @@ module RemoteSyslogSender
48
48
  packet.content = line
49
49
  send_msg(packet.assemble(@packet_size))
50
50
  rescue
51
- $stderr.puts "#{self.class} error: #{$!.class}: #{$!}\nOriginal message: #{line}"
52
- raise if @whinyerrors
51
+ if @whinyerrors
52
+ raise
53
+ else
54
+ $stderr.puts "#{self.class} error: #{$!.class}: #{$!}\nOriginal message: #{line}"
55
+ end
53
56
  end
54
57
  end
55
58
  end
@@ -16,10 +16,13 @@ module RemoteSyslogSender
16
16
  @ssl_method = options[:ssl_method] || 'TLSv1_2'
17
17
  @ca_file = options[:ca_file]
18
18
  @verify_mode = options[:verify_mode]
19
- @timeout = options[:timeout]
19
+ @timeout = options[:timeout] || 600
20
20
  @timeout_exception = !!options[:timeout_exception]
21
21
  @exponential_backoff = !!options[:exponential_backoff]
22
22
 
23
+ @mutex = Mutex.new
24
+ @tcp_socket = nil
25
+
23
26
  if [:SOL_SOCKET, :SO_KEEPALIVE, :IPPROTO_TCP, :TCP_KEEPIDLE].all? {|c| Socket.const_defined? c}
24
27
  @keep_alive = options[:keep_alive]
25
28
  end
@@ -35,27 +38,53 @@ module RemoteSyslogSender
35
38
  connect
36
39
  end
37
40
 
41
+ def close
42
+ @socket.close if @socket
43
+ @tcp_socket.close if @tcp_socket
44
+ end
45
+
38
46
  private
39
47
 
40
48
  def connect
41
- sock = TCPSocket.new(@remote_hostname, @remote_port)
42
- if @keep_alive
43
- sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
44
- sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_KEEPIDLE, @keep_alive_idle) if @keep_alive_idle
45
- sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_KEEPCNT, @keep_alive_cnt) if @keep_alive_cnt
46
- sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_KEEPINTVL, @keep_alive_intvl) if @keep_alive_intvl
47
- end
48
- if @tls
49
- require 'openssl'
50
- context = OpenSSL::SSL::SSLContext.new(@ssl_method)
51
- context.ca_file = @ca_file if @ca_file
52
- context.verify_mode = @verify_mode if @verify_mode
53
- @socket = OpenSSL::SSL::SSLSocket.new(sock, context)
54
- @socket.connect
55
- @socket.post_connection_check(@remote_hostname)
56
- raise "verification error" if @socket.verify_result != OpenSSL::X509::V_OK
57
- else
58
- @socket = sock
49
+ connect_retry_count = 0
50
+ connect_retry_limit = 3
51
+ connect_retry_interval = 1
52
+ @mutex.synchronize do
53
+ begin
54
+ close
55
+
56
+ @tcp_socket = TCPSocket.new(@remote_hostname, @remote_port)
57
+
58
+ if @keep_alive
59
+ @tcp_socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
60
+ @tcp_socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_KEEPIDLE, @keep_alive_idle) if @keep_alive_idle
61
+ @tcp_socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_KEEPCNT, @keep_alive_cnt) if @keep_alive_cnt
62
+ @tcp_socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_KEEPINTVL, @keep_alive_intvl) if @keep_alive_intvl
63
+ end
64
+ if @tls
65
+ require 'openssl'
66
+ context = OpenSSL::SSL::SSLContext.new(@ssl_method)
67
+ context.ca_file = @ca_file if @ca_file
68
+ context.verify_mode = @verify_mode if @verify_mode
69
+
70
+ @socket = OpenSSL::SSL::SSLSocket.new(@tcp_socket, context)
71
+ @socket.connect
72
+ if @verify_mode != OpenSSL::SSL::VERIFY_NONE
73
+ @socket.post_connection_check(@remote_hostname)
74
+ raise "verification error" if @socket.verify_result != OpenSSL::X509::V_OK
75
+ end
76
+ else
77
+ @socket = @tcp_socket
78
+ end
79
+ rescue
80
+ if connect_retry_count < connect_retry_limit
81
+ sleep connect_retry_interval
82
+ connect_retry_count += 1
83
+ retry
84
+ else
85
+ raise
86
+ end
87
+ end
59
88
  end
60
89
  end
61
90
 
@@ -77,9 +106,15 @@ module RemoteSyslogSender
77
106
  until payload_size <= 0
78
107
  start = get_time
79
108
  begin
80
- result = @socket.__send__(method, payload)
109
+ result = @mutex.synchronize { @socket.__send__(method, payload) }
81
110
  payload_size -= result
82
111
  payload.slice!(0, result) if payload_size > 0
112
+ rescue IO::WaitReadable
113
+ timeout_wait = @timeout - (get_time - start)
114
+ retry if IO.select([@socket], nil, nil, timeout_wait)
115
+
116
+ raise NonBlockingTimeout if @timeout_exception
117
+ break
83
118
  rescue IO::WaitWritable
84
119
  timeout_wait = @timeout - (get_time - start)
85
120
  retry if IO.select(nil, [@socket], nil, timeout_wait)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'remote_syslog_sender'
3
- s.version = '1.1.2'
3
+ s.version = '1.2.2'
4
4
  s.summary = "Message sender that sends directly to a remote syslog endpoint"
5
5
  s.description = "Message sender that sends directly to a remote syslog endpoint (Support UDP, TCP, TCP+TLS)"
6
6
 
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.add_runtime_dependency 'syslog_protocol'
17
17
 
18
- s.add_development_dependency "bundler", "~> 1.6"
18
+ s.add_development_dependency "bundler", ">= 1.6", "< 3.0"
19
19
  s.add_development_dependency "rake"
20
20
  s.add_development_dependency "test-unit"
21
21
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remote_syslog_sender
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomohiro Hashidate
8
8
  - Eric Lindvall
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-10-04 00:00:00.000000000 Z
12
+ date: 2021-07-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: syslog_protocol
@@ -29,16 +29,22 @@ dependencies:
29
29
  name: bundler
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '1.6'
35
+ - - "<"
36
+ - !ruby/object:Gem::Version
37
+ version: '3.0'
35
38
  type: :development
36
39
  prerelease: false
37
40
  version_requirements: !ruby/object:Gem::Requirement
38
41
  requirements:
39
- - - "~>"
42
+ - - ">="
40
43
  - !ruby/object:Gem::Version
41
44
  version: '1.6'
45
+ - - "<"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
42
48
  - !ruby/object:Gem::Dependency
43
49
  name: rake
44
50
  requirement: !ruby/object:Gem::Requirement
@@ -89,7 +95,7 @@ files:
89
95
  homepage: https://github.com/reproio/remote_syslog_logger
90
96
  licenses: []
91
97
  metadata: {}
92
- post_install_message:
98
+ post_install_message:
93
99
  rdoc_options: []
94
100
  require_paths:
95
101
  - lib
@@ -104,9 +110,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
110
  - !ruby/object:Gem::Version
105
111
  version: '0'
106
112
  requirements: []
107
- rubyforge_project:
108
- rubygems_version: 2.6.13
109
- signing_key:
113
+ rubygems_version: 3.2.3
114
+ signing_key:
110
115
  specification_version: 4
111
116
  summary: Message sender that sends directly to a remote syslog endpoint
112
117
  test_files: