gelfd2 0.3.0 → 0.4.2

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
- SHA1:
3
- metadata.gz: 8b3499cd8199e37e4da3a8ff9ca40f532e15369f
4
- data.tar.gz: acf0f142d4f915d3f2381be5c96f8b71abf58d70
2
+ SHA256:
3
+ metadata.gz: 23034a7e5e8a182a7905206efc058592efcd68e0ed3f1e9dd68c76b6913334f9
4
+ data.tar.gz: 04bc7308323df9d7df559a96eb2de308c870086d9d91f8726b7ac948f9ca5617
5
5
  SHA512:
6
- metadata.gz: be9ca319feb6f9dce7bfb779ecb20af6391e33e4fa110c09a661ecbb6792f8519c2f88563e08e1e827e98d7ca9e33c2cb89a8316dfb41af7b1532d376327623c
7
- data.tar.gz: 6f42adedef1b33599c89f27a1bae7e9e183de63055fa7188cfc13a88f2eaceaa91049e349c7a7d61d2ff58ced68315a9c6eb0a74b0f86fec9dfa020247acef75
6
+ metadata.gz: e4e72b8034244f003440c4371df0f768e6e02cefad00deb21e76cb01aab13ea4bd664f04a196ff8cc851b50519fd03de321694b99961a5bfd1b28b15dcc685ad
7
+ data.tar.gz: e452f312c9537f0bb90d00e7bb90d9287b82d239e9d90e9d1fcd4408978b8647ee031ba6f01e3786e703dda5091edef1a6d56ed8c5c52d9d4b1c37f9b7d44465
data/.travis.yml CHANGED
@@ -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,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
@@ -5,7 +5,9 @@ module Gelfd2
5
5
  def self.parse(data)
6
6
  begin
7
7
  t = Zlib::GzipReader.new(StringIO.new(data))
8
- t.read
8
+ decompressed = t.read
9
+ t.close # may trigger CRCError if there was corruption
10
+ decompressed
9
11
  #raise NotYetImplementedError, "GZip decoding is not yet implemented"
10
12
  rescue Exception => e
11
13
  raise DecodeError, "Failed to decode data: #{e}"
data/lib/gelfd2/parser.rb CHANGED
@@ -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.2'
3
3
  end
data/lib/gelfd2.rb CHANGED
@@ -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
data/test/tc_chunked.rb CHANGED
@@ -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,15 +1,15 @@
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John E. Vincent
8
8
  - ptQa
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-09-15 00:00:00.000000000 Z
12
+ date: 2025-03-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -54,7 +54,7 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  version: 3.2.1
56
56
  description: Standalone implementation of the Graylog Extended Log Format
57
- email:
57
+ email:
58
58
  executables:
59
59
  - gelfd
60
60
  extensions: []
@@ -121,7 +121,7 @@ files:
121
121
  homepage: https://github.com/ptqa/gelfd2
122
122
  licenses: []
123
123
  metadata: {}
124
- post_install_message:
124
+ post_install_message:
125
125
  rdoc_options: []
126
126
  require_paths:
127
127
  - lib
@@ -136,10 +136,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  - !ruby/object:Gem::Version
137
137
  version: '0'
138
138
  requirements: []
139
- rubyforge_project: gelfd2
140
- rubygems_version: 2.4.6
141
- signing_key:
139
+ rubygems_version: 3.4.19
140
+ signing_key:
142
141
  specification_version: 4
143
142
  summary: Pure ruby gelf server and decoding library
144
143
  test_files: []
145
- has_rdoc: