From ae48e435770a708bb2954fc27d3be3524e6eed27 Mon Sep 17 00:00:00 2001 From: bfloyd Date: Tue, 12 Jan 2016 10:21:17 -0500 Subject: [PATCH] First commit of gzip codec --- .gitignore | 3 +++ CHANGELOG.md | 16 ++++++++++++++++ CONTRIBUTORS | 17 +++++++++++++++++ Gemfile | 2 ++ LICENSE | 13 +++++++++++++ NOTICE.TXT | 5 +++++ README.md | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- Rakefile | 7 +++++++ lib/logstash/codecs/gzip.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ logstash-codec-gzip.gemspec | 27 +++++++++++++++++++++++++++ 10 files changed, 221 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 CONTRIBUTORS create mode 100644 Gemfile create mode 100644 LICENSE create mode 100644 NOTICE.TXT create mode 100644 Rakefile create mode 100644 lib/logstash/codecs/gzip.rb create mode 100644 logstash-codec-gzip.gemspec diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0c14ba2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.gem +Gemfile.lock +.bundle diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..32b8d35 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,16 @@ +## 2.0.4 + - Reduce the size of the gem by removing the vendor files + +## 2.0.3 + - fixed a spec, no change in functionality + +## 2.0.0 + - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully, + instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895 + - Dependency on logstash-core update to 2.0 + +## 1.1.0 + - Handle scalar types (string/number) and be more defensive about crashable errors + +## 1.0.1 + - Handle JSON arrays at source root by emitting multiple events diff --git a/CONTRIBUTORS b/CONTRIBUTORS new file mode 100644 index 0000000..a87840d --- /dev/null +++ b/CONTRIBUTORS @@ -0,0 +1,17 @@ +The following is a list of people who have contributed ideas, code, bug +reports, or in general have helped logstash along its way. + +Contributors: +* Colin Surprenant (colinsurprenant) +* Jordan Sissel (jordansissel) +* João Duarte (jsvd) +* Kurt Hurtado (kurtado) +* Nick Ethier (nickethier) +* Pier-Hugues Pellerin (ph) +* Richard Pijnenburg (electrical) +* Tal Levy (talevy) + +Note: If you've sent us patches, bug reports, or otherwise contributed to +Logstash, and you aren't on the list above and want to be, please let us know +and we'll make sure you're here. Contributions from folks like you are what make +open source awesome. diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..d926697 --- /dev/null +++ b/Gemfile @@ -0,0 +1,2 @@ +source 'https://rubygems.org' +gemspec \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8026afd --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ +Copyright (c) 2012–2015 Elasticsearch + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/NOTICE.TXT b/NOTICE.TXT new file mode 100644 index 0000000..0b8a947 --- /dev/null +++ b/NOTICE.TXT @@ -0,0 +1,5 @@ +Elasticsearch +Copyright 2012-2015 Elasticsearch + +This product includes software developed by The Apache Software +Foundation (http://www.apache.org/). \ No newline at end of file diff --git a/README.md b/README.md index cdf0376..d82d050 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,89 @@ -# logstash-codec-gzip -This codec may be used to decode and encode gzip encoded data +# Logstash Plugin + +[![Build +Status](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Codecs/job/logstash-plugin-codec-json-unit/badge/icon)](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Codecs/job/logstash-plugin-codec-json-unit/) + +This is a plugin for [Logstash](https://github.com/elastic/logstash). + +It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way. + +## Documentation + +Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/). + +- For formatting code or config example, you can use the asciidoc `[source,ruby]` directive +- For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide + +## Need Help? + +Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum. + +## Developing + +### 1. Plugin Developement and Testing + +#### Code +- To get started, you'll need JRuby with the Bundler gem installed. + +- Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example). + +- Install dependencies +```sh +bundle install +``` + +#### Test + +- Update your dependencies + +```sh +bundle install +``` + +- Run tests + +```sh +bundle exec rspec +``` + +### 2. Running your unpublished Plugin in Logstash + +#### 2.1 Run in a local Logstash clone + +- Edit Logstash `Gemfile` and add the local plugin path, for example: +```ruby +gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome" +``` +- Install plugin +```sh +bin/plugin install --no-verify +``` +- Run Logstash with your plugin +```sh +bin/logstash -e 'filter {awesome {}}' +``` +At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash. + +#### 2.2 Run in an installed Logstash + +You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using: + +- Build your plugin gem +```sh +gem build logstash-filter-awesome.gemspec +``` +- Install the plugin from the Logstash home +```sh +bin/plugin install /your/local/plugin/logstash-filter-awesome.gem +``` +- Start Logstash and proceed to test the plugin + +## Contributing + +All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin. + +Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here. + +It is more important to the community that you are able to contribute. + +For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file. \ No newline at end of file diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..4f4b858 --- /dev/null +++ b/Rakefile @@ -0,0 +1,7 @@ +@files=[] + +task :default do + system("rake -T") +end + +require "logstash/devutils/rake" diff --git a/lib/logstash/codecs/gzip.rb b/lib/logstash/codecs/gzip.rb new file mode 100644 index 0000000..90c01fd --- /dev/null +++ b/lib/logstash/codecs/gzip.rb @@ -0,0 +1,42 @@ +# encoding: utf-8 +require "logstash/codecs/base" +require "logstash/util/charset" +require "zlib" +require "stringio" + +# This codec may be used to decode gzip data from string. +# +# If this codec recieves a payload from an input that is not valid GZIP, then +# it will fall back to plain text and add a tag `_gzipparsefailure`. Upon a GZIP +# failure, the payload will be stored in the `message` field. +class LogStash::Codecs::GZIP < LogStash::Codecs::Base + config_name "gzip" + + # The character encoding used in this codec. Examples include "UTF-8" and + # "CP1252". + # + # GZIP requires valid UTF-8 strings, but in some cases, software that + # emits GZIP does so in another encoding (nxlog, for example). In + # weird cases like this, you can set the `charset` setting to the + # actual encoding of the text and Logstash will convert it for you. + # + # For nxlog users, you may to set this to "CP1252". + config :charset, :validate => ::Encoding.name_list, :default => "UTF-8" + + public + def register + @converter = LogStash::Util::Charset.new(@charset) + @converter.logger = @logger + end + + public + def decode(data) + begin + decoded = Zlib::GzipReader.new(StringIO.new(data)).read + yield LogStash::Event.new("message" => @converter.convert(decoded)) + rescue Zlib::Error, Zlib::GzipFile::Error=> e + @logger.info? && @logger.info("GZIP parse failure. Falling back to plain-text", :error => e, :data => data) + yield LogStash::Event.new("message" => data, "tags" => ["_gzipparsefailure"]) + end + end # def decode +end # class LogStash::Codecs::JSON diff --git a/logstash-codec-gzip.gemspec b/logstash-codec-gzip.gemspec new file mode 100644 index 0000000..209d425 --- /dev/null +++ b/logstash-codec-gzip.gemspec @@ -0,0 +1,27 @@ +Gem::Specification.new do |s| + + s.name = 'logstash-codec-gzip' + s.version = '2.0.4' + s.licenses = ['Apache License (2.0)'] + s.summary = "This codec may be used to decode (via inputs) and encode (via outputs) full gzip messages" + s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program" + s.authors = ["Elastic"] + s.email = 'info@elastic.co' + s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html" + s.require_paths = ["lib"] + + # Files + s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT'] + + # Tests + s.test_files = s.files.grep(%r{^(test|spec|features)/}) + + # Special flag to let us know this is actually a logstash plugin + s.metadata = { "logstash_plugin" => "true", "logstash_group" => "codec" } + + # Gem dependencies + s.add_runtime_dependency "logstash-core", "< 2.0.0" + + s.add_development_dependency 'logstash-devutils' +end + -- libgit2 1.7.2