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 +4 -4
- data/.travis.yml +4 -3
- data/lib/gelfd2.rb +5 -5
- data/lib/gelfd2/chunked_parser.rb +50 -34
- data/lib/gelfd2/parser.rb +14 -16
- data/lib/gelfd2/version.rb +1 -1
- data/test/tc_chunked.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ace6f71696dcfd3d301731d7e94ed7fa42132e15
|
4
|
+
data.tar.gz: 7a845badc222fdd38ebc76109a45e2d6509dd133
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c14a7512b1ac0536a69812115c90fb95d8f7328f16c827fccbc1baac69f33c00a83d9a21c7e4659387f5540d6484a9230d6b363b02c2b277d10a6a4dc85a454
|
7
|
+
data.tar.gz: 102409e0d8da8bb854fa2a582c447b427c4569473f1ee7ecb2b0bf0605f59f4aabec689a95579dd2c0baa6448fac00cfe00b2ef0e957166b147124f4bc105c21
|
data/.travis.yml
CHANGED
data/lib/gelfd2.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
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
|
-
|
3
|
+
class << self
|
4
4
|
|
5
|
-
|
5
|
+
attr_accessor :message_id, :max_chunks, :decoded_data, :chunks, :seen
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
data/lib/gelfd2/parser.rb
CHANGED
@@ -1,22 +1,20 @@
|
|
1
1
|
module Gelfd2
|
2
2
|
class Parser
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
data/lib/gelfd2/version.rb
CHANGED
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,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gelfd2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 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:
|
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.
|
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
|