logstash-codec-es_bulk 0.1.1

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: 056be7360d412c0dc082aee477b91bbd3f9826fa
4
+ data.tar.gz: 1b86efe8e257a10e308bc43e5fa189fcb212fb92
5
+ SHA512:
6
+ metadata.gz: 8023e5e0ea12fa1e83dc845bd1020c58e57007ec6a8c79b5835f22e6ae33539d405f2ffb13e363f5b9113ca0da552578788c510c1e1c1ec145fc498c5f259d19
7
+ data.tar.gz: b44553d7e61caec35d6227e3a903af593c540787aaa00759e326ee596b9076f43ab5e95f1f912d8b4031bd8703c327f9605548286342bb089a1db7d623b352f0
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ Gemfile.lock
3
+ .bundle
4
+ vendor
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+ gem "logstash", :github => "elasticsearch/logstash", :branch => "1.5"
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,6 @@
1
+ @files=[]
2
+
3
+ task :default do
4
+ system("rake -T")
5
+ end
6
+ require "logstash/devutils/rake"
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+ require "logstash/codecs/base"
3
+ require "logstash/codecs/line"
4
+ require "logstash/json"
5
+
6
+ # This codec will decode the Elasticsearch bulk format into
7
+ # individual events, plus metadata into the `@metadata` field.
8
+ #
9
+ # Encoding is not supported at this time as the Elasticsearch
10
+ # output submits Logstash events in bulk format.
11
+ class LogStash::Codecs::ESBulk < LogStash::Codecs::Base
12
+ config_name "es_bulk"
13
+
14
+ milestone 1
15
+
16
+ public
17
+ def initialize(params={})
18
+ super(params)
19
+ @lines = LogStash::Codecs::Line.new
20
+ @lines.charset = "UTF-8"
21
+ end
22
+
23
+ public
24
+ def decode(data)
25
+ state = :initial
26
+ metadata = Hash.new
27
+ @lines.decode(data) do |bulk|
28
+ begin
29
+ line = LogStash::Json.load(bulk["message"])
30
+ case state
31
+ when :metadata
32
+ event = LogStash::Event.new(line)
33
+ event["@metadata"] = metadata
34
+ yield event
35
+ state = :initial
36
+ when :initial
37
+ metadata = line[line.keys[0]]
38
+ metadata["action"] = line.keys[0].to_s
39
+ state = :metadata
40
+ if line.keys[0] == 'delete'
41
+ event = LogStash::Event.new()
42
+ event["@metadata"] = metadata
43
+ yield event
44
+ state = :initial
45
+ end
46
+ end
47
+ rescue LogStash::Json::ParserError => e
48
+ @logger.error("JSON parse failure. ES Bulk messages must in be UTF-8 JSON", :error => e, :data => data)
49
+ end
50
+ end
51
+ end # def decode
52
+
53
+ end # class LogStash::Codecs::ESBulk
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'logstash-codec-es_bulk'
4
+ s.version = '0.1.1'
5
+ s.licenses = ['Apache License (2.0)']
6
+ s.summary = "This codec decodes messages received in the Elasticsearch bulk format"
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 = ["Elasticsearch"]
9
+ s.email = 'aaron.mildenstein@elasticsearch.com'
10
+ s.homepage = "http://www.elasticsearch.org/guide/en/logstash/current/index.html"
11
+ s.require_paths = ["lib"]
12
+
13
+ # Files
14
+ s.files = `git ls-files`.split($\)+::Dir.glob('vendor/*')
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', '>= 1.4.0', '< 2.0.0'
24
+ s.add_runtime_dependency 'logstash-codec-line'
25
+
26
+ s.add_development_dependency 'logstash-devutils'
27
+ end
@@ -0,0 +1,57 @@
1
+ require "logstash/codecs/es_bulk"
2
+ require "logstash/event"
3
+ require "insist"
4
+
5
+ describe LogStash::Codecs::ESBulk do
6
+ subject do
7
+ next LogStash::Codecs::ESBulk.new
8
+ end
9
+
10
+ context "#decode" do
11
+ it "should return 4 events from json data" do
12
+ data = <<-HERE
13
+ { "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
14
+ { "field1" : "value1" }
15
+ { "delete" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }
16
+ { "create" : { "_index" : "test", "_type" : "type1", "_id" : "3" } }
17
+ { "field1" : "value3" }
18
+ { "update" : {"_id" : "1", "_type" : "type1", "_index" : "index1"} }
19
+ { "doc" : {"field2" : "value2"} }
20
+ HERE
21
+
22
+ count = 0
23
+ subject.decode(data) do |event|
24
+ case count
25
+ when 0
26
+ insist { event['@metadata']['_id'] } == "1"
27
+ insist { event['@metadata']['action'] } == "index"
28
+ insist { event['field1'] } == "value1"
29
+ when 1
30
+ insist { event['@metadata']['_id'] } == "2"
31
+ insist { event['@metadata']['action'] } == "delete"
32
+ when 2
33
+ insist { event['@metadata']['_id'] } == "3"
34
+ insist { event['@metadata']['action'] } == "create"
35
+ insist { event['field1'] } == "value3"
36
+ when 3
37
+ insist { event['@metadata']['_id'] } == "1"
38
+ insist { event['@metadata']['action'] } == "update"
39
+ insist { event['doc']['field2'] } == "value2"
40
+ end
41
+ count += 1
42
+ end
43
+ insist { count } == 4
44
+ end
45
+ end
46
+
47
+ context "fail to process non-bulk event then continue" do
48
+ it "continues after a fail" do
49
+ decoded = false
50
+ subject.decode("something that isn't a bulk event\n") do |event|
51
+ decoded = true
52
+ end
53
+ insist { decoded } == false
54
+ end
55
+ end
56
+
57
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-codec-es_bulk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Elasticsearch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.0
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.0
23
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: 1.4.0
28
+ - - <
29
+ - !ruby/object:Gem::Version
30
+ version: 2.0.0
31
+ prerelease: false
32
+ type: :runtime
33
+ - !ruby/object:Gem::Dependency
34
+ name: logstash-codec-line
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: :runtime
47
+ - !ruby/object:Gem::Dependency
48
+ name: logstash-devutils
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ prerelease: false
60
+ type: :development
61
+ 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
62
+ email: aaron.mildenstein@elasticsearch.com
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - .gitignore
68
+ - Gemfile
69
+ - LICENSE
70
+ - Rakefile
71
+ - lib/logstash/codecs/es_bulk.rb
72
+ - logstash-codec-es_bulk.gemspec
73
+ - spec/codecs/es_bulk_spec.rb
74
+ homepage: http://www.elasticsearch.org/guide/en/logstash/current/index.html
75
+ licenses:
76
+ - Apache License (2.0)
77
+ metadata:
78
+ logstash_plugin: 'true'
79
+ logstash_group: codec
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.4
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: This codec decodes messages received in the Elasticsearch bulk format
100
+ test_files:
101
+ - spec/codecs/es_bulk_spec.rb