fluent-plugin-elasticsearch-ruby 0.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fe858d5733f762e8524c308e4cf326398efe0a39
4
+ data.tar.gz: 4998868ebbbef1493ac61e42590da93f649948ba
5
+ SHA512:
6
+ metadata.gz: 910800a5dac6bf674c4b2e420db6b0fdf22d38a80a7dc6d5345d2bcd971c1f574eece09b1e91f43cc6ca9bc35140c3e24eb025766eea39f511de59fde6376238
7
+ data.tar.gz: 75667c912a692a921f437f0e4075f153a10e53a45d48d87f2d73d9a2cb5855eb1376dbed4f414a42d4639d8a6ecadac67b405354b89167a433a6fe30b906b98e
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-elasticsearch-ruby.gemspec
4
+ gem 'test-unit'
5
+ gem 'elasticsearch'
6
+
7
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Fluent::Plugin::Elasticsearch
2
+
3
+ I wrote this so you can search logs routed through Fluentd.
4
+
5
+ WIP - converting from tire to the official elasticsearch ruby client.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'fluent-plugin-elasticsearch-ruby'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install fluent-plugin-elasticsearch-ruby
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.pattern = 'test/**/test_*.rb'
7
+ test.verbose = true
8
+ end
9
+
10
+ task :default => :test
11
+
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fluent-plugin-elasticsearch/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "fluent-plugin-elasticsearch-ruby"
8
+ gem.version = Fluent::Plugin::Elasticsearch::VERSION
9
+ gem.authors = ["Jon"]
10
+ gem.email = ["blooberr@gmail.com"]
11
+ gem.description = %q{Fluent plugin for elasticsearch}
12
+ gem.summary = %q{Use this plugin in conjunction with elasticsearch and fluentd to log events.}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,10 @@
1
+ require "fluent-plugin-elasticsearch/version"
2
+ require 'fluent/plugin'
3
+
4
+ module Fluent
5
+ module Plugin
6
+ module Elasticsearch
7
+ # Your code goes here...
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Fluent
2
+ module Plugin
3
+ module Elasticsearch
4
+ VERSION = "0.0.2"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,61 @@
1
+ # encoding: UTF-8
2
+
3
+ class Fluent::ElasticsearchOutput < Fluent::BufferedOutput
4
+ # register plugin first.
5
+ attr_reader :es
6
+ Fluent::Plugin.register_output('elasticsearch', self)
7
+
8
+ config_param :host, :string, :default => 'localhost'
9
+ config_param :port, :integer, :default => 9200
10
+ config_param :index, :string, :default => "fluentd"
11
+
12
+ def initialize
13
+ require 'elasticsearch'
14
+ super
15
+ end
16
+
17
+ def configure(conf)
18
+ super
19
+ end
20
+
21
+ def start
22
+ super
23
+ es_url = "#{self.host}:#{self.port}"
24
+ puts "es_url: #{es_url}"
25
+ @es = Elasticsearch::Client.new hosts: [es_url]
26
+ end
27
+
28
+ def shutdown
29
+ super
30
+ end
31
+
32
+ def format(tag, time, record)
33
+ [tag, time, record].to_msgpack
34
+ end
35
+
36
+ def write(chunk)
37
+ puts "chunk - #{chunk.inspect}"
38
+ bulk_items = []
39
+
40
+ chunk.msgpack_each do |tag, time, record|
41
+ puts "#{tag} #{time} #{record}"
42
+ bulk_items << {
43
+ :index => {
44
+ :_index => self.index,
45
+ :_type => tag,
46
+ :data => {
47
+ :tag => tag,
48
+ :time => time,
49
+ :record => record
50
+ }
51
+ }
52
+ }
53
+ end
54
+
55
+ ## now bulk index
56
+ puts "bulk_items - #{bulk_items.inspect}"
57
+ @es.bulk :index => self.index, :body => bulk_items
58
+ end
59
+ ##--
60
+ end
61
+
data/test/helper.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ gem 'test-unit'
4
+ require 'test/unit'
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ require 'fluent/test'
9
+
10
+ require 'fluent/plugin/out_elasticsearch'
11
+
12
+ class Test::Unit::TestCase
13
+ end
14
+
@@ -0,0 +1,46 @@
1
+ require 'helper'
2
+
3
+ class ElasticsearchOutputTest < Test::Unit::TestCase
4
+
5
+ CONFIG_OUT_KEYS = %[
6
+ host localhost
7
+ port 9200
8
+ index fluent_es_test
9
+ ]
10
+
11
+ def setup
12
+ d = create_driver(CONFIG_OUT_KEYS)
13
+ @es_client = Elasticsearch::Client.new hosts: ["#{d.instance.host}:#{d.instance.port}"]
14
+
15
+ if @es_client.indices.exists index: d.instance.index
16
+ @es_client.indices.delete index: d.instance.index # remove the test index
17
+ end
18
+ end
19
+
20
+ def create_driver(conf=CONFIG_OUT_KEYS, tag='test-tag')
21
+ Fluent::Test::BufferedOutputTestDriver.new(Fluent::ElasticsearchOutput, tag).configure(conf)
22
+ end
23
+
24
+ def test_configure
25
+ d = create_driver(CONFIG_OUT_KEYS)
26
+
27
+ assert_equal "localhost", d.instance.host
28
+ assert_equal 9200, d.instance.port
29
+ assert_equal "fluent_es_test", d.instance.index
30
+ end
31
+
32
+ def test_indexing
33
+ d = create_driver(CONFIG_OUT_KEYS)
34
+ d.emit({"hello" => "world"})
35
+ d.emit({"why" => "not"})
36
+ d.run
37
+
38
+ # give elasticsearch time to index documents (should be under integration testing?)
39
+ sleep 2
40
+ puts "#{@es_client.search index: d.instance.index}"
41
+ count_result = @es_client.count index: d.instance.index
42
+ assert_equal 2, count_result["count"]
43
+ end
44
+
45
+ end
46
+
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-elasticsearch-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Jon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Fluent plugin for elasticsearch
14
+ email:
15
+ - blooberr@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - .gitignore
21
+ - Gemfile
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - fluent-plugin-elasticsearch-ruby.gemspec
26
+ - lib/fluent-plugin-elasticsearch.rb
27
+ - lib/fluent-plugin-elasticsearch/version.rb
28
+ - lib/fluent/plugin/out_elasticsearch.rb
29
+ - test/helper.rb
30
+ - test/plugin/test_out_elasticsearch.rb
31
+ homepage: ''
32
+ licenses: []
33
+ metadata: {}
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 2.0.3
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: Use this plugin in conjunction with elasticsearch and fluentd to log events.
54
+ test_files:
55
+ - test/helper.rb
56
+ - test/plugin/test_out_elasticsearch.rb