logstash-output-rethinkdb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5cdd73fc4f9e95db9f74f68eb7f6d1a666516edf31db76ba4bc34e5ad4466a18
4
+ data.tar.gz: ff7b12efd453bb2ca1d72c15ae1ab267e573cee32a6727211a38991dcb7ed246
5
+ SHA512:
6
+ metadata.gz: 74a9047114c05ab0ddea018ff28d9ffcfe5d088800187eddbb9a734b3e30b898584bbb311d2cfc505a2f63581e7cf83fe2c354a214c5bb654c7bfda532b510ec
7
+ data.tar.gz: 55698dbf538461d2d421a581d978b30a73c99352316398d4b16ff8b8b9bcf1fb4b3770dbb5691419f82689fe6c5e708145211e82c4b842c719b91031a5194a04
@@ -0,0 +1,2 @@
1
+ ## 0.1.0
2
+ - Plugin created with the logstash plugin generator
@@ -0,0 +1,10 @@
1
+ The following is a list of people who have contributed ideas, code, bug
2
+ reports, or in general have helped logstash along its way.
3
+
4
+ Contributors:
5
+ * Dane Jensen - dane.jensen@gmail.com
6
+
7
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
8
+ Logstash, and you aren't on the list above and want to be, please let us know
9
+ and we'll make sure you're here. Contributions from folks like you are what make
10
+ open source awesome.
@@ -0,0 +1,2 @@
1
+ # logstash-output-rethinkdb
2
+ Example output plugin. This should help bootstrap your effort to write your own output plugin!
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Licensed under the Apache License, Version 2.0 (the "License");
2
+ you may not use this file except in compliance with the License.
3
+ You may obtain a copy of the License at
4
+
5
+ http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
@@ -0,0 +1,88 @@
1
+ # Logstash Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
+
5
+ It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
6
+
7
+ ## Documentation
8
+
9
+ Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
10
+
11
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
12
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
13
+
14
+ ## Need Help?
15
+
16
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
17
+
18
+ ## Developing
19
+
20
+ https://www.elastic.co/guide/en/logstash/current/_how_to_write_a_logstash_output_plugin.html
21
+
22
+ ### 1. Plugin Developement and Testing
23
+
24
+ #### Code
25
+ - To get started, you'll need JRuby with the Bundler gem installed.
26
+
27
+ - Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
28
+
29
+ - Install dependencies
30
+ ```sh
31
+ bundle install
32
+ ```
33
+
34
+ #### Test
35
+
36
+ - Update your dependencies
37
+
38
+ ```sh
39
+ bundle install
40
+ ```
41
+
42
+ - Run tests
43
+
44
+ ```sh
45
+ bundle exec rspec
46
+ ```
47
+
48
+ ### 2. Running your unpublished Plugin in Logstash
49
+
50
+ #### 2.1 Run in a local Logstash clone
51
+
52
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
53
+ ```ruby
54
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
55
+ ```
56
+ - Install plugin
57
+ ```sh
58
+ bin/logstash-plugin install --no-verify
59
+ ```
60
+ - Run Logstash with your plugin
61
+ ```sh
62
+ bin/logstash -e 'filter {awesome {}}'
63
+ ```
64
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
65
+
66
+ #### 2.2 Run in an installed Logstash
67
+
68
+ You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
69
+
70
+ - Build your plugin gem
71
+ ```sh
72
+ gem build logstash-filter-awesome.gemspec
73
+ ```
74
+ - Install the plugin from the Logstash home
75
+ ```sh
76
+ bin/logstash-plugin install /your/local/plugin/logstash-filter-awesome.gem
77
+ ```
78
+ - Start Logstash and proceed to test the plugin
79
+
80
+ ## Contributing
81
+
82
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
83
+
84
+ Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
85
+
86
+ It is more important to the community that you are able to contribute.
87
+
88
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
4
+ require 'logstash/outputs/base'
5
+ require 'logstash/namespace'
6
+
7
+ require 'rethinkdb'
8
+
9
+ class LogStash::Outputs::Rethinkdb < LogStash::Outputs::Base
10
+ include RethinkDB::Shortcuts
11
+ # include Stud::Buffer
12
+
13
+ config_name 'rethinkdb'
14
+ concurrency :shared
15
+ default :codec, 'json'
16
+ # attr_accessor :logger
17
+
18
+ # Hostname of RethinkDB server
19
+ config :host, validate: :string, default: 'localhost'
20
+ # Driver connection port of RethinkDB server
21
+ config :port, validate: :number, default: 28_015
22
+ # Auth key of RethinkDB server (don't provide if nil)
23
+ config :auth_key, validate: :string, default: ''
24
+ # Which tables to watch for changes
25
+ config :table, validate: :string
26
+ config :database, validate: :string
27
+ # ssl support
28
+ config :ca_certs, default: nil
29
+ # Credentials as of RethinkDB v2.3.x
30
+ config :user, validate: :string, default: 'admin'
31
+ config :password, validate: :string, default: ''
32
+
33
+ # used in https://github.com/logstash-plugins/logstash-output-redis
34
+ # which we may want to work in here too
35
+
36
+ # # If true, we send an RPUSH every "batch_events" events or
37
+ # # "batch_timeout" seconds (whichever comes first).
38
+ # # Only supported for `data_type` is "list".
39
+ # config :batch, :validate => :boolean, :default => false
40
+
41
+ # # If batch is set to true, the number of events we queue up for an RPUSH.
42
+ # config :batch_events, :validate => :number, :default => 50
43
+
44
+ # # If batch is set to true, the maximum amount of time between RPUSH commands
45
+ # # when there are pending events to flush.
46
+ # config :batch_timeout, :validate => :number, :default => 5
47
+
48
+ def register
49
+ @codec.on_event(&method(:send_to_rethink))
50
+ create_table
51
+ end
52
+
53
+ def close
54
+ connection.close
55
+ end
56
+
57
+ def receive(event)
58
+ @codec.encode(event)
59
+ rescue LocalJumpError
60
+ # This LocalJumpError rescue clause is required to test for regressions
61
+ # for https://github.com/logstash-plugins/logstash-output-redis/issues/26
62
+ # see specs. Without it the LocalJumpError is rescued by the StandardError
63
+ raise
64
+ rescue StandardError => e
65
+ @logger.warn('Error encoding event', exception: e,
66
+ event: event)
67
+ end
68
+
69
+ protected
70
+
71
+ def create_table
72
+ return false if self.database.table_list.run(self.connection).include?(@table)
73
+ self.database.table_create(@table).run(self.connection)
74
+ end
75
+
76
+ def send_to_rethink(event, payload)
77
+ table.insert(JSON.parse(payload, symbolize_names: true)).run(self.connection)
78
+ rescue => e
79
+ pp e
80
+ @logger.warn('Failed to send event to Redis', event: event,
81
+ identity: identity, exception: e,
82
+ backtrace: e.backtrace)
83
+ sleep @reconnect_interval
84
+ @redis = nil
85
+ retry
86
+ end
87
+
88
+ def connection
89
+ @connection ||= begin
90
+ ssl = ({ ca_certs: @ca_certs } if @ca_certs)
91
+ if @auth_key == ''
92
+ r.connect(
93
+ host: @host,
94
+ port: @port,
95
+ user: @user,
96
+ password: @password,
97
+ ssl: ssl
98
+ )
99
+ else
100
+ r.connect(
101
+ host: @host,
102
+ port: @port,
103
+ auth_key: @auth_key,
104
+ ssl: ssl
105
+ )
106
+ end
107
+ end
108
+ end
109
+
110
+ def database
111
+ r.db(@database)
112
+ end
113
+
114
+ def table
115
+ r.table(@table)
116
+ end
117
+
118
+ # A string used to identify a RethinkDB instance in log messages
119
+ def identity
120
+ # "redis://#{@password}@#{@current_host}:#{@current_port}/#{@db} #{@data_type}:#{@key}"
121
+ 'rethinkdb://TODO'
122
+ end
123
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'logstash-output-rethinkdb'
5
+ s.version = '0.1.0'
6
+ s.licenses = ['Apache-2.0']
7
+ s.summary = 'Write a short summary, because Rubygems requires one.'
8
+ s.description = 'Write a longer description or delete this line.'
9
+ s.homepage = 'http://example.com/'
10
+ s.authors = ['Dane Jensen']
11
+ s.email = 'djensen@apericorp.com'
12
+ s.require_paths = ['lib']
13
+
14
+ # Files
15
+ s.files = Dir['lib/**/*',
16
+ 'spec/**/*',
17
+ 'vendor/**/*',
18
+ '*.gemspec',
19
+ '*.md',
20
+ 'CONTRIBUTORS',
21
+ 'Gemfile',
22
+ 'LICENSE',
23
+ 'NOTICE.TXT'
24
+ ]
25
+ # Tests
26
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
27
+
28
+ # Special flag to let us know this is actually a logstash plugin
29
+ s.metadata = { 'logstash_plugin' => 'true', 'logstash_group' => 'output' }
30
+
31
+ # Gem dependencies
32
+ s.add_runtime_dependency 'logstash-core-plugin-api', '~> 2.0'
33
+
34
+ # for bufffering
35
+ # s.add_runtime_dependency 'stud'
36
+
37
+ s.add_runtime_dependency 'rethinkdb', '~> 2.3'
38
+
39
+ s.add_development_dependency 'logstash-codec-json'
40
+ s.add_development_dependency 'logstash-devutils'
41
+ s.add_development_dependency 'logstash-input-generator'
42
+ s.add_development_dependency 'rspec'
43
+ s.add_development_dependency 'rubocop'
44
+ # s.add_development_dependency 'flores'
45
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'spec_helper'
5
+
6
+ describe LogStash::Outputs::Rethinkdb do
7
+ let(:sample_event) { LogStash::Event.new }
8
+
9
+ let(:extra_config) { {} }
10
+ let(:default_config) do
11
+ {
12
+ 'database' => 'test',
13
+ 'table' => 'events'
14
+ }
15
+ end
16
+ let(:redis_config) do
17
+ default_config.merge(extra_config)
18
+ end
19
+ let(:rethinkdb_output) { described_class.new(redis_config) }
20
+
21
+ before do
22
+ rethinkdb_output.register
23
+ end
24
+
25
+ describe 'receive message' do
26
+ subject(:result) { rethinkdb_output.receive(sample_event) }
27
+ it 'inserts the records' do
28
+ expect(result['inserted']).to eq 1
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logstash/devutils/rspec/spec_helper'
4
+ require 'logstash/outputs/rethinkdb'
5
+ require 'logstash/codecs/plain'
6
+ require 'logstash/event'
7
+
8
+ RSpec.configure do |config|
9
+ config.before do
10
+ RethinkHelper.clear_db
11
+ end
12
+
13
+ config.after(:suite) do
14
+ RethinkHelper.clear_db
15
+ end
16
+ end
17
+
18
+ class RethinkHelper
19
+ include RethinkDB::Shortcuts
20
+
21
+ def self.clear_db
22
+ self.new.clear_db
23
+ end
24
+
25
+ def initialize
26
+ @conn = r.connect(host: '127.0.0.1', port: 28_015, db: 'test')
27
+ end
28
+
29
+ def clear_db
30
+ r.db('test').table('events').delete.run(@conn)
31
+ end
32
+ end
@@ -0,0 +1,4 @@
1
+ http.host: "0.0.0.0"
2
+ path.config: /usr/share/logstash/pipeline
3
+ xpack.monitoring.enabled: false
4
+ config.reload.automatic: true
@@ -0,0 +1,22 @@
1
+ input {
2
+ file {
3
+ path => "/srv/code/tmp/test.log"
4
+ }
5
+ }
6
+
7
+ filter {
8
+ split {
9
+ terminator => " "
10
+ }
11
+ }
12
+
13
+ output {
14
+ stdout {
15
+ codec => rubydebug
16
+ }
17
+ rethinkdb {
18
+ host => '172.18.0.3'
19
+ table => 'events'
20
+ database => 'test'
21
+ }
22
+ }
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-rethinkdb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dane Jensen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ name: logstash-core-plugin-api
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.3'
33
+ name: rethinkdb
34
+ prerelease: false
35
+ type: :runtime
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.3'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ name: logstash-codec-json
48
+ prerelease: false
49
+ type: :development
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ name: logstash-devutils
62
+ prerelease: false
63
+ type: :development
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ name: logstash-input-generator
76
+ prerelease: false
77
+ type: :development
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ name: rspec
90
+ prerelease: false
91
+ type: :development
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ name: rubocop
104
+ prerelease: false
105
+ type: :development
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Write a longer description or delete this line.
112
+ email: djensen@apericorp.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - CHANGELOG.md
118
+ - CONTRIBUTORS
119
+ - DEVELOPER.md
120
+ - Gemfile
121
+ - LICENSE
122
+ - README.md
123
+ - lib/logstash/outputs/rethinkdb.rb
124
+ - logstash-output-rethinkdb.gemspec
125
+ - spec/outputs/rethinkdb_spec.rb
126
+ - spec/spec_helper.rb
127
+ - spec/support/logstash.yml
128
+ - spec/support/pipeline/simple.conf
129
+ homepage: http://example.com/
130
+ licenses:
131
+ - Apache-2.0
132
+ metadata:
133
+ logstash_plugin: 'true'
134
+ logstash_group: output
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.6.11
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Write a short summary, because Rubygems requires one.
155
+ test_files:
156
+ - spec/outputs/rethinkdb_spec.rb
157
+ - spec/spec_helper.rb
158
+ - spec/support/logstash.yml
159
+ - spec/support/pipeline/simple.conf