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 +5 -5
- data/.travis.yml +4 -3
- data/lib/gelfd2/chunked_parser.rb +50 -34
- data/lib/gelfd2/gzip_parser.rb +3 -1
- data/lib/gelfd2/parser.rb +14 -16
- data/lib/gelfd2/version.rb +1 -1
- data/lib/gelfd2.rb +5 -5
- data/test/tc_chunked.rb +1 -1
- metadata +7 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 23034a7e5e8a182a7905206efc058592efcd68e0ed3f1e9dd68c76b6913334f9
|
4
|
+
data.tar.gz: 04bc7308323df9d7df559a96eb2de308c870086d9d91f8726b7ac948f9ca5617
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4e72b8034244f003440c4371df0f768e6e02cefad00deb21e76cb01aab13ea4bd664f04a196ff8cc851b50519fd03de321694b99961a5bfd1b28b15dcc685ad
|
7
|
+
data.tar.gz: e452f312c9537f0bb90d00e7bb90d9287b82d239e9d90e9d1fcd4408978b8647ee031ba6f01e3786e703dda5091edef1a6d56ed8c5c52d9d4b1c37f9b7d44465
|
data/.travis.yml
CHANGED
@@ -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/gzip_parser.rb
CHANGED
@@ -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
|
-
|
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/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
|
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.
|
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:
|
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
|
-
|
140
|
-
|
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:
|