fluent-plugin-es-mohit 1.9.3

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.
data/README.md ADDED
@@ -0,0 +1,520 @@
1
+ # Fluent::Plugin::Elasticsearch, a plugin for [Fluentd](http://fluentd.org)
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/fluent-plugin-elasticsearch.png)](http://badge.fury.io/rb/fluent-plugin-elasticsearch)
4
+ [![Build Status](https://travis-ci.org/uken/fluent-plugin-elasticsearch.png?branch=master)](https://travis-ci.org/uken/fluent-plugin-elasticsearch)
5
+ [![Coverage Status](https://coveralls.io/repos/uken/fluent-plugin-elasticsearch/badge.png)](https://coveralls.io/r/uken/fluent-plugin-elasticsearch)
6
+ [![Code Climate](https://codeclimate.com/github/uken/fluent-plugin-elasticsearch.png)](https://codeclimate.com/github/uken/fluent-plugin-elasticsearch)
7
+ [![Issue Stats](http://issuestats.com/github/uken/fluent-plugin-elasticsearch/badge/pr)](http://issuestats.com/github/uken/fluent-plugin-elasticsearch)
8
+ [![Issue Stats](http://issuestats.com/github/uken/fluent-plugin-elasticsearch/badge/issue)](http://issuestats.com/github/uken/fluent-plugin-elasticsearch)
9
+
10
+ Send your logs to ElasticSearch (and search them with Kibana maybe?)
11
+
12
+ Note: For Amazon Elasticsearch Service please consider using [fluent-plugin-aws-elasticsearch-service](https://github.com/atomita/fluent-plugin-aws-elasticsearch-service)
13
+
14
+ * [Installation](#installation)
15
+ * [Usage](#usage)
16
+ + [Index templates](#index-templates)
17
+ * [Configuration](#configuration)
18
+ + [hosts](#hosts)
19
+ + [user, password, path, scheme, ssl_verify](#user-password-path-scheme-ssl_verify)
20
+ + [logstash_format](#logstash_format)
21
+ + [logstash_prefix](#logstash_prefix)
22
+ + [logstash_dateformat](#logstash_dateformat)
23
+ + [time_key_format](#time_key_format)
24
+ + [time_key](#time_key)
25
+ + [time_key_exclude_timestamp](#time_key_exclude_timestamp)
26
+ + [utc_index](#utc_index)
27
+ + [target_index_key](#target_index_key)
28
+ + [target_type_key](#target_type_key)
29
+ + [template_name](#template_name)
30
+ + [template_file](#template_file)
31
+ + [templates](#templates)
32
+ + [request_timeout](#request_timeout)
33
+ + [reload_connections](#reload_connections)
34
+ + [reload_on_failure](#reload_on_failure)
35
+ + [resurrect_after](#resurrect_after)
36
+ + [include_tag_key, tag_key](#include_tag_key-tag_key)
37
+ + [id_key](#id_key)
38
+ + [parent_key](#parent_key)
39
+ + [routing_key](#routing_key)
40
+ + [remove_keys](#remove_keys)
41
+ + [remove_keys_on_update](#remove_keys_on_update)
42
+ + [remove_keys_on_update_key](#remove_keys_on_update_key)
43
+ + [write_operation](#write_operation)
44
+ + [time_parse_error_tag](#time_parse_error_tag)
45
+ + [reconnect_on_error](#reconnect_on_error)
46
+ + [Client/host certificate options](#clienthost-certificate-options)
47
+ + [Proxy Support](#proxy-support)
48
+ + [Buffered output options](#buffered-output-options)
49
+ + [Hash flattening](#hash-flattening)
50
+ + [Not seeing a config you need?](#not-seeing-a-config-you-need)
51
+ + [Dynamic configuration](#dynamic-configuration)
52
+ * [Contact](#contact)
53
+ * [Contributing](#contributing)
54
+ * [Running tests](#running-tests)
55
+
56
+ ## Installation
57
+
58
+ ```sh
59
+ $ gem install fluent-plugin-elasticsearch
60
+ ```
61
+
62
+ ## Usage
63
+
64
+ In your Fluentd configuration, use `@type elasticsearch`. Additional configuration is optional, default values would look like this:
65
+
66
+ ```
67
+ <match my.logs>
68
+ @type elasticsearch
69
+ host localhost
70
+ port 9200
71
+ index_name fluentd
72
+ type_name fluentd
73
+ </match>
74
+ ```
75
+
76
+ ### Index templates
77
+
78
+ This plugin creates ElasticSearch indices by merely writing to them. Consider using [Index Templates](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html) to gain control of what get indexed and how. See [this example](https://github.com/uken/fluent-plugin-elasticsearch/issues/33#issuecomment-38693282) for a good starting point.
79
+
80
+ ## Configuration
81
+
82
+ ### hosts
83
+
84
+ ```
85
+ hosts host1:port1,host2:port2,host3:port3
86
+ # or
87
+ hosts https://customhost.com:443/path,https://username:password@host-failover.com:443
88
+ ```
89
+
90
+ You can specify multiple ElasticSearch hosts with separator ",".
91
+
92
+ If you specify multiple hosts, this plugin will load balance updates to ElasticSearch. This is an [elasticsearch-ruby](https://github.com/elasticsearch/elasticsearch-ruby) feature, the default strategy is round-robin.
93
+
94
+ ### user, password, path, scheme, ssl_verify
95
+
96
+ If you specify this option, host and port options are ignored.
97
+
98
+ ```
99
+ user demo
100
+ password secret
101
+ path /elastic_search/
102
+ scheme https
103
+ ```
104
+
105
+ You can specify user and password for HTTP basic auth. If used in conjunction with a hosts list, then these options will be used by default i.e. if you do not provide any of these options within the hosts listed.
106
+
107
+ Specify `ssl_verify false` to skip ssl verification (defaults to true)
108
+
109
+ ### logstash_format
110
+
111
+ ```
112
+ logstash_format true # defaults to false
113
+ ```
114
+
115
+ This is meant to make writing data into ElasticSearch indices compatible to what [Logstash](https://www.elastic.co/products/logstash) calls them. By doing this, one could take advantage of [Kibana](https://www.elastic.co/products/kibana). See logstash_prefix and logstash_dateformat to customize this index name pattern. The index name will be `#{logstash_prefix}-#{formated_date}`
116
+
117
+ ### logstash_prefix
118
+
119
+ ```
120
+ logstash_prefix mylogs # defaults to "logstash"
121
+ ```
122
+
123
+ ### logstash_dateformat
124
+
125
+ The strftime format to generate index target index name when `logstash_format` is set to true. By default, the records are inserted into index `logstash-YYYY.MM.DD`. This option, alongwith `logstash_prefix` lets us insert into specified index like `mylogs-YYYYMM` for a monthly index.
126
+
127
+ ```
128
+ logstash_dateformat %Y.%m. # defaults to "%Y.%m.%d"
129
+ ```
130
+
131
+ ### time_key_format
132
+
133
+ The format of the time stamp field (`@timestamp` or what you specify with [time_key](#time_key)). This parameter only has an effect when [logstash_format](#logstash_format) is true as it only affects the name of the index we write to. Please see [Time#strftime](http://ruby-doc.org/core-1.9.3/Time.html#method-i-strftime) for information about the value of this format.
134
+
135
+ Setting this to a known format can vastly improve your log ingestion speed if all most of your logs are in the same format. If there is an error parsing this format the timestamp will default to the ingestion time. If you are on Ruby 2.0 or later you can get a further performance improvment by installing the "strptime" gem: `fluent-gem install strptime`.
136
+
137
+ For example to parse ISO8601 times with sub-second precision:
138
+
139
+ ```
140
+ time_key_format %Y-%m-%dT%H:%M:%S.%N%z
141
+ ```
142
+
143
+ ### time_key
144
+
145
+ By default, when inserting records in [Logstash](https://www.elastic.co/products/logstash) format, `@timestamp` is dynamically created with the time at log ingestion. If you'd like to use a custom time, include an `@timestamp` with your record.
146
+
147
+ ```
148
+ {"@timestamp":"2014-04-07T000:00:00-00:00"}
149
+ ```
150
+
151
+ You can specify an option `time_key` (like the option described in [tail Input Plugin](http://docs.fluentd.org/articles/in_tail)) to replace `@timestamp` key.
152
+
153
+ Suppose you have settings
154
+
155
+ ```
156
+ logstash_format true
157
+ time_key vtm
158
+ ```
159
+
160
+ Your input is:
161
+ ```
162
+ {
163
+ "title": "developer",
164
+ "vtm": "2014-12-19T08:01:03Z"
165
+ }
166
+ ```
167
+
168
+ The output will be
169
+ ```
170
+ {
171
+ "title": "developer",
172
+ "@timestamp": "2014-12-19T08:01:03Z",
173
+ "vtm": "2014-12-19T08:01:03Z"
174
+ }
175
+ ```
176
+
177
+ See `time_key_exclude_timestamp` to avoid adding `@timestamp`.
178
+
179
+ ### time_key_exclude_timestamp
180
+
181
+ ```
182
+ time_key_exclude_timestamp false
183
+ ```
184
+
185
+ By default, setting `time_key` will copy the value to an additional field `@timestamp`. When setting `time_key_exclude_timestamp true`, no additional field will be added.
186
+
187
+ ### utc_index
188
+
189
+ ```
190
+ utc_index true
191
+ ```
192
+
193
+ By default, the records inserted into index `logstash-YYMMDD` with UTC (Coordinated Universal Time). This option allows to use local time if you describe utc_index to false.
194
+
195
+ ### target_index_key
196
+
197
+ Tell this plugin to find the index name to write to in the record under this key in preference to other mechanisms. Key can be specified as path to nested record using dot ('.') as a separator.
198
+
199
+ If it is present in the record (and the value is non falsey) the value will be used as the index name to write to and then removed from the record before output; if it is not found then it will use logstash_format or index_name settings as configured.
200
+
201
+ Suppose you have the following settings
202
+
203
+ ```
204
+ target_index_key @target_index
205
+ index_name fallback
206
+ ```
207
+
208
+ If your input is:
209
+ ```
210
+ {
211
+ "title": "developer",
212
+ "@timestamp": "2014-12-19T08:01:03Z",
213
+ "@target_index": "logstash-2014.12.19"
214
+ }
215
+ ```
216
+
217
+ The output would be
218
+
219
+ ```
220
+ {
221
+ "title": "developer",
222
+ "@timestamp": "2014-12-19T08:01:03Z",
223
+ }
224
+ ```
225
+
226
+ and this record will be written to the specified index (`logstash-2014.12.19`) rather than `fallback`.
227
+
228
+ ### target_type_key
229
+
230
+ 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").
231
+
232
+ ### template_name
233
+
234
+ The name of the template to define. If a template by the name given is already present, it will be left unchanged.
235
+
236
+ 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).
237
+
238
+ [template_file](#template_file) must also be specified.
239
+
240
+ ### template_file
241
+
242
+ The path to the file containing the template to install.
243
+
244
+ [template_name](#template_name) must also be specified.
245
+
246
+ ### templates
247
+
248
+ Specify index templates in form of hash. Can contain multiple templates.
249
+
250
+ ```
251
+ templates { "templane_name_1": "path_to_template_1_file", "templane_name_2": "path_to_template_2_file"}
252
+ ```
253
+
254
+ If `template_file` and `template_name` are set, then this parameter will be ignored.
255
+
256
+ ### request_timeout
257
+
258
+ You can specify HTTP request timeout.
259
+
260
+ This is useful when ElasticSearch cannot return response for bulk request within the default of 5 seconds.
261
+
262
+ ```
263
+ request_timeout 15s # defaults to 5s
264
+ ```
265
+
266
+ ### reload_connections
267
+
268
+ You can tune how the elasticsearch-transport host reloading feature works. By default it will reload the host list from the server every 10,000th request to spread the load. This can be an issue if your ElasticSearch cluster is behind a Reverse Proxy, as Fluentd process may not have direct network access to the ElasticSearch nodes.
269
+
270
+ ```
271
+ reload_connections false # defaults to true
272
+ ```
273
+
274
+ ### reload_on_failure
275
+
276
+ Indicates that the elasticsearch-transport will try to reload the nodes addresses if there is a failure while making the
277
+ request, this can be useful to quickly remove a dead node from the list of addresses.
278
+
279
+ ```
280
+ reload_on_failure true # defaults to false
281
+ ```
282
+
283
+ ### resurrect_after
284
+
285
+ You can set in the elasticsearch-transport how often dead connections from the elasticsearch-transport's pool will be resurrected.
286
+
287
+ ```
288
+ resurrect_after 5 # defaults to 60s
289
+ ```
290
+
291
+ ### include_tag_key, tag_key
292
+
293
+ ```
294
+ include_tag_key true # defaults to false
295
+ tag_key tag # defaults to tag
296
+ ```
297
+
298
+ This will add the Fluentd tag in the JSON record. For instance, if you have a config like this:
299
+
300
+ ```
301
+ <match my.logs>
302
+ @type elasticsearch
303
+ include_tag_key true
304
+ tag_key _key
305
+ </match>
306
+ ```
307
+
308
+ The record inserted into ElasticSearch would be
309
+
310
+ ```
311
+ {"_key":"my.logs", "name":"Johnny Doeie"}
312
+ ```
313
+
314
+ ### id_key
315
+
316
+ ```
317
+ id_key request_id # use "request_id" field as a record id in ES
318
+ ```
319
+
320
+ By default, all records inserted into ElasticSearch get a random _id. This option allows to use a field in the record as an identifier.
321
+
322
+ This following record `{"name":"Johnny","request_id":"87d89af7daffad6"}` will trigger the following ElasticSearch command
323
+
324
+ ```
325
+ { "index" : { "_index" : "logstash-2013.01.01, "_type" : "fluentd", "_id" : "87d89af7daffad6" } }
326
+ { "name": "Johnny", "request_id": "87d89af7daffad6" }
327
+ ```
328
+
329
+ ### parent_key
330
+
331
+ ```
332
+ parent_key a_parent # use "a_parent" field value to set _parent in elasticsearch command
333
+ ```
334
+
335
+ If your input is
336
+ ```
337
+ { "name": "Johnny", "a_parent": "my_parent" }
338
+ ```
339
+
340
+ ElasticSearch command would be
341
+
342
+ ```
343
+ { "index" : { "_index" : "****", "_type" : "****", "_id" : "****", "_parent" : "my_parent" } }
344
+ { "name": "Johnny", "a_parent": "my_parent" }
345
+ ```
346
+
347
+ if `parent_key` is not configed or the `parent_key` is absent in input record, nothing will happen.
348
+
349
+ ### routing_key
350
+
351
+ Similar to `parent_key` config, will add `_routing` into elasticsearch command if `routing_key` is set and the field does exist in input event.
352
+
353
+ ### remove_keys
354
+
355
+ ```
356
+ parent_key a_parent
357
+ routing_key a_routing
358
+ remove_keys a_parent, a_routing # a_parent and a_routing fields won't be sent to elasticsearch
359
+ ```
360
+
361
+ ### remove_keys_on_update
362
+
363
+ Remove keys on update will not update the configured keys in elasticsearch when a record is being updated.
364
+ This setting only has any effect if the write operation is update or upsert.
365
+
366
+ If the write setting is upsert then these keys are only removed if the record is being
367
+ updated, if the record does not exist (by id) then all of the keys are indexed.
368
+
369
+ ```
370
+ remove_keys_on_update foo,bar
371
+ ```
372
+
373
+ ### remove_keys_on_update_key
374
+
375
+ This setting allows `remove_keys_on_update` to be configured with a key in each record, in much the same way as `target_index_key` works.
376
+ The configured key is removed before indexing in elasticsearch. If both `remove_keys_on_update` and `remove_keys_on_update_key` is
377
+ present in the record then the keys in record are used, if the `remove_keys_on_update_key` is not present then the value of
378
+ `remove_keys_on_update` is used as a fallback.
379
+
380
+ ```
381
+ remove_keys_on_update_key keys_to_skip
382
+ ```
383
+
384
+ ### write_operation
385
+
386
+ The write_operation can be any of:
387
+
388
+ | Operation | Description |
389
+ | ------------- | ----------- |
390
+ | index (default) | new data is added while existing data (based on its id) is replaced (reindexed).|
391
+ | create | adds new data - if the data already exists (based on its id), the op is skipped.|
392
+ | update | updates existing data (based on its id). If no data is found, the op is skipped.|
393
+ | upsert | known as merge or insert if the data does not exist, updates if the data exists (based on its id).|
394
+
395
+ **Please note, id is required in create, update, and upsert scenario. Without id, the message will be dropped.**
396
+
397
+ ### time_parse_error_tag
398
+
399
+ With `logstash_format true`, elasticsearch plugin parses timestamp field for generating index name. If the record has invalid timestamp value, this plugin emits an error event to `@ERROR` label with `time_parse_error_tag` configured tag.
400
+
401
+ Default value is `Fluent::ElasticsearchOutput::TimeParser.error` for backward compatibility. `::` separated tag is not good for tag routing because some plugins assume tag is separated by `.`. We recommend to set this parameter like `time_parse_error_tag es_plugin.output.time.error`.
402
+ We will change default value to `.` separated tag.
403
+
404
+ ### reconnect_on_error
405
+ Indicates that the plugin should reset connection on any error (reconnect on next send).
406
+ By default it will reconnect only on "host unreachable exceptions".
407
+ We recommended to set this true in the presence of elasticsearch shield.
408
+ ```
409
+ reconnect_on_error true # defaults to false
410
+ ```
411
+
412
+ ### Client/host certificate options
413
+
414
+ Need to verify ElasticSearch's certificate? You can use the following parameter to specify a CA instead of using an environment variable.
415
+ ```
416
+ ca_file /path/to/your/ca/cert
417
+ ```
418
+
419
+ Does your ElasticSearch cluster want to verify client connections? You can specify the following parameters to use your client certificate, key, and key password for your connection.
420
+ ```
421
+ client_cert /path/to/your/client/cert
422
+ client_key /path/to/your/private/key
423
+ client_key_pass password
424
+ ```
425
+
426
+ ### Proxy Support
427
+
428
+ Starting with version 0.8.0, this gem uses excon, which supports proxy with environment variables - https://github.com/excon/excon#proxy-support
429
+
430
+ ### Buffered output options
431
+
432
+ `fluentd-plugin-elasticsearch` extends [Fluentd's builtin Buffered Output plugin](http://docs.fluentd.org/articles/buffer-plugin-overview). It adds the following options:
433
+
434
+ ```
435
+ buffer_type memory
436
+ flush_interval 60
437
+ retry_limit 17
438
+ retry_wait 1.0
439
+ num_threads 1
440
+ ```
441
+
442
+ The value for option `buffer_chunk_limit` should not exceed value `http.max_content_length` in your Elasticsearch setup (by default it is 100mb).
443
+
444
+ ### Hash flattening
445
+
446
+ Elasticsearch will complain if you send object and concrete values to the same field. For example, you might have logs that look this, from different places:
447
+
448
+ {"people" => 100}
449
+ {"people" => {"some" => "thing"}}
450
+
451
+ The second log line will be rejected by the Elasticsearch parser because objects and concrete values can't live in the same field. To combat this, you can enable hash flattening.
452
+
453
+ ```
454
+ flatten_hashes true
455
+ flatten_hashes_separator _
456
+ ```
457
+
458
+ This will produce elasticsearch output that looks like this:
459
+ {"people_some" => "thing"}
460
+
461
+ Note that the flattener does not deal with arrays at this time.
462
+
463
+ ### Not seeing a config you need?
464
+
465
+ We try to keep the scope of this plugin small and not add too many configuration options. If you think an option would be useful to others, feel free to open an issue or contribute a Pull Request.
466
+
467
+ Alternatively, consider using [fluent-plugin-forest](https://github.com/tagomoris/fluent-plugin-forest). For example, to configure multiple tags to be sent to different ElasticSearch indices:
468
+
469
+ ```
470
+ <match my.logs.*>
471
+ @type forest
472
+ subtype elasticsearch
473
+ remove_prefix my.logs
474
+ <template>
475
+ logstash_prefix ${tag}
476
+ # ...
477
+ </template>
478
+ </match>
479
+ ```
480
+
481
+ And yet another option is described in Dynamic Configuration section.
482
+
483
+ ### Dynamic configuration
484
+
485
+ If you want configurations to depend on information in messages, you can use `elasticsearch_dynamic`. This is an experimental variation of the ElasticSearch plugin allows configuration values to be specified in ways such as the below:
486
+
487
+ ```
488
+ <match my.logs.*>
489
+ @type elasticsearch_dynamic
490
+ hosts ${record['host1']}:9200,${record['host2']}:9200
491
+ index_name my_index.${Time.at(time).getutc.strftime(@logstash_dateformat)}
492
+ logstash_prefix ${tag_parts[3]}
493
+ port ${9200+rand(4)}
494
+ index_name ${tag_parts[2]}-${Time.at(time).getutc.strftime(@logstash_dateformat)}
495
+ </match>
496
+ ```
497
+
498
+ **Please note, this uses Ruby's `eval` for every message, so there are performance and security implications.**
499
+
500
+ ## Contact
501
+
502
+ If you have a question, [open an Issue](https://github.com/uken/fluent-plugin-elasticsearch/issues).
503
+
504
+ ## Contributing
505
+
506
+ There are usually a few feature requests, tagged [Easy](https://github.com/uken/fluent-plugin-elasticsearch/issues?q=is%3Aissue+is%3Aopen+label%3Alevel%3AEasy), [Normal](https://github.com/uken/fluent-plugin-elasticsearch/issues?q=is%3Aissue+is%3Aopen+label%3Alevel%3ANormal) and [Hard](https://github.com/uken/fluent-plugin-elasticsearch/issues?q=is%3Aissue+is%3Aopen+label%3Alevel%3AHard). Feel free to work on any one of them.
507
+
508
+ Pull Requests are welcomed.
509
+
510
+ [![Pull Request Graph](https://graphs.waffle.io/uken/fluent-plugin-elasticsearch/throughput.svg)](https://waffle.io/uken/fluent-plugin-elasticsearch/metrics)
511
+
512
+ ## Running tests
513
+
514
+ Install dev dependencies:
515
+
516
+ ```sh
517
+ $ gem install bundler
518
+ $ bundle install
519
+ $ bundle exec rake test
520
+ ```
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'test'
6
+ test.pattern = 'test/**/test_*.rb'
7
+ test.verbose = true
8
+ test.warning = false
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'fluent-plugin-es-mohit'
6
+ s.version = '1.9.3'
7
+ s.authors = ['mohit']
8
+ s.email = ['mohitsoral.87@gmail.com']
9
+ s.description = %q{ElasticSearch output plugin for Fluent event collector}
10
+ s.summary = s.description
11
+ s.homepage = 'https://github.com/mohit-soral/fluent-plugin-elasticsearch'
12
+ s.license = 'MIT'
13
+
14
+ s.files = `git ls-files`.split($/)
15
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
17
+ s.require_paths = ['lib']
18
+
19
+ s.required_ruby_version = Gem::Requirement.new(">= 2.0".freeze)
20
+
21
+ s.add_runtime_dependency 'fluentd', '>= 0.10.43'
22
+ s.add_runtime_dependency 'excon', '>= 0'
23
+ s.add_runtime_dependency 'elasticsearch', '< 5.0.0'
24
+
25
+
26
+ s.add_development_dependency 'rake', '>= 0'
27
+ s.add_development_dependency 'webmock', '~> 1'
28
+ s.add_development_dependency 'test-unit', '~> 3.1.0'
29
+ s.add_development_dependency 'minitest', '~> 5.8'
30
+ end
@@ -0,0 +1,37 @@
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
+ def templates_hash_install (templates)
32
+ templates.each do |key, value|
33
+ template_install(key, value)
34
+ end
35
+ end
36
+
37
+ end