logstash-codec-lineeof 0.1.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: 098a38756136c401d608c5b490615ccbec1d97b9
4
+ data.tar.gz: f6494f73ab63c8748e1a01439b205c6296daa779
5
+ SHA512:
6
+ metadata.gz: 8e72f6ef34e30231afbae0e52e15831e1aca92787f90b2fca4474226811285dc2156804bcc7f5726f60fd6d93c67ee6f250d926c8214d69d7fad9310d31c8057
7
+ data.tar.gz: f328da1975307c4517ab8b9eb6dfe3c9f742e5951a89b001ba4349a2c53aedb0c55d31621be37e6bcdf1445c5cc5fc15692788e9484e476b3c6985da201a0a46
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ Gemfile.lock
2
+ .ruby-version
3
+ *.gem
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-2014 Elasticsearch <http://www.elasticsearch.org>
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/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ @files=[]
2
+
3
+ task :default do
4
+ system("rake -T")
5
+ end
6
+
7
+ require "logstash/devutils/rake"
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+ require "logstash/codecs/base"
3
+ require "logstash/util/charset"
4
+
5
+ # Line-oriented text data with EOF(end of file) recognition.
6
+ #
7
+ # Decoding behavior: Only whole line events will be emitted.
8
+ #
9
+ # Encoding behavior: Each event will be emitted with a trailing newline.
10
+ class LogStash::Codecs::LineEOF < LogStash::Codecs::Base
11
+ config_name "lineeof"
12
+
13
+ # Set the desired text format for encoding.
14
+ config :format, :validate => :string
15
+
16
+ # The character encoding used in this input. Examples include "UTF-8"
17
+ # and "cp1252"
18
+ #
19
+ # This setting is useful if your log files are in Latin-1 (aka cp1252)
20
+ # or in another character set other than UTF-8.
21
+ #
22
+ # This only affects "plain" format logs since json is UTF-8 already.
23
+ config :charset, :validate => ::Encoding.name_list, :default => "UTF-8"
24
+
25
+ public
26
+ def register
27
+ require "logstash/util/buftok"
28
+ @buffer = FileWatch::BufferedTokenizer.new
29
+ @converter = LogStash::Util::Charset.new(@charset)
30
+ @converter.logger = @logger
31
+ end
32
+
33
+ public
34
+ def decode(data)
35
+ lines = @buffer.extract(data)
36
+ lines.each_with_index do |line, index|
37
+ event = LogStash::Event.new("message" => @converter.convert(line))
38
+ #if end of file is reached?
39
+ event.tag("eof") if index == lines.size - 1 && data.length < 32768
40
+ yield event
41
+ end
42
+ end # def decode
43
+
44
+ public
45
+ def flush(&block)
46
+ remainder = @buffer.flush
47
+ if !remainder.empty?
48
+ block.call(LogStash::Event.new({"message" => remainder}))
49
+ end
50
+ end
51
+
52
+ public
53
+ def encode(data)
54
+ if data.is_a? LogStash::Event and @format
55
+ @on_event.call(data.sprintf(@format) + "\n")
56
+ else
57
+ @on_event.call(data.to_s + "\n")
58
+ end
59
+ end # def encode
60
+
61
+ end # class LogStash::Codecs::Plain
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'logstash-codec-lineeof'
4
+ s.version = '0.1.0'
5
+ s.licenses = ['Apache License (2.0)']
6
+ s.summary = "Line-oriented text data with EOF(end of file) recognition."
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 = ["Signify"]
9
+ s.email = 'dietmar@signifydata.com'
10
+ s.homepage = "http://www.signifydata.com"
11
+ s.require_paths = ["lib"]
12
+
13
+ # Files
14
+ s.files = `git ls-files`.split($\)
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', '>= 1.4.0', '< 2.0.0'
24
+
25
+ s.add_development_dependency 'logstash-devutils'
26
+ end
27
+
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+
3
+ require "logstash/devutils/rspec/spec_helper"
4
+ require "logstash/codecs/line"
5
+ require "logstash/event"
6
+
7
+ describe LogStash::Codecs::Line do
8
+ subject do
9
+ next LogStash::Codecs::Line.new
10
+ end
11
+
12
+ context "#encode" do
13
+ let (:event) {LogStash::Event.new({"message" => "hello world", "host" => "test"})}
14
+
15
+ it "should return a default date formatted line" do
16
+ expect(subject).to receive(:on_event).once.and_call_original
17
+ subject.on_event do |e, d|
18
+ insist {d} == event.to_s + "\n"
19
+ end
20
+ subject.encode(event)
21
+ end
22
+
23
+ it "should respect the supplied format" do
24
+ format = "%{host}"
25
+ subject.format = format
26
+ expect(subject).to receive(:on_event).once.and_call_original
27
+ subject.on_event do |e, d|
28
+ insist {d} == event.sprintf(format) + "\n"
29
+ end
30
+ subject.encode(event)
31
+ end
32
+ end
33
+
34
+ context "#decode" do
35
+ it "should return an event from an ascii string" do
36
+ decoded = false
37
+ subject.decode("hello world\n") do |e|
38
+ decoded = true
39
+ insist { e.is_a?(LogStash::Event) }
40
+ insist { e["message"] } == "hello world"
41
+ end
42
+ insist { decoded } == true
43
+ end
44
+
45
+ it "should return an event from a valid utf-8 string" do
46
+ subject.decode("München\n") do |e|
47
+ insist { e.is_a?(LogStash::Event) }
48
+ insist { e["message"] } == "München"
49
+ end
50
+ end
51
+ end
52
+
53
+ context "#flush" do
54
+ it "should convert charsets" do
55
+ garbage = [0xD0].pack("C")
56
+ subject.decode(garbage) do |e|
57
+ fail "Should not get here."
58
+ end
59
+ count = 0
60
+ subject.flush do |event|
61
+ count += 1
62
+ insist { event["message"].encoding } == Encoding::UTF_8
63
+ end
64
+ insist { count } == 1
65
+ end
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-codec-lineeof
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Signify
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - '>='
17
+ - !ruby/object:Gem::Version
18
+ version: 1.4.0
19
+ - - <
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.0
22
+ name: logstash-core
23
+ prerelease: false
24
+ type: :runtime
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.4.0
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ name: logstash-devutils
40
+ prerelease: false
41
+ type: :development
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
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: dietmar@signifydata.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE
56
+ - Rakefile
57
+ - lib/logstash/codecs/lineeof.rb
58
+ - logstash-codec-lineeof.gemspec
59
+ - spec/codecs/lineeof_spec.rb
60
+ homepage: http://www.signifydata.com
61
+ licenses:
62
+ - Apache License (2.0)
63
+ metadata:
64
+ logstash_plugin: 'true'
65
+ logstash_group: codec
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.1.9
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Line-oriented text data with EOF(end of file) recognition.
86
+ test_files:
87
+ - spec/codecs/lineeof_spec.rb