fluent-plugin-elasticsearch 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5313f204bb2cc56d58acf4587337bb9be25cabe5
4
- data.tar.gz: bdf2ace0733655e50771305036256ec2a2486944
3
+ metadata.gz: e1ce21e5b836181cdc5f32e97e4d3a91bfc31da7
4
+ data.tar.gz: 77c81ab19d4749da338f481404983f1bcf8b069e
5
5
  SHA512:
6
- metadata.gz: 30f15c3bf195a5455c5d84f374934721a8550d25636a8e10d1410d6c6792e5f590f69b34129efcc1a9547bf0fefb68f703f82a61765fea4c603096a6d20a2568
7
- data.tar.gz: 55ee1ed8366cd4c6624be2c216fa28428d42cbbecfcf6b8c1d87444761e91a55c83176376b91213b11f5e9edd6dd673d2845bb16ef03604688071a733a8617c4
6
+ metadata.gz: dd36dacfb1b9c7fe7c860ffe4b2ed0e7bbdd3c5803c2faef0879c7898d8d9f732860e4b54e63125b1dabf8bb7fdc66868babaec7c199b896fbb913b644ae778a
7
+ data.tar.gz: 90d3c5c2b9c4af19d4c5c19d48288c92aebcb4d80cc83343a2502377f85dfef0e9ca1bf39c3de5a6065456e0a2bdc985a4f312372af2e3ad40fcd05f8df46225
data/History.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  ### Future
4
4
 
5
+ ### 1.7.0
6
+ - add support for `template_name` and `template_file` (#194)
7
+
5
8
  ### 1.6.0
6
9
  - add support for dot separated `target_index_key` and `target_type_key` (#175)
7
10
  - add `remove_keys_on_update` and `remove_keys_on_update_key` (#189)
data/README.md CHANGED
@@ -26,6 +26,8 @@ Note: For Amazon Elasticsearch Service please consider using [fluent-plugin-aws-
26
26
  + [utc_index](#utc_index)
27
27
  + [target_index_key](#target_index_key)
28
28
  + [target_type_key](#target_type_key)
29
+ + [template_name](#template_name)
30
+ + [template_file](#template_file)
29
31
  + [request_timeout](#request_timeout)
30
32
  + [reload_connections](#reload_connections)
31
33
  + [reload_on_failure](#reload_on_failure)
@@ -224,6 +226,20 @@ and this record will be written to the specified index (`logstash-2014.12.19`) r
224
226
 
225
227
  Similar to `target_index_key` config, find the type name to write to in the record under this key (or nested record). If key not found in record - fallback to `type_name` (default "fluentd").
226
228
 
229
+ ### template_name
230
+
231
+ The name of the template to define. If a template by the name given is already present, it will be left unchanged.
232
+
233
+ This parameter along with template_file allow the plugin to behave similarly to Logstash (it installs a template at creation time) so that raw records are available. See [https://github.com/uken/fluent-plugin-elasticsearch/issues/33](https://github.com/uken/fluent-plugin-elasticsearch/issues/33).
234
+
235
+ [template_file](#template_file) must also be specified.
236
+
237
+ ### template_file
238
+
239
+ The path to the file containing the template to install.
240
+
241
+ [template_name](#template_name) must also be specified.
242
+
227
243
  ### request_timeout
228
244
 
229
245
  You can specify HTTP request timeout.
@@ -3,7 +3,7 @@ $:.push File.expand_path('../lib', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'fluent-plugin-elasticsearch'
6
- s.version = '1.6.0'
6
+ s.version = '1.7.0'
7
7
  s.authors = ['diogo', 'pitr']
8
8
  s.email = ['pitr.vern@gmail.com', 'me@diogoterror.com']
9
9
  s.description = %q{ElasticSearch output plugin for Fluent event collector}
@@ -0,0 +1,31 @@
1
+ module Fluent::ElasticsearchIndexTemplate
2
+
3
+ def get_template(template_file)
4
+ if !File.exists?(template_file)
5
+ raise "If you specify a template_name you must specify a valid template file (checked '#{template_file}')!"
6
+ end
7
+ file_contents = IO.read(template_file).gsub(/\n/,'')
8
+ JSON.parse(file_contents)
9
+ end
10
+
11
+ def template_exists?(name)
12
+ client.indices.get_template(:name => name)
13
+ return true
14
+ rescue Elasticsearch::Transport::Transport::Errors::NotFound
15
+ return false
16
+ end
17
+
18
+ def template_put(name, template)
19
+ client.indices.put_template(:name => name, :body => template)
20
+ end
21
+
22
+ def template_install(name, template_file)
23
+ if !template_exists?(name)
24
+ template_put(name, get_template(template_file))
25
+ log.info("Template configured, but no template installed. Installed '#{name}' from #{template_file}.")
26
+ else
27
+ log.info("Template configured and already installed.")
28
+ end
29
+ end
30
+
31
+ end
@@ -2,12 +2,15 @@
2
2
  require 'date'
3
3
  require 'excon'
4
4
  require 'elasticsearch'
5
+ require 'json'
5
6
  require 'uri'
6
7
  begin
7
8
  require 'strptime'
8
9
  rescue LoadError
9
10
  end
10
11
 
12
+ require_relative 'elasticsearch_index_template'
13
+
11
14
  class Fluent::ElasticsearchOutput < Fluent::BufferedOutput
12
15
  class ConnectionFailure < StandardError; end
13
16
 
@@ -49,8 +52,11 @@ class Fluent::ElasticsearchOutput < Fluent::BufferedOutput
49
52
  config_param :remove_keys_on_update_key, :string, :default => nil
50
53
  config_param :flatten_hashes, :bool, :default => false
51
54
  config_param :flatten_hashes_separator, :string, :default => "_"
55
+ config_param :template_name, :string, :default => nil
56
+ config_param :template_file, :string, :default => nil
52
57
 
53
58
  include Fluent::SetTagKeyMixin
59
+ include Fluent::ElasticsearchIndexTemplate
54
60
  config_set_default :include_tag_key, false
55
61
 
56
62
  def initialize
@@ -77,6 +83,10 @@ class Fluent::ElasticsearchOutput < Fluent::BufferedOutput
77
83
  if @remove_keys_on_update && @remove_keys_on_update.is_a?(String)
78
84
  @remove_keys_on_update = @remove_keys_on_update.split ','
79
85
  end
86
+
87
+ if @template_name && @template_file
88
+ template_install(@template_name, @template_file)
89
+ end
80
90
  end
81
91
 
82
92
  def start
@@ -65,6 +65,80 @@ class ElasticsearchOutput < Test::Unit::TestCase
65
65
  assert_equal 'doe', instance.password
66
66
  end
67
67
 
68
+ def test_template_already_present
69
+ config = %{
70
+ host logs.google.com
71
+ port 777
72
+ scheme https
73
+ path /es/
74
+ user john
75
+ password doe
76
+ template_name logstash
77
+ template_file /abc123
78
+ }
79
+
80
+ # connection start
81
+ stub_request(:head, "https://john:doe@logs.google.com:777/es//").
82
+ to_return(:status => 200, :body => "", :headers => {})
83
+ # check if template exists
84
+ stub_request(:get, "https://john:doe@logs.google.com:777/es//_template/logstash").
85
+ to_return(:status => 200, :body => "", :headers => {})
86
+
87
+ driver('test', config)
88
+ end
89
+
90
+ def test_template_create
91
+ cwd = File.dirname(__FILE__)
92
+ template_file = File.join(cwd, 'test_template.json')
93
+
94
+ config = %{
95
+ host logs.google.com
96
+ port 777
97
+ scheme https
98
+ path /es/
99
+ user john
100
+ password doe
101
+ template_name logstash
102
+ template_file #{template_file}
103
+ }
104
+
105
+ # connection start
106
+ stub_request(:head, "https://john:doe@logs.google.com:777/es//").
107
+ to_return(:status => 200, :body => "", :headers => {})
108
+ # check if template exists
109
+ stub_request(:get, "https://john:doe@logs.google.com:777/es//_template/logstash").
110
+ to_return(:status => 404, :body => "", :headers => {})
111
+ # creation
112
+ stub_request(:put, "https://john:doe@logs.google.com:777/es//_template/logstash").
113
+ to_return(:status => 200, :body => "", :headers => {})
114
+
115
+ driver('test', config)
116
+ end
117
+
118
+ def test_template_create_invalid_filename
119
+ config = %{
120
+ host logs.google.com
121
+ port 777
122
+ scheme https
123
+ path /es/
124
+ user john
125
+ password doe
126
+ template_name logstash
127
+ template_file /abc123
128
+ }
129
+
130
+ # connection start
131
+ stub_request(:head, "https://john:doe@logs.google.com:777/es//").
132
+ to_return(:status => 200, :body => "", :headers => {})
133
+ # check if template exists
134
+ stub_request(:get, "https://john:doe@logs.google.com:777/es//_template/logstash").
135
+ to_return(:status => 404, :body => "", :headers => {})
136
+
137
+ assert_raise(RuntimeError) {
138
+ driver('test', config)
139
+ }
140
+ end
141
+
68
142
  def test_legacy_hosts_list
69
143
  config = %{
70
144
  hosts host1:50,host2:100,host3
@@ -0,0 +1,23 @@
1
+ {
2
+ "template": "te*",
3
+ "settings": {
4
+ "number_of_shards": 1
5
+ },
6
+ "mappings": {
7
+ "type1": {
8
+ "_source": {
9
+ "enabled": false
10
+ },
11
+ "properties": {
12
+ "host_name": {
13
+ "type": "string",
14
+ "index": "not_analyzed"
15
+ },
16
+ "created_at": {
17
+ "type": "date",
18
+ "format": "EEE MMM dd HH:mm:ss Z YYYY"
19
+ }
20
+ }
21
+ }
22
+ }
23
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - diogo
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-08-19 00:00:00.000000000 Z
12
+ date: 2016-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd
@@ -129,11 +129,13 @@ files:
129
129
  - README.md
130
130
  - Rakefile
131
131
  - fluent-plugin-elasticsearch.gemspec
132
+ - lib/fluent/plugin/elasticsearch_index_template.rb
132
133
  - lib/fluent/plugin/out_elasticsearch.rb
133
134
  - lib/fluent/plugin/out_elasticsearch_dynamic.rb
134
135
  - test/helper.rb
135
136
  - test/plugin/test_out_elasticsearch.rb
136
137
  - test/plugin/test_out_elasticsearch_dynamic.rb
138
+ - test/plugin/test_template.json
137
139
  homepage: https://github.com/uken/fluent-plugin-elasticsearch
138
140
  licenses:
139
141
  - MIT
@@ -162,3 +164,4 @@ test_files:
162
164
  - test/helper.rb
163
165
  - test/plugin/test_out_elasticsearch.rb
164
166
  - test/plugin/test_out_elasticsearch_dynamic.rb
167
+ - test/plugin/test_template.json