logstash-output-elasticsearch 0.1.6 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -13
- data/CHANGELOG.md +117 -0
- data/CONTRIBUTORS +32 -0
- data/Gemfile +4 -4
- data/LICENSE +1 -1
- data/NOTICE.TXT +5 -0
- data/README.md +110 -0
- data/lib/logstash/outputs/elasticsearch.rb +97 -425
- data/lib/logstash/outputs/elasticsearch/buffer.rb +124 -0
- data/lib/logstash/outputs/elasticsearch/common.rb +205 -0
- data/lib/logstash/outputs/elasticsearch/common_configs.rb +164 -0
- data/lib/logstash/outputs/elasticsearch/elasticsearch-template.json +36 -24
- data/lib/logstash/outputs/elasticsearch/http_client.rb +236 -0
- data/lib/logstash/outputs/elasticsearch/http_client_builder.rb +106 -0
- data/lib/logstash/outputs/elasticsearch/template_manager.rb +35 -0
- data/logstash-output-elasticsearch.gemspec +17 -15
- data/spec/es_spec_helper.rb +77 -0
- data/spec/fixtures/scripts/scripted_update.groovy +2 -0
- data/spec/fixtures/scripts/scripted_update_nested.groovy +2 -0
- data/spec/fixtures/scripts/scripted_upsert.groovy +2 -0
- data/spec/integration/outputs/create_spec.rb +55 -0
- data/spec/integration/outputs/index_spec.rb +68 -0
- data/spec/integration/outputs/parent_spec.rb +73 -0
- data/spec/integration/outputs/pipeline_spec.rb +75 -0
- data/spec/integration/outputs/retry_spec.rb +163 -0
- data/spec/integration/outputs/routing_spec.rb +65 -0
- data/spec/integration/outputs/secure_spec.rb +108 -0
- data/spec/integration/outputs/templates_spec.rb +90 -0
- data/spec/integration/outputs/update_spec.rb +188 -0
- data/spec/unit/buffer_spec.rb +118 -0
- data/spec/unit/http_client_builder_spec.rb +27 -0
- data/spec/unit/outputs/elasticsearch/http_client_spec.rb +133 -0
- data/spec/unit/outputs/elasticsearch_proxy_spec.rb +58 -0
- data/spec/unit/outputs/elasticsearch_spec.rb +227 -0
- data/spec/unit/outputs/elasticsearch_ssl_spec.rb +55 -0
- metadata +137 -51
- data/.gitignore +0 -4
- data/Rakefile +0 -6
- data/lib/logstash/outputs/elasticsearch/protocol.rb +0 -253
- data/rakelib/publish.rake +0 -9
- data/rakelib/vendor.rake +0 -169
- data/spec/outputs/elasticsearch.rb +0 -518
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative "../../../spec/es_spec_helper"
|
2
|
+
require 'stud/temporary'
|
3
|
+
|
4
|
+
describe "SSL option" do
|
5
|
+
context "when using ssl without cert verification" do
|
6
|
+
subject do
|
7
|
+
require "logstash/outputs/elasticsearch"
|
8
|
+
settings = {
|
9
|
+
"hosts" => "node01",
|
10
|
+
"ssl" => true,
|
11
|
+
"ssl_certificate_verification" => false
|
12
|
+
}
|
13
|
+
next LogStash::Outputs::ElasticSearch.new(settings)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should pass the flag to the ES client" do
|
17
|
+
expect(::Elasticsearch::Client).to receive(:new) do |args|
|
18
|
+
expect(args[:ssl]).to eq(:enabled => true, :verify => false)
|
19
|
+
end
|
20
|
+
subject.register
|
21
|
+
end
|
22
|
+
|
23
|
+
it "print a warning" do
|
24
|
+
expect(subject.logger).to receive(:warn)
|
25
|
+
subject.register
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when using ssl with client certificates" do
|
30
|
+
let(:keystore_path) { Stud::Temporary.file.path }
|
31
|
+
|
32
|
+
after :each do
|
33
|
+
File.delete(keystore_path)
|
34
|
+
end
|
35
|
+
|
36
|
+
subject do
|
37
|
+
require "logstash/outputs/elasticsearch"
|
38
|
+
settings = {
|
39
|
+
"hosts" => "node01",
|
40
|
+
"ssl" => true,
|
41
|
+
"keystore" => keystore_path,
|
42
|
+
"keystore_password" => "test"
|
43
|
+
}
|
44
|
+
next LogStash::Outputs::ElasticSearch.new(settings)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should pass the keystore parameters to the ES client" do
|
48
|
+
expect(::Elasticsearch::Client).to receive(:new) do |args|
|
49
|
+
expect(args[:ssl]).to include(:keystore => keystore_path, :keystore_password => "test")
|
50
|
+
end
|
51
|
+
subject.register
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,143 +1,212 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-output-elasticsearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: concurrent-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: elasticsearch
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
|
-
- -
|
31
|
+
- - ">="
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.0.
|
20
|
-
- - ~>
|
33
|
+
version: 1.0.13
|
34
|
+
- - "~>"
|
21
35
|
- !ruby/object:Gem::Version
|
22
36
|
version: '1.0'
|
23
37
|
type: :runtime
|
24
38
|
prerelease: false
|
25
39
|
version_requirements: !ruby/object:Gem::Requirement
|
26
40
|
requirements:
|
27
|
-
- -
|
41
|
+
- - ">="
|
28
42
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.0.
|
30
|
-
- - ~>
|
43
|
+
version: 1.0.13
|
44
|
+
- - "~>"
|
31
45
|
- !ruby/object:Gem::Version
|
32
46
|
version: '1.0'
|
33
47
|
- !ruby/object:Gem::Dependency
|
34
48
|
name: stud
|
35
49
|
requirement: !ruby/object:Gem::Requirement
|
36
50
|
requirements:
|
37
|
-
- -
|
51
|
+
- - ">="
|
38
52
|
- !ruby/object:Gem::Version
|
39
53
|
version: 0.0.17
|
40
|
-
- - ~>
|
54
|
+
- - "~>"
|
41
55
|
- !ruby/object:Gem::Version
|
42
56
|
version: '0.0'
|
43
57
|
type: :runtime
|
44
58
|
prerelease: false
|
45
59
|
version_requirements: !ruby/object:Gem::Requirement
|
46
60
|
requirements:
|
47
|
-
- -
|
61
|
+
- - ">="
|
48
62
|
- !ruby/object:Gem::Version
|
49
63
|
version: 0.0.17
|
50
|
-
- - ~>
|
64
|
+
- - "~>"
|
51
65
|
- !ruby/object:Gem::Version
|
52
66
|
version: '0.0'
|
53
67
|
- !ruby/object:Gem::Dependency
|
54
68
|
name: cabin
|
55
69
|
requirement: !ruby/object:Gem::Requirement
|
56
70
|
requirements:
|
57
|
-
- - ~>
|
71
|
+
- - "~>"
|
58
72
|
- !ruby/object:Gem::Version
|
59
73
|
version: '0.6'
|
60
74
|
type: :runtime
|
61
75
|
prerelease: false
|
62
76
|
version_requirements: !ruby/object:Gem::Requirement
|
63
77
|
requirements:
|
64
|
-
- - ~>
|
78
|
+
- - "~>"
|
65
79
|
- !ruby/object:Gem::Version
|
66
80
|
version: '0.6'
|
67
81
|
- !ruby/object:Gem::Dependency
|
68
|
-
name: logstash
|
82
|
+
name: logstash-core-plugin-api
|
69
83
|
requirement: !ruby/object:Gem::Requirement
|
70
84
|
requirements:
|
71
|
-
- -
|
85
|
+
- - "~>"
|
72
86
|
- !ruby/object:Gem::Version
|
73
|
-
version:
|
74
|
-
- - <
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: 2.0.0
|
87
|
+
version: '2.0'
|
77
88
|
type: :runtime
|
78
89
|
prerelease: false
|
79
90
|
version_requirements: !ruby/object:Gem::Requirement
|
80
91
|
requirements:
|
81
|
-
- -
|
92
|
+
- - "~>"
|
82
93
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
84
|
-
|
94
|
+
version: '2.0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: ftw
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
85
100
|
- !ruby/object:Gem::Version
|
86
|
-
version:
|
101
|
+
version: 0.0.42
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - "~>"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 0.0.42
|
87
109
|
- !ruby/object:Gem::Dependency
|
88
|
-
name:
|
110
|
+
name: logstash-codec-plain
|
89
111
|
requirement: !ruby/object:Gem::Requirement
|
90
112
|
requirements:
|
91
|
-
- -
|
113
|
+
- - ">="
|
92
114
|
- !ruby/object:Gem::Version
|
93
115
|
version: '0'
|
94
|
-
type: :
|
116
|
+
type: :development
|
95
117
|
prerelease: false
|
96
118
|
version_requirements: !ruby/object:Gem::Requirement
|
97
119
|
requirements:
|
98
|
-
- -
|
120
|
+
- - ">="
|
99
121
|
- !ruby/object:Gem::Version
|
100
122
|
version: '0'
|
101
123
|
- !ruby/object:Gem::Dependency
|
102
|
-
name:
|
124
|
+
name: logstash-devutils
|
103
125
|
requirement: !ruby/object:Gem::Requirement
|
104
126
|
requirements:
|
105
|
-
- -
|
127
|
+
- - ">="
|
106
128
|
- !ruby/object:Gem::Version
|
107
|
-
version: 0
|
108
|
-
|
129
|
+
version: '0'
|
130
|
+
type: :development
|
131
|
+
prerelease: false
|
132
|
+
version_requirements: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: longshoreman
|
139
|
+
requirement: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
109
142
|
- !ruby/object:Gem::Version
|
110
143
|
version: '0'
|
111
144
|
type: :development
|
112
145
|
prerelease: false
|
113
146
|
version_requirements: !ruby/object:Gem::Requirement
|
114
147
|
requirements:
|
115
|
-
- -
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
- !ruby/object:Gem::Dependency
|
152
|
+
name: flores
|
153
|
+
requirement: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
116
156
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0
|
118
|
-
|
157
|
+
version: '0'
|
158
|
+
type: :development
|
159
|
+
prerelease: false
|
160
|
+
version_requirements: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
119
163
|
- !ruby/object:Gem::Version
|
120
164
|
version: '0'
|
121
|
-
description:
|
122
|
-
|
165
|
+
description: This gem is a Logstash plugin required to be installed on top of the
|
166
|
+
Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
|
167
|
+
gem is not a stand-alone program
|
168
|
+
email: info@elastic.co
|
123
169
|
executables: []
|
124
170
|
extensions: []
|
125
171
|
extra_rdoc_files: []
|
126
172
|
files:
|
127
|
-
- .
|
173
|
+
- CHANGELOG.md
|
174
|
+
- CONTRIBUTORS
|
128
175
|
- Gemfile
|
129
176
|
- LICENSE
|
130
|
-
-
|
177
|
+
- NOTICE.TXT
|
178
|
+
- README.md
|
131
179
|
- lib/logstash/outputs/elasticsearch.rb
|
180
|
+
- lib/logstash/outputs/elasticsearch/buffer.rb
|
181
|
+
- lib/logstash/outputs/elasticsearch/common.rb
|
182
|
+
- lib/logstash/outputs/elasticsearch/common_configs.rb
|
132
183
|
- lib/logstash/outputs/elasticsearch/elasticsearch-template.json
|
133
|
-
- lib/logstash/outputs/elasticsearch/
|
184
|
+
- lib/logstash/outputs/elasticsearch/http_client.rb
|
185
|
+
- lib/logstash/outputs/elasticsearch/http_client_builder.rb
|
186
|
+
- lib/logstash/outputs/elasticsearch/template_manager.rb
|
134
187
|
- logstash-output-elasticsearch.gemspec
|
135
|
-
-
|
136
|
-
-
|
137
|
-
- spec/
|
188
|
+
- spec/es_spec_helper.rb
|
189
|
+
- spec/fixtures/scripts/scripted_update.groovy
|
190
|
+
- spec/fixtures/scripts/scripted_update_nested.groovy
|
191
|
+
- spec/fixtures/scripts/scripted_upsert.groovy
|
192
|
+
- spec/integration/outputs/create_spec.rb
|
193
|
+
- spec/integration/outputs/index_spec.rb
|
194
|
+
- spec/integration/outputs/parent_spec.rb
|
195
|
+
- spec/integration/outputs/pipeline_spec.rb
|
196
|
+
- spec/integration/outputs/retry_spec.rb
|
197
|
+
- spec/integration/outputs/routing_spec.rb
|
198
|
+
- spec/integration/outputs/secure_spec.rb
|
199
|
+
- spec/integration/outputs/templates_spec.rb
|
200
|
+
- spec/integration/outputs/update_spec.rb
|
201
|
+
- spec/unit/buffer_spec.rb
|
202
|
+
- spec/unit/http_client_builder_spec.rb
|
203
|
+
- spec/unit/outputs/elasticsearch/http_client_spec.rb
|
204
|
+
- spec/unit/outputs/elasticsearch_proxy_spec.rb
|
205
|
+
- spec/unit/outputs/elasticsearch_spec.rb
|
206
|
+
- spec/unit/outputs/elasticsearch_ssl_spec.rb
|
138
207
|
homepage: http://logstash.net/
|
139
208
|
licenses:
|
140
|
-
-
|
209
|
+
- apache-2.0
|
141
210
|
metadata:
|
142
211
|
logstash_plugin: 'true'
|
143
212
|
logstash_group: output
|
@@ -147,20 +216,37 @@ require_paths:
|
|
147
216
|
- lib
|
148
217
|
required_ruby_version: !ruby/object:Gem::Requirement
|
149
218
|
requirements:
|
150
|
-
- -
|
219
|
+
- - ">="
|
151
220
|
- !ruby/object:Gem::Version
|
152
221
|
version: '0'
|
153
222
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
223
|
requirements:
|
155
|
-
- -
|
224
|
+
- - ">="
|
156
225
|
- !ruby/object:Gem::Version
|
157
226
|
version: '0'
|
158
|
-
requirements:
|
159
|
-
- jar 'org.elasticsearch:elasticsearch', '1.4.0'
|
227
|
+
requirements: []
|
160
228
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.
|
229
|
+
rubygems_version: 2.5.1
|
162
230
|
signing_key:
|
163
231
|
specification_version: 4
|
164
232
|
summary: Logstash Output to Elasticsearch
|
165
233
|
test_files:
|
166
|
-
- spec/
|
234
|
+
- spec/es_spec_helper.rb
|
235
|
+
- spec/fixtures/scripts/scripted_update.groovy
|
236
|
+
- spec/fixtures/scripts/scripted_update_nested.groovy
|
237
|
+
- spec/fixtures/scripts/scripted_upsert.groovy
|
238
|
+
- spec/integration/outputs/create_spec.rb
|
239
|
+
- spec/integration/outputs/index_spec.rb
|
240
|
+
- spec/integration/outputs/parent_spec.rb
|
241
|
+
- spec/integration/outputs/pipeline_spec.rb
|
242
|
+
- spec/integration/outputs/retry_spec.rb
|
243
|
+
- spec/integration/outputs/routing_spec.rb
|
244
|
+
- spec/integration/outputs/secure_spec.rb
|
245
|
+
- spec/integration/outputs/templates_spec.rb
|
246
|
+
- spec/integration/outputs/update_spec.rb
|
247
|
+
- spec/unit/buffer_spec.rb
|
248
|
+
- spec/unit/http_client_builder_spec.rb
|
249
|
+
- spec/unit/outputs/elasticsearch/http_client_spec.rb
|
250
|
+
- spec/unit/outputs/elasticsearch_proxy_spec.rb
|
251
|
+
- spec/unit/outputs/elasticsearch_spec.rb
|
252
|
+
- spec/unit/outputs/elasticsearch_ssl_spec.rb
|
data/.gitignore
DELETED
data/Rakefile
DELETED
@@ -1,253 +0,0 @@
|
|
1
|
-
require "logstash/outputs/elasticsearch"
|
2
|
-
require "cabin"
|
3
|
-
|
4
|
-
module LogStash::Outputs::Elasticsearch
|
5
|
-
module Protocols
|
6
|
-
class Base
|
7
|
-
private
|
8
|
-
def initialize(options={})
|
9
|
-
# host(s), port, cluster
|
10
|
-
@logger = Cabin::Channel.get
|
11
|
-
end
|
12
|
-
|
13
|
-
def client
|
14
|
-
return @client if @client
|
15
|
-
@client = build_client(@options)
|
16
|
-
return @client
|
17
|
-
end # def client
|
18
|
-
|
19
|
-
|
20
|
-
def template_install(name, template, force=false)
|
21
|
-
if template_exists?(name) && !force
|
22
|
-
@logger.debug("Found existing Elasticsearch template. Skipping template management", :name => name)
|
23
|
-
return
|
24
|
-
end
|
25
|
-
template_put(name, template)
|
26
|
-
end
|
27
|
-
|
28
|
-
# Do a bulk request with the given actions.
|
29
|
-
#
|
30
|
-
# 'actions' is expected to be an array of bulk requests as string json
|
31
|
-
# values.
|
32
|
-
#
|
33
|
-
# Each 'action' becomes a single line in the bulk api call. For more
|
34
|
-
# details on the format of each.
|
35
|
-
def bulk(actions)
|
36
|
-
raise NotImplemented, "You must implement this yourself"
|
37
|
-
# bulk([
|
38
|
-
# '{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }',
|
39
|
-
# '{ "field1" : "value1" }'
|
40
|
-
#])
|
41
|
-
end
|
42
|
-
|
43
|
-
public(:initialize, :template_install)
|
44
|
-
end
|
45
|
-
|
46
|
-
class HTTPClient < Base
|
47
|
-
private
|
48
|
-
|
49
|
-
DEFAULT_OPTIONS = {
|
50
|
-
:port => 9200
|
51
|
-
}
|
52
|
-
|
53
|
-
def initialize(options={})
|
54
|
-
super
|
55
|
-
require "elasticsearch" # gem 'elasticsearch-ruby'
|
56
|
-
# manticore http transport
|
57
|
-
require "elasticsearch/transport/transport/http/manticore"
|
58
|
-
@options = DEFAULT_OPTIONS.merge(options)
|
59
|
-
@client = client
|
60
|
-
end
|
61
|
-
|
62
|
-
def build_client(options)
|
63
|
-
uri = "#{options[:protocol]}://#{options[:host]}:#{options[:port]}"
|
64
|
-
|
65
|
-
client_options = {
|
66
|
-
:host => [uri],
|
67
|
-
:transport_options => options[:client_settings]
|
68
|
-
}
|
69
|
-
client_options[:transport_class] = ::Elasticsearch::Transport::Transport::HTTP::Manticore
|
70
|
-
client_options[:ssl] = client_options[:transport_options].delete(:ssl)
|
71
|
-
|
72
|
-
if options[:user] && options[:password] then
|
73
|
-
token = Base64.strict_encode64(options[:user] + ":" + options[:password])
|
74
|
-
client_options[:headers] = { "Authorization" => "Basic #{token}" }
|
75
|
-
end
|
76
|
-
|
77
|
-
Elasticsearch::Client.new client_options
|
78
|
-
end
|
79
|
-
|
80
|
-
def bulk(actions)
|
81
|
-
@client.bulk(:body => actions.collect do |action, args, source|
|
82
|
-
if source
|
83
|
-
next [ { action => args }, source ]
|
84
|
-
else
|
85
|
-
next { action => args }
|
86
|
-
end
|
87
|
-
end.flatten)
|
88
|
-
end # def bulk
|
89
|
-
|
90
|
-
def template_exists?(name)
|
91
|
-
@client.indices.get_template(:name => name)
|
92
|
-
return true
|
93
|
-
rescue Elasticsearch::Transport::Transport::Errors::NotFound
|
94
|
-
return false
|
95
|
-
end # def template_exists?
|
96
|
-
|
97
|
-
def template_put(name, template)
|
98
|
-
@client.indices.put_template(:name => name, :body => template)
|
99
|
-
end # template_put
|
100
|
-
|
101
|
-
public(:bulk)
|
102
|
-
end # class HTTPClient
|
103
|
-
|
104
|
-
class NodeClient < Base
|
105
|
-
private
|
106
|
-
|
107
|
-
DEFAULT_OPTIONS = {
|
108
|
-
:port => 9300,
|
109
|
-
}
|
110
|
-
|
111
|
-
def initialize(options={})
|
112
|
-
super
|
113
|
-
require "java"
|
114
|
-
@options = DEFAULT_OPTIONS.merge(options)
|
115
|
-
setup(@options)
|
116
|
-
@client = client
|
117
|
-
end # def initialize
|
118
|
-
|
119
|
-
def settings
|
120
|
-
return @settings
|
121
|
-
end
|
122
|
-
|
123
|
-
def setup(options={})
|
124
|
-
@settings = org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder
|
125
|
-
if options[:host]
|
126
|
-
@settings.put("discovery.zen.ping.multicast.enabled", false)
|
127
|
-
@settings.put("discovery.zen.ping.unicast.hosts", hosts(options))
|
128
|
-
end
|
129
|
-
|
130
|
-
@settings.put("node.client", true)
|
131
|
-
@settings.put("http.enabled", false)
|
132
|
-
|
133
|
-
if options[:client_settings]
|
134
|
-
options[:client_settings].each do |key, value|
|
135
|
-
@settings.put(key, value)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
return @settings
|
140
|
-
end
|
141
|
-
|
142
|
-
def hosts(options)
|
143
|
-
# http://www.elasticsearch.org/guide/reference/modules/discovery/zen/
|
144
|
-
result = Array.new
|
145
|
-
if options[:host].class == Array
|
146
|
-
options[:host].each do |host|
|
147
|
-
if host.to_s =~ /^.+:.+$/
|
148
|
-
# For host in format: host:port, ignore options[:port]
|
149
|
-
result << host
|
150
|
-
else
|
151
|
-
if options[:port].to_s =~ /^\d+-\d+$/
|
152
|
-
# port ranges are 'host[port1-port2]'
|
153
|
-
result << Range.new(*options[:port].split("-")).collect { |p| "#{host}:#{p}" }
|
154
|
-
else
|
155
|
-
result << "#{host}:#{options[:port]}"
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
else
|
160
|
-
if options[:host].to_s =~ /^.+:.+$/
|
161
|
-
# For host in format: host:port, ignore options[:port]
|
162
|
-
result << options[:host]
|
163
|
-
else
|
164
|
-
if options[:port].to_s =~ /^\d+-\d+$/
|
165
|
-
# port ranges are 'host[port1-port2]' according to
|
166
|
-
# http://www.elasticsearch.org/guide/reference/modules/discovery/zen/
|
167
|
-
# However, it seems to only query the first port.
|
168
|
-
# So generate our own list of unicast hosts to scan.
|
169
|
-
range = Range.new(*options[:port].split("-"))
|
170
|
-
result << range.collect { |p| "#{options[:host]}:#{p}" }
|
171
|
-
else
|
172
|
-
result << "#{options[:host]}:#{options[:port]}"
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
result.flatten.join(",")
|
177
|
-
end # def hosts
|
178
|
-
|
179
|
-
def build_client(options)
|
180
|
-
nodebuilder = org.elasticsearch.node.NodeBuilder.nodeBuilder
|
181
|
-
return nodebuilder.settings(@settings).node.client
|
182
|
-
end # def build_client
|
183
|
-
|
184
|
-
def bulk(actions)
|
185
|
-
# Actions an array of [ action, action_metadata, source ]
|
186
|
-
prep = @client.prepareBulk
|
187
|
-
actions.each do |action, args, source|
|
188
|
-
prep.add(build_request(action, args, source))
|
189
|
-
end
|
190
|
-
response = prep.execute.actionGet()
|
191
|
-
|
192
|
-
# TODO(sissel): What format should the response be in?
|
193
|
-
end # def bulk
|
194
|
-
|
195
|
-
def build_request(action, args, source)
|
196
|
-
case action
|
197
|
-
when "index"
|
198
|
-
request = org.elasticsearch.action.index.IndexRequest.new(args[:_index])
|
199
|
-
request.id(args[:_id]) if args[:_id]
|
200
|
-
request.source(source)
|
201
|
-
when "delete"
|
202
|
-
request = org.elasticsearch.action.delete.DeleteRequest.new(args[:_index])
|
203
|
-
request.id(args[:_id])
|
204
|
-
#when "update"
|
205
|
-
#when "create"
|
206
|
-
end # case action
|
207
|
-
|
208
|
-
request.type(args[:_type]) if args[:_type]
|
209
|
-
return request
|
210
|
-
end # def build_request
|
211
|
-
|
212
|
-
def template_exists?(name)
|
213
|
-
request = org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequestBuilder.new(@client.admin.indices, name)
|
214
|
-
response = request.get
|
215
|
-
return !response.getIndexTemplates.isEmpty
|
216
|
-
end # def template_exists?
|
217
|
-
|
218
|
-
def template_put(name, template)
|
219
|
-
request = org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder.new(@client.admin.indices, name)
|
220
|
-
request.setSource(LogStash::Json.dump(template))
|
221
|
-
|
222
|
-
# execute the request and get the response, if it fails, we'll get an exception.
|
223
|
-
request.get
|
224
|
-
end # template_put
|
225
|
-
|
226
|
-
public(:initialize, :bulk)
|
227
|
-
end # class NodeClient
|
228
|
-
|
229
|
-
class TransportClient < NodeClient
|
230
|
-
private
|
231
|
-
def build_client(options)
|
232
|
-
client = org.elasticsearch.client.transport.TransportClient.new(settings.build)
|
233
|
-
|
234
|
-
if options[:host]
|
235
|
-
client.addTransportAddress(
|
236
|
-
org.elasticsearch.common.transport.InetSocketTransportAddress.new(
|
237
|
-
options[:host], options[:port].to_i
|
238
|
-
)
|
239
|
-
)
|
240
|
-
end
|
241
|
-
|
242
|
-
return client
|
243
|
-
end # def build_client
|
244
|
-
end # class TransportClient
|
245
|
-
end # module Protocols
|
246
|
-
|
247
|
-
module Requests
|
248
|
-
class GetIndexTemplates; end
|
249
|
-
class Bulk; end
|
250
|
-
class Index; end
|
251
|
-
class Delete; end
|
252
|
-
end
|
253
|
-
end
|