logstash-codec-frame 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f2350bf465065c80e70bac20a476ed4c55c20ce0
4
+ data.tar.gz: 8f1f8ba3930610d9ac052a789b0d2386419c2195
5
+ SHA512:
6
+ metadata.gz: aca70558262971363309f04c3f01f59d485593b4c2e49742c01f8f1dfe08148082cd102d3c3431f42361ca21966359ec174d8c7242e12df2e33c96a07629d79f
7
+ data.tar.gz: df112c9a0baa7a563b384005c7e00298380c075eaef584bbda0530308ce1eb315d1dc592f97908bc5f2f3340847e69150efe01c8a4b5fbe31da57619cf20fdb9
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## 2.0.0
2
+ - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
3
+ instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
4
+ - Dependency on logstash-core update to 2.0
5
+
data/DEVELOPER.md ADDED
@@ -0,0 +1,2 @@
1
+ # logstash-codec-example
2
+ Example codec plugin. This should help bootstrap your effort to write your own codec plugin!
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012–2015 Elasticsearch <http://www.elastic.co>
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/NOTICE.TXT ADDED
@@ -0,0 +1,5 @@
1
+ Elasticsearch
2
+ Copyright 2012-2015 Elasticsearch
3
+
4
+ This product includes software developed by The Apache Software
5
+ Foundation (http://www.apache.org/).
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # Logstash Plugin
2
+
3
+ [![Build
4
+ Status](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Codecs/job/logstash-plugin-codec-example-unit/badge/icon)](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Codecs/job/logstash-plugin-codec-example-unit/)
5
+
6
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
7
+
8
+ 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.
9
+
10
+ ## Documentation
11
+
12
+ 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/).
13
+
14
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
15
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
16
+
17
+ ## Need Help?
18
+
19
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
20
+
21
+ ## Developing
22
+
23
+ ### 1. Plugin Developement and Testing
24
+
25
+ #### Code
26
+ - To get started, you'll need JRuby with the Bundler gem installed.
27
+
28
+ - Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization.
29
+
30
+ - Install dependencies
31
+ ```sh
32
+ bundle install
33
+ ```
34
+
35
+ #### Test
36
+
37
+ ```sh
38
+ bundle exec rspec
39
+ ```
40
+
41
+ The Logstash code required to run the tests/specs is specified in the `Gemfile` by the line similar to:
42
+ ```ruby
43
+ gem "logstash", :github => "elasticsearch/logstash", :branch => "1.5"
44
+ ```
45
+ To test against another version or a local Logstash, edit the `Gemfile` to specify an alternative location, for example:
46
+ ```ruby
47
+ gem "logstash", :github => "elasticsearch/logstash", :ref => "master"
48
+ ```
49
+ ```ruby
50
+ gem "logstash", :path => "/your/local/logstash"
51
+ ```
52
+
53
+ Then update your dependencies and run your tests:
54
+
55
+ ```sh
56
+ bundle install
57
+ bundle exec rspec
58
+ ```
59
+
60
+ ### 2. Running your unpublished Plugin in Logstash
61
+
62
+ #### 2.1 Run in a local Logstash clone
63
+
64
+ - Edit Logstash `tools/Gemfile` and add the local plugin path, for example:
65
+ ```ruby
66
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
67
+ ```
68
+ - Update Logstash dependencies
69
+ ```sh
70
+ rake vendor:gems
71
+ ```
72
+ - Run Logstash with your plugin
73
+ ```sh
74
+ bin/logstash -e 'filter {awesome {}}'
75
+ ```
76
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
77
+
78
+ #### 2.2 Run in an installed Logstash
79
+
80
+ - Build your plugin gem
81
+ ```sh
82
+ gem build logstash-filter-awesome.gemspec
83
+ ```
84
+ - Install the plugin from the Logstash home
85
+ ```sh
86
+ bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
87
+ ```
88
+ - Start Logstash and proceed to test the plugin
89
+
90
+ ## Contributing
91
+
92
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
93
+
94
+ 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.
95
+
96
+ It is more important to me that you are able to contribute.
97
+
98
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,68 @@
1
+ # encoding: utf-8
2
+ require "logstash/codecs/base"
3
+ require "logstash/util/charset"
4
+
5
+ # Frame-oriented text data.
6
+ #
7
+ # Decoding behavior: Only whole frame events will be emitted.
8
+ #
9
+ # Encoding behavior: Each event will be emitted with a prefixed <length><delimiter>.
10
+ class LogStash::Codecs::Frame < LogStash::Codecs::Base
11
+ config_name "frame"
12
+
13
+ # Set the desired text format for encoding.
14
+ config :format, :validate => :string
15
+
16
+ # This only affects "plain" format logs since json is `UTF-8` already.
17
+ config :charset, :validate => ::Encoding.name_list, :default => "UTF-8"
18
+
19
+ # Change the delimiter that separates frame length from the data
20
+ config :delimiter, :validate => :string, :default => " "
21
+
22
+ public
23
+ def register
24
+ @buffer = ""
25
+ @offset
26
+ @frame_length
27
+ @converter = LogStash::Util::Charset.new(@charset)
28
+ @converter.logger = @logger
29
+ end
30
+
31
+ public
32
+ def decode(data)
33
+ @buffer += data
34
+ while (nextMessage)
35
+ yield LogStash::Event.new("message" => @converter.convert(@buffer[@offset, @frameLength]))
36
+ @buffer.slice!(0, @offset + @frameLength)
37
+ @offset = nil
38
+ end
39
+ end # def decode
40
+
41
+ public
42
+ def encode(event)
43
+ if event.is_a? LogStash::Event and @format
44
+ @on_event.call(event, encodeFrameLength(event.sprintf(@format)))
45
+ else
46
+ @on_event.call(event, encodeFrameLength(event.to_s))
47
+ end
48
+ end # def encode
49
+
50
+ private
51
+ def nextMessage()
52
+ if (@offset.nil?)
53
+ @offset = @buffer.index(@delimiter);
54
+ if (@offset.nil?)
55
+ return false
56
+ end
57
+ @frameLength = @buffer[0, @offset].to_i
58
+ @offset += @delimiter.length
59
+ end
60
+ return @buffer.length >= @offset + @frameLength
61
+ end # def nextMessage
62
+
63
+ private
64
+ def encodeFrameLength(message)
65
+ return message.length.to_s + @delimiter + message
66
+ end # def encodeFrameLength
67
+
68
+ end # class LogStash::Codecs::Frame
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'logstash-codec-frame'
4
+ s.version = '2.0.0'
5
+ s.licenses = ['Apache License (2.0)']
6
+ s.summary = "Frame-oriented text data."
7
+ 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"
8
+ s.authors = ["Gunter Zeilinger"]
9
+ s.email = 'gunterze@gmail.com'
10
+ s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
11
+ s.require_paths = ["lib"]
12
+
13
+ # Files
14
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
15
+
16
+ # Tests
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+
19
+ # Special flag to let us know this is actually a logstash plugin
20
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "codec" }
21
+
22
+ # Gem dependencies
23
+ s.add_runtime_dependency "logstash-core", ">= 2.0.0.beta2", "< 3.0.0"
24
+
25
+ s.add_development_dependency 'logstash-devutils'
26
+ end
@@ -0,0 +1,79 @@
1
+ # encoding: utf-8
2
+
3
+ require "logstash/devutils/rspec/spec_helper"
4
+ require "logstash/codecs/frame"
5
+ require "logstash/event"
6
+
7
+ describe LogStash::Codecs::Frame do
8
+ subject do
9
+ next LogStash::Codecs::Frame.new
10
+ end
11
+
12
+ context "#encode" do
13
+ let (:event) {LogStash::Event.new({"message" => "hello world", "host" => "test"})}
14
+
15
+ it "should prefix message with length" do
16
+ subject.format = "%{message}"
17
+ expect(subject).to receive(:on_event).once.and_call_original
18
+ subject.on_event do |e, d|
19
+ insist {d} == "11 hello world"
20
+ end
21
+ subject.encode(event)
22
+ end
23
+
24
+ end
25
+
26
+ context "#decode" do
27
+ it "should return an event from an ascii string" do
28
+ decoded = false
29
+ subject.decode("11 hello world") do |e|
30
+ decoded = true
31
+ insist { e.is_a?(LogStash::Event) }
32
+ insist { e["message"] } == "hello world"
33
+ end
34
+ insist { decoded } == true
35
+ end
36
+
37
+ it "should return an event from a valid utf-8 string" do
38
+ subject.decode("7 München") do |e|
39
+ insist { e.is_a?(LogStash::Event) }
40
+ insist { e["message"] } == "München"
41
+ end
42
+ end
43
+
44
+ it "should return 1 event from 2 strings" do
45
+ messages = []
46
+ subject.decode("11 hello") do |e|
47
+ messages << e["message"]
48
+ end
49
+ subject.decode(" world") do |e|
50
+ messages << e["message"]
51
+ end
52
+ insist { messages } == ["hello world" ]
53
+ end
54
+
55
+ it "should return 2 events from 3 strings" do
56
+ messages = []
57
+ subject.decode("11 hello") do |e|
58
+ messages << e["message"]
59
+ end
60
+ subject.decode(" world7") do |e|
61
+ messages << e["message"]
62
+ end
63
+ subject.decode(" München") do |e|
64
+ messages << e["message"]
65
+ end
66
+ insist { messages } == ["hello world", "München"]
67
+ end
68
+
69
+ it "should return 2 events from one string" do
70
+ messages = []
71
+ subject.decode("11 hello world7 München") do |e|
72
+ messages << e["message"]
73
+ end
74
+ insist { messages } == ["hello world", "München"]
75
+ end
76
+
77
+ end
78
+
79
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-codec-frame
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Gunter Zeilinger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-core
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0.beta2
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.0
23
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 2.0.0.beta2
28
+ - - "<"
29
+ - !ruby/object:Gem::Version
30
+ version: 3.0.0
31
+ prerelease: false
32
+ type: :runtime
33
+ - !ruby/object:Gem::Dependency
34
+ name: logstash-devutils
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ prerelease: false
46
+ type: :development
47
+ 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
48
+ email: gunterze@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - CHANGELOG.md
54
+ - DEVELOPER.md
55
+ - Gemfile
56
+ - LICENSE
57
+ - NOTICE.TXT
58
+ - README.md
59
+ - lib/logstash/codecs/frame.rb
60
+ - logstash-codec-frame.gemspec
61
+ - spec/codecs/frame_spec.rb
62
+ homepage: http://www.elastic.co/guide/en/logstash/current/index.html
63
+ licenses:
64
+ - Apache License (2.0)
65
+ metadata:
66
+ logstash_plugin: 'true'
67
+ logstash_group: codec
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.4.8
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Frame-oriented text data.
88
+ test_files:
89
+ - spec/codecs/frame_spec.rb