logstash-output-elasticsearch 0.1.5 → 0.1.6

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTFjZmRiNDk2YjMzNGE4NzVmYTgyNGMzYzAxNGUxZjY3ZDEwMTE4MQ==
4
+ N2UwMzczMTE0ZWNmZjFhOGU4Mjk0YjUwZDE5YmVmNDQyMWUzMzg0Mw==
5
5
  data.tar.gz: !binary |-
6
- ZTcyNTg2NzA5ZDQ3NGRmZDM4NGE1ZmJlNzllOWI3MTAxMzgwNjllMQ==
6
+ ODJkYzg1NWU5YWEzYmZmOWRiMDFkNjFlYmM0Y2Q2NmZiZGEwNjYyMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MmIxMGUyZjAxYTE5NmUzZGIzZWRmNDc0NmMyOWVlMTQ2YTQxMjA2ZmQzZDg2
10
- M2FlMWVjMGRmNTQwMjdjZjM3NzY5Y2UxMTk1ODVlM2NhOTBlZmIwMzA4ZjE4
11
- YWNjYjdlMzgxYmUyMTMwN2UwMzI2MWEzNjI3OWMyNWM4ZDRlYmE=
9
+ Y2M3ZDliMjhjYmY4OGM0NjI5ODA2OTYyZWE1MzM2MzE0MmVlZDI1NmE0OTNl
10
+ YWY0MmEzNzQ2OWUwODc0ZWRkNmI0OWY3MDViOTU3ZjlhMGY5NzFjZDJhNGQz
11
+ NjdlZWQ4YWM3Nzk1NTI3OWQ1MDEyZmY0MzBkODM0Nzc3YTgzNWM=
12
12
  data.tar.gz: !binary |-
13
- YjZmYWQzZjMxMGUwODFkZDMzYWY4OTQ2Zjc1NmZiMDRiODUwYWVmMmIyNDNl
14
- YjMwMjIyMzg2YjA5M2MwNTdlNDdiMmZlOTA0OTZkNGRkZGNmYTFkYTFjNGUz
15
- YTQ4YjQ1ZWFiZjQzZTU5Y2I5MzI1ZWJlZjVhNTlhMDU5NzZmNDI=
13
+ MjY2Mzc0ZDRiOGEyOGIzMDg2NWMzNGRiMDA2MWYxMDM4YzhiZmZiN2ViZDhk
14
+ ZDI2ZGE2MzRhMTA1ZDMxZGM2NTQ3YzU1ZjE0NjYzMTU0NTk4OTJhMWFiNTMy
15
+ MzQzYzc0OGM2NTNkMzJmNmIxY2I4YWY5ODZhYTgzOTAwODUxYWM=
@@ -42,6 +42,7 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base
42
42
  # The default value will partition your indices by day so you can more easily
43
43
  # delete old data or only search specific date ranges.
44
44
  # Indexes may not contain uppercase characters.
45
+ # For weekly indexes ISO 8601 format is recommended, eg. logstash-%{+xxxx.ww}
45
46
  config :index, :validate => :string, :default => "logstash-%{+YYYY.MM.dd}"
46
47
 
47
48
  # The index type to write events to. Generally you should try to write only
@@ -178,7 +179,7 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base
178
179
  # - index: indexes a document (an event from Logstash).
179
180
  # - delete: deletes a document by id
180
181
  #
181
- # For more details on actions, check out the [Elasticsearch bulk API documentation](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html)
182
+ # For more details on actions, check out the http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html[Elasticsearch bulk API documentation]
182
183
  config :action, :validate => :string, :default => "index"
183
184
 
184
185
  # Username and password (HTTP only)
@@ -200,6 +201,14 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base
200
201
  # Set the truststore password
201
202
  config :truststore_password, :validate => :password
202
203
 
204
+ # helper function to replace placeholders
205
+ # in index names to wildcards
206
+ # example:
207
+ # "logs-%{YYYY}" -> "logs-*"
208
+ def wildcard_substitute(name)
209
+ name.gsub(/%\{[^}]+\}/, "*")
210
+ end
211
+
203
212
  public
204
213
  def register
205
214
  client_settings = {}
@@ -242,38 +251,14 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base
242
251
  @host = ["localhost"]
243
252
  end
244
253
 
245
- if @ssl
246
- if @protocol == "http"
247
- @protocol = "https"
248
- if @cacert && @truststore
249
- raise(LogStash::ConfigurationError, "Use either \"cacert\" or \"truststore\" when configuring the CA certificate") if @truststore
250
- end
251
- ssl_options = {}
252
- if @cacert then
253
- @truststore, ssl_options[:truststore_password] = generate_jks @cacert
254
- elsif @truststore
255
- ssl_options[:truststore_password] = @truststore_password.value if @truststore_password
256
- end
257
- ssl_options[:truststore] = @truststore
258
- client_settings[:ssl] = ssl_options
259
- else
260
- raise(LogStash::ConfigurationError, "SSL is not supported for '#{@protocol}'. Change the protocol to 'http' if you need SSL.")
261
- end
262
- end
254
+ client_settings.merge! setup_ssl()
263
255
 
264
256
  common_options = {
265
257
  :protocol => @protocol,
266
258
  :client_settings => client_settings
267
259
  }
268
260
 
269
- if @user && @password
270
- if @protocol =~ /http/
271
- common_options[:user] = ::URI.escape(@user, "@:")
272
- common_options[:password] = ::URI.escape(@password.value, "@:")
273
- else
274
- raise(LogStash::ConfigurationError, "User and password parameters are not supported for '#{@protocol}'. Change the protocol to 'http' if you need them.")
275
- end
276
- end
261
+ common_options.merge! setup_basic_auth()
277
262
 
278
263
  client_class = case @protocol
279
264
  when "transport"
@@ -350,6 +335,40 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base
350
335
  @logger.debug? and @logger.debug("Switched current elasticsearch client to ##{@client_idx} at #{@host[@client_idx]}")
351
336
  end
352
337
 
338
+ private
339
+ def setup_ssl
340
+ return {} unless @ssl
341
+ if @protocol != "http"
342
+ raise(LogStash::ConfigurationError, "SSL is not supported for '#{@protocol}'. Change the protocol to 'http' if you need SSL.")
343
+ end
344
+ @protocol = "https"
345
+ if @cacert && @truststore
346
+ raise(LogStash::ConfigurationError, "Use either \"cacert\" or \"truststore\" when configuring the CA certificate") if @truststore
347
+ end
348
+ ssl_options = {}
349
+ if @cacert then
350
+ @truststore, ssl_options[:truststore_password] = generate_jks @cacert
351
+ elsif @truststore
352
+ ssl_options[:truststore_password] = @truststore_password.value if @truststore_password
353
+ end
354
+ ssl_options[:truststore] = @truststore
355
+ { ssl: ssl_options }
356
+ end
357
+
358
+ private
359
+ def setup_basic_auth
360
+ return {} unless @user && @password
361
+
362
+ if @protocol =~ /http/
363
+ {
364
+ :user => ::URI.escape(@user, "@:"),
365
+ :password => ::URI.escape(@password.value, "@:")
366
+ }
367
+ else
368
+ raise(LogStash::ConfigurationError, "User and password parameters are not supported for '#{@protocol}'. Change the protocol to 'http' if you need them.")
369
+ end
370
+ end
371
+
353
372
  public
354
373
  def get_template
355
374
  if @template.nil?
@@ -359,8 +378,10 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base
359
378
  end
360
379
  end
361
380
  template_json = IO.read(@template).gsub(/\n/,'')
362
- @logger.info("Using mapping template", :template => template_json)
363
- return LogStash::Json.load(template_json)
381
+ template = LogStash::Json.load(template_json)
382
+ template['template'] = wildcard_substitute(@index)
383
+ @logger.info("Using mapping template", :template => template)
384
+ return template
364
385
  end # def get_template
365
386
 
366
387
  protected
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-output-elasticsearch'
4
- s.version = '0.1.5'
4
+ s.version = '0.1.6'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Logstash Output to Elasticsearch"
7
7
  s.description = "Output events to elasticsearch"
@@ -20,18 +20,19 @@ Gem::Specification.new do |s|
20
20
  s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
21
21
 
22
22
  # Jar dependencies
23
- s.requirements << "jar 'org.elasticsearch:elasticsearch', '1.3.1'"
23
+ s.requirements << "jar 'org.elasticsearch:elasticsearch', '1.4.0'"
24
24
 
25
25
  # Gem dependencies
26
- s.add_runtime_dependency 'elasticsearch', ['~> 1.0.6']
27
- s.add_runtime_dependency 'stud'
28
- s.add_runtime_dependency 'cabin', ['>=0.6.0']
29
- s.add_runtime_dependency 'ftw', ['~> 0.0.40']
26
+ s.add_runtime_dependency 'elasticsearch', ['>= 1.0.6', '~> 1.0']
27
+ s.add_runtime_dependency 'stud', ['>= 0.0.17', '~> 0.0']
28
+ s.add_runtime_dependency 'cabin', ['~> 0.6']
30
29
  s.add_runtime_dependency 'logstash', '>= 1.4.0', '< 2.0.0'
31
30
  s.add_runtime_dependency 'jar-dependencies'
32
31
 
32
+ s.add_development_dependency 'ftw', ['>= 0.0.40', '~> 0']
33
+
33
34
  if RUBY_PLATFORM == 'java'
34
- gem.add_runtime_dependency "manticore"
35
+ s.add_runtime_dependency "manticore", '~> 0.3'
35
36
  end
36
37
  end
37
38
 
@@ -12,6 +12,7 @@ describe "outputs/elasticsearch" do
12
12
  expect {output.register}.to_not raise_error
13
13
  end
14
14
 
15
+
15
16
  describe "ship lots of events w/ default index_type", :elasticsearch => true do
16
17
  # Generate a random index name
17
18
  index = 10.times.collect { rand(10).to_s }.join("")
@@ -257,6 +258,34 @@ describe "outputs/elasticsearch" do
257
258
  end
258
259
  end
259
260
 
261
+ describe "wildcard substitution in index templates", :todo => true do
262
+ require "logstash/outputs/elasticsearch"
263
+
264
+ let(:template) { '{"template" : "not important, will be updated by :index"}' }
265
+
266
+ def settings_with_index(index)
267
+ return {
268
+ "manage_template" => true,
269
+ "template_overwrite" => true,
270
+ "protocol" => "http",
271
+ "host" => "localhost",
272
+ "index" => "#{index}"
273
+ }
274
+ end
275
+
276
+ it "should substitude placeholders" do
277
+ IO.stub(:read).with(anything) { template }
278
+ es_output = LogStash::Outputs::ElasticSearch.new(settings_with_index("index-%{YYYY}"))
279
+ insist { es_output.get_template['template'] } == "index-*"
280
+ end
281
+
282
+ it "should do nothing to an index with no placeholder" do
283
+ IO.stub(:read).with(anything) { template }
284
+ es_output = LogStash::Outputs::ElasticSearch.new(settings_with_index("index"))
285
+ insist { es_output.get_template['template'] } == "index"
286
+ end
287
+ end
288
+
260
289
  describe "index template expected behavior", :elasticsearch => true do
261
290
  ["node", "transport", "http"].each do |protocol|
262
291
  context "with protocol => #{protocol}" do
metadata CHANGED
@@ -1,71 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elasticsearch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-07 00:00:00.000000000 Z
11
+ date: 2014-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: elasticsearch
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ! '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.0.6
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
20
  - - ~>
25
21
  - !ruby/object:Gem::Version
26
- version: 1.0.6
27
- - !ruby/object:Gem::Dependency
28
- name: stud
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
22
+ version: '1.0'
34
23
  type: :runtime
35
24
  prerelease: false
36
25
  version_requirements: !ruby/object:Gem::Requirement
37
26
  requirements:
38
27
  - - ! '>='
39
28
  - !ruby/object:Gem::Version
40
- version: '0'
29
+ version: 1.0.6
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '1.0'
41
33
  - !ruby/object:Gem::Dependency
42
- name: cabin
34
+ name: stud
43
35
  requirement: !ruby/object:Gem::Requirement
44
36
  requirements:
45
37
  - - ! '>='
46
38
  - !ruby/object:Gem::Version
47
- version: 0.6.0
39
+ version: 0.0.17
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ version: '0.0'
48
43
  type: :runtime
49
44
  prerelease: false
50
45
  version_requirements: !ruby/object:Gem::Requirement
51
46
  requirements:
52
47
  - - ! '>='
53
48
  - !ruby/object:Gem::Version
54
- version: 0.6.0
49
+ version: 0.0.17
50
+ - - ~>
51
+ - !ruby/object:Gem::Version
52
+ version: '0.0'
55
53
  - !ruby/object:Gem::Dependency
56
- name: ftw
54
+ name: cabin
57
55
  requirement: !ruby/object:Gem::Requirement
58
56
  requirements:
59
57
  - - ~>
60
58
  - !ruby/object:Gem::Version
61
- version: 0.0.40
59
+ version: '0.6'
62
60
  type: :runtime
63
61
  prerelease: false
64
62
  version_requirements: !ruby/object:Gem::Requirement
65
63
  requirements:
66
64
  - - ~>
67
65
  - !ruby/object:Gem::Version
68
- version: 0.0.40
66
+ version: '0.6'
69
67
  - !ruby/object:Gem::Dependency
70
68
  name: logstash
71
69
  requirement: !ruby/object:Gem::Requirement
@@ -100,6 +98,26 @@ dependencies:
100
98
  - - ! '>='
101
99
  - !ruby/object:Gem::Version
102
100
  version: '0'
101
+ - !ruby/object:Gem::Dependency
102
+ name: ftw
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: 0.0.40
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 0.0.40
118
+ - - ~>
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
103
121
  description: Output events to elasticsearch
104
122
  email: richard.pijnenburg@elasticsearch.com
105
123
  executables: []
@@ -138,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
156
  - !ruby/object:Gem::Version
139
157
  version: '0'
140
158
  requirements:
141
- - jar 'org.elasticsearch:elasticsearch', '1.3.1'
159
+ - jar 'org.elasticsearch:elasticsearch', '1.4.0'
142
160
  rubyforge_project:
143
161
  rubygems_version: 2.4.1
144
162
  signing_key: