logstash-output-appsearch 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8319d2bb602b0945ab9dbbd3ebd9fd1f7185a4d31fbdb7ffc55da0bf08439c94
4
+ data.tar.gz: 32993c1731e2d356b1a2c5c7e41961e063a4322cd6220626a08941b1768b453a
5
+ SHA512:
6
+ metadata.gz: 9013619834b2b2b6597d4cd3327479555a3fe16dc0fce3a34751d269025435fbb4480a46009342883d0439de970144dac184843d20500367bebc6d02d9768236
7
+ data.tar.gz: 8f5f4c3a8fd223634ea9cbef34daca2d88a30110afe03c35fc4f0ffd1884a40a13e419275c3ef4125434b5ce40b80b125da548281cf8ed94d37b16c0467a77b4
@@ -0,0 +1,7 @@
1
+ ## 1.0.0.beta1
2
+ - Changed documentation to correct required fields and other information [#2](https://github.com/logstash-plugins/logstash-output-appsearch/pull/2)
3
+ - Added check for correct host, engine and api_key during register [#2](https://github.com/logstash-plugins/logstash-output-appsearch/pull/2)
4
+ - Changed config `store_timestamp` to `timestamp_destination` [#2](https://github.com/logstash-plugins/logstash-output-appsearch/pull/2)
5
+
6
+ ## 0.1.0
7
+ - Initial version
@@ -0,0 +1,10 @@
1
+ The following is a list of people who have contributed ideas, code, bug
2
+ reports, or in general have helped logstash along its way.
3
+
4
+ Contributors:
5
+ * Joao Duarte - jsvduarte@gmail.com
6
+
7
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
8
+ Logstash, and you aren't on the list above and want to be, please let us know
9
+ and we'll make sure you're here. Contributions from folks like you are what make
10
+ open source awesome.
@@ -0,0 +1,2 @@
1
+ # logstash-output-appsearch
2
+ Example output plugin. This should help bootstrap your effort to write your own output plugin!
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ logstash_path = ENV["LOGSTASH_PATH"] || "../../logstash"
6
+ use_logstash_source = ENV["LOGSTASH_SOURCE"] && ENV["LOGSTASH_SOURCE"].to_s == "1"
7
+
8
+ if Dir.exist?(logstash_path) && use_logstash_source
9
+ gem 'logstash-core', :path => "#{logstash_path}/logstash-core"
10
+ gem 'logstash-core-plugin-api', :path => "#{logstash_path}/logstash-core-plugin-api"
11
+ end
data/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Licensed under the Apache License, Version 2.0 (the "License");
2
+ you may not use this file except in compliance with the License.
3
+ You may obtain a copy of the License at
4
+
5
+ http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
@@ -0,0 +1,86 @@
1
+ # Logstash Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
+
5
+ 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.
6
+
7
+ ## Documentation
8
+
9
+ 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/).
10
+
11
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
12
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
13
+
14
+ ## Need Help?
15
+
16
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
17
+
18
+ ## Developing
19
+
20
+ ### 1. Plugin Developement and Testing
21
+
22
+ #### Code
23
+ - To get started, you'll need JRuby with the Bundler gem installed.
24
+
25
+ - 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).
26
+
27
+ - Install dependencies
28
+ ```sh
29
+ bundle install
30
+ ```
31
+
32
+ #### Test
33
+
34
+ - Update your dependencies
35
+
36
+ ```sh
37
+ bundle install
38
+ ```
39
+
40
+ - Run tests
41
+
42
+ ```sh
43
+ bundle exec rspec
44
+ ```
45
+
46
+ ### 2. Running your unpublished Plugin in Logstash
47
+
48
+ #### 2.1 Run in a local Logstash clone
49
+
50
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
51
+ ```ruby
52
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
53
+ ```
54
+ - Install plugin
55
+ ```sh
56
+ bin/logstash-plugin install --no-verify
57
+ ```
58
+ - Run Logstash with your plugin
59
+ ```sh
60
+ bin/logstash -e 'filter {awesome {}}'
61
+ ```
62
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
63
+
64
+ #### 2.2 Run in an installed Logstash
65
+
66
+ 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:
67
+
68
+ - Build your plugin gem
69
+ ```sh
70
+ gem build logstash-filter-awesome.gemspec
71
+ ```
72
+ - Install the plugin from the Logstash home
73
+ ```sh
74
+ bin/logstash-plugin install /your/local/plugin/logstash-filter-awesome.gem
75
+ ```
76
+ - Start Logstash and proceed to test the plugin
77
+
78
+ ## Contributing
79
+
80
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
81
+
82
+ 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.
83
+
84
+ It is more important to the community that you are able to contribute.
85
+
86
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1 @@
1
+ require_relative '../vendor/swiftype-app-search-0.3.0-all.jar'
@@ -0,0 +1,80 @@
1
+ # encoding: utf-8
2
+ require "logstash/outputs/base"
3
+ require 'logstash-output-appsearch_jars.rb'
4
+ java_import com.swiftype.appsearch.Client
5
+
6
+ # An appsearch output that does nothing.
7
+ class LogStash::Outputs::AppSearch < LogStash::Outputs::Base
8
+ config_name "appsearch"
9
+
10
+ config :engine, :validate => :string, :required => true
11
+ config :host, :validate => :string, :required => true
12
+ config :api_key, :validate => :password, :required => true
13
+ config :timestamp_destination, :validate => :string
14
+ config :document_id, :validate => :string
15
+
16
+ public
17
+ def register
18
+ @client = Client.new(@host, @api_key.value)
19
+ @client.get_engine(@engine)
20
+ rescue => e
21
+ if e.message =~ /401/
22
+ raise ::LogStash::ConfigurationError.new("Failed to connect to App Search. Error: 401. Please check your credentials")
23
+ elsif e.message =~ /404/
24
+ raise ::LogStash::ConfigurationError.new("Failed to connect to App Search. Error: 404. Please check if host '#{@host}' is correct and you've created an engine with name '#{@engine}'")
25
+ else
26
+ raise ::LogStash::ConfigurationError.new("Failed to connect to App Search. #{e.message}")
27
+ end
28
+ end
29
+
30
+ public
31
+ def multi_receive(events)
32
+ # because App Search has a limit of 100 documents per bulk
33
+ events.each_slice(100) do |events|
34
+ batch = format_batch(events)
35
+ if @logger.trace?
36
+ @logger.trace("Sending bulk to AppSearch", :size => batch.size, :data => batch.inspect)
37
+ end
38
+ index(batch)
39
+ end
40
+ end
41
+
42
+ private
43
+ def format_batch(events)
44
+ events.map do |event|
45
+ doc = event.to_hash
46
+ # we need to remove default fields that start with "@"
47
+ # since appsearch doesn't accept them
48
+ if @timestamp_destination
49
+ doc[@timestamp_destination] = doc.delete("@timestamp")
50
+ else # delete it
51
+ doc.delete("@timestamp")
52
+ end
53
+ if @document_id
54
+ doc["id"] = event.sprintf(@document_id)
55
+ end
56
+ doc.delete("@version")
57
+ doc
58
+ end
59
+ end
60
+
61
+ def index(documents)
62
+ response = @client.index_documents(@engine, documents)
63
+ report(documents, response)
64
+ rescue => e
65
+ @logger.error("Failed to execute index operation. Retrying..", :exception => e.class, :reason => e.message)
66
+ sleep(1)
67
+ retry
68
+ end
69
+
70
+ def report(documents, response)
71
+ documents.each_with_index do |document, i|
72
+ errors = response[i]["errors"]
73
+ if errors.empty?
74
+ @logger.trace? && @logger.trace("Document was indexed with no errors", :document => document)
75
+ else
76
+ @logger.warn("Document failed to index. Dropping..", :document => document, :errors => errors.to_a)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-output-appsearch'
3
+ s.version = '1.0.0.beta1'
4
+ s.licenses = ['Apache-2.0']
5
+ s.summary = 'Index data to Elastic App Search'
6
+ s.description = 'This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program'
7
+ s.homepage = 'https://elastic.co'
8
+ s.authors = ['Joao Duarte', 'Elastic']
9
+ s.email = 'info@elastic.co'
10
+ s.require_paths = ['lib']
11
+
12
+ # Files
13
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
14
+ # Tests
15
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
+
17
+ # Special flag to let us know this is actually a logstash plugin
18
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
19
+
20
+ s.add_development_dependency 'jar-dependencies', '~> 0.3.2'
21
+
22
+ # Gem dependencies
23
+ s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
24
+ s.add_runtime_dependency "logstash-codec-plain"
25
+ s.add_development_dependency "logstash-devutils"
26
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/outputs/appsearch"
4
+ require "logstash/codecs/plain"
5
+ require "logstash/event"
6
+
7
+ describe LogStash::Outputs::AppSearch do
8
+ let(:sample_event) { LogStash::Event.new }
9
+ let(:host) { "test-host" }
10
+ let(:api_key) { "my_key" }
11
+ let(:engine) { "test-engine" }
12
+ let(:output) { described_class.new("host" => host, "api_key" => api_key, "engine" => engine) }
13
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-appsearch
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.beta1
5
+ platform: ruby
6
+ authors:
7
+ - Joao Duarte
8
+ - Elastic
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2018-10-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.2
20
+ name: jar-dependencies
21
+ prerelease: false
22
+ type: :development
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 0.3.2
28
+ - !ruby/object:Gem::Dependency
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ name: logstash-core-plugin-api
35
+ prerelease: false
36
+ type: :runtime
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '2.0'
42
+ - !ruby/object:Gem::Dependency
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ name: logstash-codec-plain
49
+ prerelease: false
50
+ type: :runtime
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ name: logstash-devutils
63
+ prerelease: false
64
+ type: :development
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ description: This gem is a Logstash plugin required to be installed on top of the
71
+ Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
72
+ gem is not a stand-alone program
73
+ email: info@elastic.co
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - CHANGELOG.md
79
+ - CONTRIBUTORS
80
+ - DEVELOPER.md
81
+ - Gemfile
82
+ - LICENSE
83
+ - README.md
84
+ - lib/logstash-output-appsearch_jars.rb
85
+ - lib/logstash/outputs/appsearch.rb
86
+ - logstash-output-appsearch.gemspec
87
+ - spec/outputs/appsearch_spec.rb
88
+ - vendor/swiftype-app-search-0.3.0-all.jar
89
+ homepage: https://elastic.co
90
+ licenses:
91
+ - Apache-2.0
92
+ metadata:
93
+ logstash_plugin: 'true'
94
+ logstash_group: output
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">"
107
+ - !ruby/object:Gem::Version
108
+ version: 1.3.1
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.7.6
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Index data to Elastic App Search
115
+ test_files:
116
+ - spec/outputs/appsearch_spec.rb