mee-rfc5424 0.2.0 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b64aa276950368440556ed5d17ac7c27df6f48f5
4
- data.tar.gz: a86c909f14e6d38c3a990356f7670d025b6bb98e
3
+ metadata.gz: 78619957dcd9f1f40312b3223002b15fbb6e14c3
4
+ data.tar.gz: 7ea268131d410532d12693d8ab98cff6c8868701
5
5
  SHA512:
6
- metadata.gz: f5027bff62db8c2d5d7aa4f812de5a23c41a85f9a58e530c6ce5c71c0e20e9232901feada91232cbbb13487e0dde6f6eccbbb001af9591bde89187d3bf7b29a1
7
- data.tar.gz: 82489524b6085c92b3147c4e77aa32ebe4014a0bef0555178cfebf499dcef019c770ad99adc34f1d84cda79ec18606dcfc14fdc8e2be0392b4d4ea2bdd4b2583
6
+ metadata.gz: dcf3075b3dd90fd765cbbe37eb9ae2ce63d71099b7ac5483b967319c0d5c5b131c5e3c0862cb3ab6626b6a2f8494aae9af2511a799a29cc0f908da83e41179f9
7
+ data.tar.gz: d298053e73c104cffb7078be36dd45022cef51f871f3d3e1af0d4b099c5120545db5f42788dc90a0079c116e234040d2eb803cc19f1f9737c8b2f0e346c01e35
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # MEE::Rfc5424
1
+ # MEE::RFC5424
2
2
 
3
3
  Ruby loggger capable of logging against Syslog (RFC5424) over TCP and Syslog over TLS. Logs may be in either non-transparent newline framing or octet counting framing.
4
4
 
@@ -44,11 +44,9 @@ logger.info { "TLS message logging" }
44
44
 
45
45
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
46
46
 
47
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
48
-
49
47
  ## Contributing
50
48
 
51
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mee-rfc5424.
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/meschbach/mee-rfc5424.
52
50
 
53
51
  ## Licensing
54
52
 
@@ -10,7 +10,7 @@ require 'time'
10
10
  module MEE
11
11
  module RFC5424
12
12
  class Meta
13
- attr_accessor :host, :proc_name, :facility, :pid
13
+ attr_accessor :host, :proc_name, :facility, :pid, :when
14
14
 
15
15
  def initialize( props = {})
16
16
  self.host = props[:host] || Socket.gethostname
@@ -21,7 +21,7 @@ module MEE
21
21
 
22
22
  def header( params = {} )
23
23
  severity = params[:severity] || Syslog::LOG_INFO
24
- when_date = (params[:when] || DateTime.now).new_offset( 0 )
24
+ when_date = (@when || (params[:when] || DateTime.now) ).new_offset( 0 )
25
25
  formatted_when = when_date.strftime("%FT%T.%3NZ")
26
26
  priority = (facility * 8) + severity
27
27
  "<#{priority}>1 #{formatted_when} #{self.host} #{proc_name} #{self.pid} - - \xEF\xBB\xBF"
@@ -58,14 +58,50 @@ module MEE
58
58
  end
59
59
  end
60
60
 
61
+ class TCPFactory
62
+ def initialize( host, port )
63
+ @host = host
64
+ @port = port
65
+ end
66
+
67
+ def dial()
68
+ target = TCPSocket.new( @host, @port )
69
+ target
70
+ end
71
+ end
72
+
73
+ class TLSFactory < TCPFactory
74
+ def initialize( host, port )
75
+ super
76
+ end
77
+
78
+ def dial()
79
+ clear_text_transport = super
80
+ secure_transport = OpenSSL::SSL::SSLSocket.new clear_text_transport
81
+ secure_transport.connect
82
+ secure_transport
83
+ end
84
+ end
85
+
61
86
  class SocketTransport
62
- attr_accessor :socket
63
- def initialize( socket )
64
- self.socket = socket
87
+ attr_accessor :factory, :socket
88
+ def initialize( factory )
89
+ self.factory = factory
65
90
  end
66
91
 
67
92
  def send_frame( frame )
68
- socket.write( frame )
93
+ self.socket = self.factory.dial() unless self.socket
94
+ retrying = false
95
+ begin
96
+ socket.write( frame )
97
+ rescue Exception
98
+ self.socket.close()
99
+ self.socket = self.factory.dial() unless self.socket
100
+ if !retrying
101
+ retrying = true
102
+ retry
103
+ end
104
+ end
69
105
  end
70
106
  end
71
107
 
@@ -87,16 +123,12 @@ module MEE
87
123
  end
88
124
 
89
125
  def self.tcp( host, port )
90
- target = TCPSocket.new( host, port )
91
- protocol = SyslogClient.new( SocketTransport.new( target ) )
126
+ protocol = SyslogClient.new( SocketTransport.new( TCPFactory.new( host, port ) ) )
92
127
  LoggerProtocolAdapter.new( protocol )
93
128
  end
94
129
 
95
130
  def self.tls( host, port )
96
- raw_transport = TCPSocket.new( host, port )
97
- secure_transport = OpenSSL::SSL::SSLSocket.new raw_transport
98
- secure_transport.connect
99
- protocol = SyslogClient.new( SocketTransport.new( secure_transport ) )
131
+ protocol = SyslogClient.new( SocketTransport.new( TLSFactory.new( host, port ) ) )
100
132
  LoggerProtocolAdapter.new( protocol )
101
133
  end
102
134
  end
@@ -1,5 +1,5 @@
1
1
  module MEE
2
2
  module RFC5424
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mee-rfc5424
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Eschbach
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-25 00:00:00.000000000 Z
11
+ date: 2017-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler