gelfd2 0.3.0 → 0.4.1

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
2
  SHA1:
3
- metadata.gz: 8b3499cd8199e37e4da3a8ff9ca40f532e15369f
4
- data.tar.gz: acf0f142d4f915d3f2381be5c96f8b71abf58d70
3
+ metadata.gz: ace6f71696dcfd3d301731d7e94ed7fa42132e15
4
+ data.tar.gz: 7a845badc222fdd38ebc76109a45e2d6509dd133
5
5
  SHA512:
6
- metadata.gz: be9ca319feb6f9dce7bfb779ecb20af6391e33e4fa110c09a661ecbb6792f8519c2f88563e08e1e827e98d7ca9e33c2cb89a8316dfb41af7b1532d376327623c
7
- data.tar.gz: 6f42adedef1b33599c89f27a1bae7e9e183de63055fa7188cfc13a88f2eaceaa91049e349c7a7d61d2ff58ced68315a9c6eb0a74b0f86fec9dfa020247acef75
6
+ metadata.gz: 8c14a7512b1ac0536a69812115c90fb95d8f7328f16c827fccbc1baac69f33c00a83d9a21c7e4659387f5540d6484a9230d6b363b02c2b277d10a6a4dc85a454
7
+ data.tar.gz: 102409e0d8da8bb854fa2a582c447b427c4569473f1ee7ecb2b0bf0605f59f4aabec689a95579dd2c0baa6448fac00cfe00b2ef0e957166b147124f4bc105c21
@@ -1,8 +1,9 @@
1
+ language: ruby
1
2
  rvm:
2
- - 1.9.3
3
3
  - 2.0.0
4
- - 2.3.1
5
- - rbx
4
+ - 2.3
5
+ - 2.4
6
+ - rbx-3.86
6
7
  - jruby
7
8
 
8
9
  script: "bundle exec rake test"
@@ -1,10 +1,10 @@
1
- require "gelfd2/version"
1
+ require 'gelfd2/version'
2
2
 
3
3
  module Gelfd2
4
- CHUNKED_MAGIC = [0x1e,0x0f].pack('C*').freeze
5
- ZLIB_MAGIC = [0x78,0x9c].pack('C*').freeze
6
- GZIP_MAGIC = [0x1f,0x8b].pack('C*').freeze
7
- UNCOMPRESSED_MAGIC = [0x1f,0x3c].pack('C*').freeze
4
+ CHUNKED_MAGIC = [0x1e, 0x0f].pack('C*').freeze
5
+ ZLIB_MAGIC = [0x78, 0x9c].pack('C*').freeze
6
+ GZIP_MAGIC = [0x1f, 0x8b].pack('C*').freeze
7
+ UNCOMPRESSED_MAGIC = [0x1f, 0x3c].pack('C*').freeze
8
8
  HEADER_LENGTH = 12
9
9
  DATA_LENGTH = 8192 - HEADER_LENGTH
10
10
  MAX_CHUNKS = 128
@@ -1,48 +1,64 @@
1
1
  module Gelfd2
2
2
  class ChunkedParser
3
- @@chunk_map = Hash.new {|hash,key| hash[key] = {:total_chunks => 0, :chunks => {} } }
3
+ class << self
4
4
 
5
- attr_accessor :message_id, :max_chunks, :decoded_data, :chunks, :seen
5
+ attr_accessor :message_id, :max_chunks, :decoded_data, :chunks, :seen
6
6
 
7
- def self.parse(data)
8
- msg_id = self.parse_chunk(data)
9
- if @@chunk_map[msg_id][:chunks].size == @@chunk_map[msg_id][:total_chunks]
7
+ def parse(data)
8
+ @chunk_map ||= Hash.new { |hash, key| hash[key] = { total_chunks: 0, msg_ttl: 0, chunks: {} } }
9
+ @msg_timeout ||= 20
10
+ @last_cleanup ||= 0
11
+ msg_id = parse_chunk(data)
12
+ return unless @chunk_map[msg_id][:chunks].size == @chunk_map[msg_id][:total_chunks]
13
+ cleanup_chunks
10
14
  assemble_chunks(msg_id)
11
15
  end
12
- end
13
16
 
14
- def self.assemble_chunks(msg_id)
15
- buff = ''
16
- chunks = @@chunk_map[msg_id][:chunks]
17
- chunks.keys.sort.each do |k|
18
- buff += chunks[k]
17
+ def assemble_chunks(msg_id)
18
+ buff = ''
19
+ chunks = @chunk_map[msg_id][:chunks]
20
+ chunks.keys.sort.each do |k|
21
+ buff += chunks[k]
22
+ end
23
+ begin
24
+ # TODO
25
+ # This has a chance for an DoS
26
+ # you can send a chunked message as a chunked message
27
+ t = Parser.parse(buff.clone)
28
+ @chunk_map.delete(msg_id)
29
+ t
30
+ rescue Exception => e
31
+ "Exception: #{e.message}"
32
+ end
19
33
  end
20
- begin
21
- # TODO
22
- # This has a chance for an DoS
23
- # you can send a chunked message as a chunked message
24
- t = Parser.parse(buff.clone)
25
- @@chunk_map.delete(msg_id)
26
- t
27
- rescue Exception => e
28
- "Exception: #{e.message}"
34
+
35
+ def parse_chunk(data)
36
+ header = data[0..1]
37
+ raise NotChunkedDataError, "This doesn't look like a Chunked GELF message!" if header != CHUNKED_MAGIC
38
+ begin
39
+ msg_id = data[2..9].unpack('C*').join
40
+ seq_number, total_number = data[10].ord, data[11].ord
41
+ zlib_chunk = data[12..-1]
42
+ raise TooManyChunksError, "#{total_number} greater than #{MAX_CHUNKS}" if total_number > MAX_CHUNKS
43
+ @chunk_map[msg_id][:total_chunks] = total_number.to_i
44
+ @chunk_map[msg_id][:chunks][seq_number.to_i] = zlib_chunk
45
+ @chunk_map[msg_id][:ttl] = Time.now.to_i + @msg_timeout
46
+ msg_id
47
+ end
29
48
  end
30
- end
31
49
 
32
- private
33
- def self.parse_chunk(data)
34
- header = data[0..1]
35
- raise NotChunkedDataError, "This doesn't look like a Chunked GELF message!" if header != CHUNKED_MAGIC
36
- begin
37
- msg_id = data[2..9].unpack('C*').join
38
- seq_number, total_number = data[10].ord, data[11].ord
39
- zlib_chunk = data[12..-1]
40
- raise TooManyChunksError, "#{total_number} greater than #{MAX_CHUNKS}" if total_number > MAX_CHUNKS
41
- @@chunk_map[msg_id][:total_chunks] = total_number.to_i
42
- @@chunk_map[msg_id][:chunks].merge!({seq_number.to_i => zlib_chunk})
43
- msg_id
50
+ def cleanup_chunks
51
+ # Run check every @msg_timeout seconds
52
+ now = Time.now.to_i
53
+ return unless now > @last_cleanup + @msg_timeout
54
+ begin
55
+ @last_cleanup = now
56
+ @chunk_map.each do |msg_id, msg|
57
+ next if msg[:ttl] > now
58
+ @chunk_map.delete(msg_id)
59
+ end
60
+ end
44
61
  end
45
62
  end
46
-
47
63
  end
48
64
  end
@@ -1,22 +1,20 @@
1
1
  module Gelfd2
2
2
  class Parser
3
-
4
- def self.parse(data)
5
- header = data[0..1]
6
- case header
7
- when ZLIB_MAGIC
8
- ZlibParser.parse(data)
9
- when CHUNKED_MAGIC
10
- ChunkedParser.parse(data)
11
- when GZIP_MAGIC
12
- GzipParser.parse(data)
13
- else
14
- # by default assume the payload to be "raw, uncompressed" GELF, parsing will fail if it's malformed.
15
- data
3
+ class << self
4
+ def parse(data)
5
+ header = data[0..1]
6
+ case header
7
+ when ZLIB_MAGIC
8
+ ZlibParser.parse(data)
9
+ when CHUNKED_MAGIC
10
+ ChunkedParser.parse(data)
11
+ when GZIP_MAGIC
12
+ GzipParser.parse(data)
13
+ else
14
+ # by default assume the payload to be "raw, uncompressed" GELF, parsing will fail if it's malformed.
15
+ data
16
+ end
16
17
  end
17
18
  end
18
-
19
19
  end
20
20
  end
21
-
22
-
@@ -1,3 +1,3 @@
1
1
  module Gelfd2
2
- VERSION = "0.3.0"
2
+ VERSION = '0.4.1'
3
3
  end
@@ -9,7 +9,7 @@ class TestChhunkedGelf < Test::Unit::TestCase
9
9
  def test_chunked_message
10
10
  files = Dir.glob("#{FIXTURE_PATH}/*.chunk")
11
11
  files.each do |file|
12
- data = File.open("#{file}", "rb") {|f| f.read}
12
+ data = File.open("#{file}", "rb") { |f| f.read }
13
13
  @t = Gelfd2::Parser.parse(data)
14
14
  end
15
15
  assert_equal(JSON_MESSAGE, @t)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gelfd2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John E. Vincent
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-09-15 00:00:00.000000000 Z
12
+ date: 2017-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  version: '0'
138
138
  requirements: []
139
139
  rubyforge_project: gelfd2
140
- rubygems_version: 2.4.6
140
+ rubygems_version: 2.5.2
141
141
  signing_key:
142
142
  specification_version: 4
143
143
  summary: Pure ruby gelf server and decoding library