logstash-output-elasticsearch_http 0.0.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: 1ef882b3adf307f0b10e05ce2e0038cf0dd4cb24
4
+ data.tar.gz: 6a8ca5dad1c65cb9c884afa56df2e74b7265e05a
5
+ SHA512:
6
+ metadata.gz: 98b122b9caa2a690036ec9cbaa867e1d838bbb6686fdb3d277014d851797e7059350ae5da5173e237bfbbfaf13bd03aec48e198f747194adaaffe4c3bdb34b9b
7
+ data.tar.gz: fdd7230e50f7f219d0a15a51204908db1969d63d6ae8801c58cf86372bf506aed9d5fdcadb8acc0a05d90cf1275c9607b6c58d36007cafafba93c394dfc251c5
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ Gemfile.lock
3
+ .bundle
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.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/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # Please read!
2
+ ## This plugin is being deprecated!
3
+ This plugin exist to provide an easy upgrade path to the new [elasticsearch](http://github.com/logstash-plugins/logstash-output-elasticsearch/) output.
4
+ This means that **new pull requests will not be accepted** here, please direct any issues to the new elasticsearch output.
5
+
6
+ # Logstash Plugin
7
+
8
+ This is a plugin for [Logstash](https://github.com/elasticsearch/logstash).
9
+
10
+ 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.
11
+
12
+ ## Documentation
13
+
14
+ 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.elasticsearch.org/guide/en/logstash/current/).
15
+
16
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
17
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elasticsearch/docs#asciidoc-guide
18
+
19
+ ## Need Help?
20
+
21
+ Need help? Try #logstash on freenode IRC or the logstash-users@googlegroups.com mailing list.
22
+
23
+ ## Developing
24
+
25
+ ### 1. Plugin Developement and Testing
26
+
27
+ #### Code
28
+ - To get started, you'll need JRuby with the Bundler gem installed.
29
+
30
+ - Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization.
31
+
32
+ - Install dependencies
33
+ ```sh
34
+ bundle install
35
+ ```
36
+
37
+ #### Test
38
+
39
+ ```sh
40
+ bundle exec rspec
41
+ ```
42
+
43
+ The Logstash code required to run the tests/specs is specified in the `Gemfile` by the line similar to:
44
+ ```ruby
45
+ gem "logstash", :github => "elasticsearch/logstash", :branch => "1.5"
46
+ ```
47
+ To test against another version or a local Logstash, edit the `Gemfile` to specify an alternative location, for example:
48
+ ```ruby
49
+ gem "logstash", :github => "elasticsearch/logstash", :ref => "master"
50
+ ```
51
+ ```ruby
52
+ gem "logstash", :path => "/your/local/logstash"
53
+ ```
54
+
55
+ Then update your dependencies and run your tests:
56
+
57
+ ```sh
58
+ bundle install
59
+ bundle exec rspec
60
+ ```
61
+
62
+ ### 2. Running your unpublished Plugin in Logstash
63
+
64
+ #### 2.1 Run in a local Logstash clone
65
+
66
+ - Edit Logstash `tools/Gemfile` and add the local plugin path, for example:
67
+ ```ruby
68
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
69
+ ```
70
+ - Update Logstash dependencies
71
+ ```sh
72
+ rake vendor:gems
73
+ ```
74
+ - Run Logstash with your plugin
75
+ ```sh
76
+ bin/logstash -e 'filter {awesome {}}'
77
+ ```
78
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
79
+
80
+ #### 2.2 Run in an installed Logstash
81
+
82
+ - Build your plugin gem
83
+ ```sh
84
+ gem build logstash-filter-awesome.gemspec
85
+ ```
86
+ - Install the plugin from the Logstash home
87
+ ```sh
88
+ bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
89
+ ```
90
+ - Start Logstash and proceed to test the plugin
91
+
92
+ ## Contributing
93
+
94
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
95
+
96
+ 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.
97
+
98
+ It is more important to me that you are able to contribute.
99
+
100
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "logstash/devutils/rake"
@@ -0,0 +1,154 @@
1
+ # encoding: utf-8
2
+ require "logstash/outputs/elasticsearch"
3
+ require "logstash/codecs/base"
4
+ require "logstash/namespace"
5
+ require "forwardable"
6
+
7
+ # This plugin is deprecated in favor of using elasticsearch output and the http protocol
8
+ # Please update your current configuration!
9
+ #
10
+ # .Example
11
+ # [source,ruby]
12
+ # elasticsearch {
13
+ # protocol => 'http'
14
+ # host => '127.0.0.1'
15
+ # }
16
+ class LogStash::Outputs::ElasticsearchHTTP < LogStash::Outputs::Base
17
+ extend Forwardable
18
+
19
+ config_name "elasticsearch_http"
20
+
21
+ # The index to write events to. This can be dynamic using the %{foo} syntax.
22
+ # The default value will partition your indices by day so you can more easily
23
+ # delete old data or only search specific date ranges.
24
+ config :index, :validate => :string, :default => "logstash-%{+YYYY.MM.dd}"
25
+
26
+ # The index type to write events to. Generally you should try to write only
27
+ # similar events to the same 'type'. String expansion '%{foo}' works here.
28
+ config :index_type, :validate => :string
29
+
30
+ # Starting in Logstash 1.3 (unless you set option "manage_template" to false)
31
+ # a default mapping template for Elasticsearch will be applied, if you do not
32
+ # already have one set to match the index pattern defined (default of
33
+ # "logstash-%{+YYYY.MM.dd}"), minus any variables. For example, in this case
34
+ # the template will be applied to all indices starting with logstash-*
35
+ #
36
+ # If you have dynamic templating (e.g. creating indices based on field names)
37
+ # then you should set "manage_template" to false and use the REST API to upload
38
+ # your templates manually.
39
+ config :manage_template, :validate => :boolean, :default => true
40
+
41
+ # This configuration option defines how the template is named inside Elasticsearch.
42
+ # Note that if you have used the template management features and subsequently
43
+ # change this you will need to prune the old template manually, e.g.
44
+ # curl -XDELETE <http://localhost:9200/_template/OldTemplateName?pretty>
45
+ # where OldTemplateName is whatever the former setting was.
46
+ config :template_name, :validate => :string, :default => "logstash"
47
+
48
+ # You can set the path to your own template here, if you so desire.
49
+ # If not the included template will be used.
50
+ config :template, :validate => :path
51
+
52
+ # Overwrite the current template with whatever is configured
53
+ # in the template and template_name directives.
54
+ config :template_overwrite, :validate => :boolean, :default => false
55
+
56
+ # The hostname or IP address to reach your Elasticsearch server.
57
+ config :host, :validate => :string, :required => true
58
+
59
+ # The port for Elasticsearch HTTP interface to use.
60
+ config :port, :validate => :number, :default => 9200
61
+
62
+ # The HTTP Basic Auth username used to access your elasticsearch server.
63
+ config :user, :validate => :string, :default => nil
64
+
65
+ # The HTTP Basic Auth password used to access your elasticsearch server.
66
+ config :password, :validate => :password, :default => nil
67
+
68
+ # This plugin uses the bulk index api for improved indexing performance.
69
+ # To make efficient bulk api calls, we will buffer a certain number of
70
+ # events before flushing that out to Elasticsearch. This setting
71
+ # controls how many events will be buffered before sending a batch
72
+ # of events.
73
+ config :flush_size, :validate => :number, :default => 100
74
+
75
+ # The amount of time since last flush before a flush is forced.
76
+ #
77
+ # This setting helps ensure slow event rates don't get stuck in Logstash.
78
+ # For example, if your `flush_size` is 100, and you have received 10 events,
79
+ # and it has been more than `idle_flush_time` seconds since the last flush,
80
+ # logstash will flush those 10 events automatically.
81
+ #
82
+ # This helps keep both fast and slow log streams moving along in
83
+ # near-real-time.
84
+ config :idle_flush_time, :validate => :number, :default => 1
85
+
86
+ # The document ID for the index. Useful for overwriting existing entries in
87
+ # Elasticsearch with the same ID.
88
+ config :document_id, :validate => :string, :default => nil
89
+
90
+ # Set the type of Elasticsearch replication to use. If async
91
+ # the index request to Elasticsearch to return after the primary
92
+ # shards have been written. If sync (default), index requests
93
+ # will wait until the primary and the replica shards have been
94
+ # written.
95
+ config :replication, :validate => ['async', 'sync'], :default => 'sync'
96
+
97
+ def_delegators :@elasticsearch_output, :teardown, :register, :receive
98
+
99
+ def initialize(options = {})
100
+ super(options)
101
+
102
+ @logger = Cabin::Channel.get(LogStash)
103
+ warning_message = []
104
+
105
+ warning_message << "The elasticsearch_http output is replaced by the elasticsearch output and will be removed in a future version of Logstash"
106
+
107
+ if options.delete("replication") == "async"
108
+ warning_message << "Ignoring the async replication option, this option is not recommended and not supported by this plugin"
109
+ end
110
+
111
+ # transform configuration
112
+ options["host"] = [options['host']]
113
+ options["protocol"] = "http"
114
+
115
+
116
+ # Generate a migration configuration for the new elasticsearch output
117
+ # using the current settings as the base.
118
+ warning_message << "The following configuration example is based on the options you specified and should work:"
119
+ warning_message << "elasticsearch {"
120
+
121
+ @config.each do |option, value|
122
+ if display_option?(option, value)
123
+ warning_message << "#{option} => #{format_value(value)}"
124
+ end
125
+ end
126
+
127
+ warning_message << "}\n"
128
+
129
+ @logger.warn(warning_message.join("\n"))
130
+ @elasticsearch_output = LogStash::Outputs::ElasticSearch.new(options)
131
+ end
132
+
133
+ private
134
+ def format_value(value)
135
+ if value.is_a?(LogStash::Codecs::Base)
136
+ return "\"#{value.class.to_s.split('::').last.downcase}\""
137
+ elsif value.is_a?(String)
138
+ return "\"#{value}\""
139
+ else
140
+ return value
141
+ end
142
+ end
143
+
144
+ def display_option?(option, value)
145
+ return false if option == 'password' && @config['user'].nil?
146
+ if !value.nil?
147
+ if value.is_a?(Array)
148
+ return true if value.size > 0
149
+ elsif value.to_s.size != 0
150
+ return true
151
+ end
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-output-elasticsearch_http'
3
+ s.version = '0.0.1'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = "The elasticsearch_http output is deprecated in favor of the elasticsearch"
6
+ s.description = "The elasticsearch_http output is deprecated in favor of the elasticsearch output with the protocol set to http"
7
+ s.authors = ["Elasticsearch"]
8
+ s.email = 'info@elasticsearch.com'
9
+ s.homepage = "http://www.elasticsearch.org/guide/en/logstash/current/index.html"
10
+ s.require_paths = ["lib"]
11
+
12
+ # Files
13
+ s.files = `git ls-files`.split($\)
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
+ # Gem dependencies
21
+ s.add_runtime_dependency 'logstash-core', '>= 1.4.0', '< 2.0.0'
22
+ s.add_runtime_dependency 'logstash-output-elasticsearch'
23
+ s.add_runtime_dependency 'logstash-codec-plain'
24
+ s.add_development_dependency 'logstash-devutils'
25
+ end
@@ -0,0 +1,84 @@
1
+ require "logstash/devutils/rspec/spec_helper"
2
+ require "logstash/outputs/elasticsearch_http"
3
+ require_relative "../support/helpers"
4
+
5
+ describe LogStash::Outputs::ElasticsearchHTTP do
6
+ let(:options) { { "host" => "127.0.0.1" } }
7
+
8
+ context "#register" do
9
+ subject do
10
+ LogStash::Outputs::ElasticsearchHTTP.new(options)
11
+ end
12
+
13
+ it 'should register' do
14
+ expect { subject.register }.to_not raise_error
15
+ end
16
+
17
+ context 'transform and display current config into the new format ' do
18
+ let(:logger) { MockLogger.new }
19
+ before do
20
+ expect(Cabin::Channel).to receive(:get).at_least(1).with(LogStash).and_return(logger)
21
+ end
22
+
23
+ subject do
24
+ LogStash::Outputs::ElasticsearchHTTP.new(options)
25
+ logger.content
26
+ end
27
+
28
+ it "warns that async replication is not supported" do
29
+ options.merge!( { "replication" => "async" })
30
+ expect(subject).to match(/Ignoring the async replication option/)
31
+ end
32
+
33
+ # since we are trying to have the same config syntax and
34
+ # Logstash's config isn't json I have to add this kind of guards
35
+ it "uses the elasticsearch output" do
36
+ expect(subject).to match(/elasticsearch {/)
37
+ end
38
+
39
+ it "contains host as array" do
40
+ expect(subject).to match(/host => \["127.0.0.1"\]/)
41
+ end
42
+
43
+ it "contains the default plain codec" do
44
+ expect(subject).to match(/codec => \"plain\"/)
45
+ end
46
+
47
+ it "defaults to one worker" do
48
+ expect(subject).to match(/workers => 1/)
49
+ end
50
+
51
+ it "uses the logstash index" do
52
+ expect(subject).to match(/index => \"logstash-%{\+YYYY\.MM\.dd}\"/)
53
+ end
54
+
55
+ it "define manages templates" do
56
+ expect(subject).to match(/manage_template => true/)
57
+ end
58
+
59
+ it "defines template_name" do
60
+ expect(subject).to match(/template_name => "logstash"/)
61
+ end
62
+
63
+ it "defines template_overwrite" do
64
+ expect(subject).to match(/template_overwrite => false/)
65
+ end
66
+
67
+ it "defines port" do
68
+ expect(subject).to match(/port => 9200/)
69
+ end
70
+
71
+ it "defines the flush_size" do
72
+ expect(subject).to match(/flush_size => 100/)
73
+ end
74
+
75
+ it "defines the idle_flush_time" do
76
+ expect(subject).to match(/idle_flush_time => 1/)
77
+ end
78
+
79
+ it "defines the protocol to http" do
80
+ expect(subject).to match(/protocol => "http"/)
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,17 @@
1
+ class MockLogger
2
+ def initialize
3
+ @content = []
4
+ end
5
+
6
+ def info(*value)
7
+ end
8
+ alias_method :debug, :info
9
+
10
+ def warn(*value)
11
+ @content << value.join(' ')
12
+ end
13
+
14
+ def content
15
+ @content.join("\n")
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-elasticsearch_http
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Elasticsearch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-24 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: 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-output-elasticsearch
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-codec-plain
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: :runtime
61
+ - !ruby/object:Gem::Dependency
62
+ name: logstash-devutils
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirement: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ prerelease: false
74
+ type: :development
75
+ description: The elasticsearch_http output is deprecated in favor of the elasticsearch output with the protocol set to http
76
+ email: info@elasticsearch.com
77
+ executables: []
78
+ extensions: []
79
+ extra_rdoc_files: []
80
+ files:
81
+ - .gitignore
82
+ - Gemfile
83
+ - LICENSE
84
+ - README.md
85
+ - Rakefile
86
+ - lib/logstash/outputs/elasticsearch_http.rb
87
+ - logstash-output-elasticsearch_http.gemspec
88
+ - spec/outputs/elasticsearch_http_spec.rb
89
+ - spec/support/helpers.rb
90
+ homepage: http://www.elasticsearch.org/guide/en/logstash/current/index.html
91
+ licenses:
92
+ - Apache License (2.0)
93
+ metadata:
94
+ logstash_plugin: 'true'
95
+ logstash_group: output
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.1.9
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: The elasticsearch_http output is deprecated in favor of the elasticsearch
116
+ test_files:
117
+ - spec/outputs/elasticsearch_http_spec.rb
118
+ - spec/support/helpers.rb