From bd3c3afa453a089c7f0ac7cb5c5cdc1efcf97046 Mon Sep 17 00:00:00 2001 From: Daniel Dao Date: Mon, 25 Jan 2016 17:10:01 +0000 Subject: [PATCH] remove uncompressed data magic header default to returning uncompressed data without checking for magic header for compliant with graylog2 server. Relevant piece for graylog2 server is at https://github.com/Graylog2/graylog2-server/blob/edd1a66a2f9924e39b217df4c94327a86b8fecab/graylog2-server/src/main/java/org/graylog2/inputs/codecs/gelf/GELFMessage.java#L147 Signed-off-by: Daniel Dao --- lib/gelfd/parser.rb | 5 ++--- test/fixtures/unchunked.uc | 2 +- test/tc_uncompressed.rb | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/gelfd/parser.rb b/lib/gelfd/parser.rb index c545725..87716e9 100644 --- a/lib/gelfd/parser.rb +++ b/lib/gelfd/parser.rb @@ -10,10 +10,9 @@ def self.parse(data) ChunkedParser.parse(data) when GZIP_MAGIC GzipParser.parse(data) - when UNCOMPRESSED_MAGIC - data[2..-1] else - raise UnknownHeaderError, "Could not find parser for header: #{header.unpack('C*').to_s}" + # by default assume the payload to be "raw, uncompressed" GELF, parsing will fail if it's malformed. + data end end diff --git a/test/fixtures/unchunked.uc b/test/fixtures/unchunked.uc index bb58524..f0b46ad 100644 --- a/test/fixtures/unchunked.uc +++ b/test/fixtures/unchunked.uc @@ -1 +1 @@ -<{"this":"is","my":"boomstick"} \ No newline at end of file +{"this":"is","my":"boomstick"} \ No newline at end of file diff --git a/test/tc_uncompressed.rb b/test/tc_uncompressed.rb index 8780a75..8e8feb5 100644 --- a/test/tc_uncompressed.rb +++ b/test/tc_uncompressed.rb @@ -5,7 +5,7 @@ class TestUncompressedGelf < Test::Unit::TestCase FIXTURE_PATH = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures')) - + def test_uncompressed_message data = File.open("#{FIXTURE_PATH}/unchunked.uc", "rb") {|f| f.read} t = Gelfd::Parser.parse(data)