Skip to content

Instantly share code, notes, and snippets.

@sameera207
Forked from morhekil/json_file_gz.rb
Created January 13, 2014 06:20
Show Gist options
  • Save sameera207/8395517 to your computer and use it in GitHub Desktop.
Save sameera207/8395517 to your computer and use it in GitHub Desktop.
# encoding: utf-8
require 'logstash/codecs/base'
class LogStash::Codecs::JsonFileGz < LogStash::Codecs::Base
config_name 'json_file_gz'
milestone 1
public
def register
require 'zlib'
end
def decode(path)
begin
json_data = Zlib::GzipReader.open(path) { |f| f.read }
rescue Zlib::GzipFile::Error => e
@logger.info('Gzip failure, skipped', :error => e, :data => data)
end
begin
yield LogStash::Event.new(JSON.parse(json_data)) if json_data
rescue JSON::ParserError => e
@logger.info('JSON parse failure. Falling back to plain-text', :error => e, :data => data)
yield LogStash::Event.new('message' => data)
end
end # def decode
def encode(data)
raise NotImplementedError
end # def encode
end # class LogStash::Codecs::JsonFileGz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment