logstash-filter-jdbc_mysql 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 32ac2dcf1813464e8d39349513bcbfb2565c8006
4
+ data.tar.gz: d7a153be9ed1bdcc1156ec94b5bfe4761069fa02
5
+ SHA512:
6
+ metadata.gz: 6ea9d718817e15537190d4d34950bf13110a6ba5323804af83a744c3cd43d75eb5036a91da707bd6177da34b23932f6cc95868c611fc345d64f5d7e241f2357e
7
+ data.tar.gz: 06e4a254d0f449ad7855c45f543b71c9f564de53d7391dce7f3cfd30b60084773b554c27d11590a0980a208c17ab820a18738d8c04ca181686b7443b806dd6f4
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+ #gem "logstash-filter-jdbc", :github => "wiibaa/logstash-filter-jdbc", :branch => "master"
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012-2015 Elasticsearch <http://www.elasticsearch.org>
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # Logstash Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elasticsearch/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.elasticsearch.org/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/elasticsearch/docs#asciidoc-guide
13
+
14
+ ## Need Help?
15
+
16
+ Need help? Try #logstash on freenode IRC or the logstash-users@googlegroups.com mailing list.
17
+
18
+ ## Developing
19
+
20
+ ### 1. Plugin Developement and Testing
21
+
22
+ #### Code
23
+ - To get started, you'll need JRuby with the Bundler gem installed.
24
+
25
+ - Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization.
26
+
27
+ - Install dependencies
28
+ ```sh
29
+ bundle install
30
+ ```
31
+
32
+ #### Test
33
+
34
+ ```sh
35
+ bundle exec rspec
36
+ ```
37
+
38
+ The Logstash code required to run the tests/specs is specified in the `Gemfile` by the line similar to:
39
+ ```ruby
40
+ gem "logstash", :github => "elasticsearch/logstash", :branch => "1.5"
41
+ ```
42
+ To test against another version or a local Logstash, edit the `Gemfile` to specify an alternative location, for example:
43
+ ```ruby
44
+ gem "logstash", :github => "elasticsearch/logstash", :ref => "master"
45
+ ```
46
+ ```ruby
47
+ gem "logstash", :path => "/your/local/logstash"
48
+ ```
49
+
50
+ Then update your dependencies and run your tests:
51
+
52
+ ```sh
53
+ bundle install
54
+ bundle exec rspec
55
+ ```
56
+
57
+ ### 2. Running your unpublished Plugin in Logstash
58
+
59
+ #### 2.1 Run in a local Logstash clone
60
+
61
+ - Edit Logstash `tools/Gemfile` and add the local plugin path, for example:
62
+ ```ruby
63
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
64
+ ```
65
+ - Update Logstash dependencies
66
+ ```sh
67
+ rake vendor:gems
68
+ ```
69
+ - Run Logstash with your plugin
70
+ ```sh
71
+ bin/logstash -e 'filter {awesome {}}'
72
+ ```
73
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
74
+
75
+ #### 2.2 Run in an installed Logstash
76
+
77
+ - Build your plugin gem
78
+ ```sh
79
+ gem build logstash-filter-awesome.gemspec
80
+ ```
81
+ - Install the plugin from the Logstash home
82
+ ```sh
83
+ bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
84
+ ```
85
+ - Start Logstash and proceed to test the plugin
86
+
87
+ ## Contributing
88
+
89
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
90
+
91
+ 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.
92
+
93
+ It is more important to me that you are able to contribute.
94
+
95
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,96 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require "logstash/namespace"
4
+ require "logstash/filters/jdbc"
5
+
6
+ # This filter executes a SQL query and store the result set in the field
7
+ # specified as `target`.
8
+ #
9
+ # This filter is a wrapper around the generic jdbc filter for
10
+ # 1. taking care of loading the necessary jdbc driver through a gem depencendy
11
+ # 2. simplified configuration to mysql database.
12
+ # For example the following configuration:
13
+ #
14
+ # [source,ruby]
15
+ # filter {
16
+ # jdbc_mysql {
17
+ # host => "localhost"
18
+ # default_schema = "mydatabase"
19
+ # user => "me"
20
+ # password => "secret"
21
+ # statement => "select * from WORLD.COUNTRY WHERE Code = :code"
22
+ # parameters => { "code" => "country_code"}
23
+ # target => "country_details"
24
+ # }
25
+ # }
26
+ #
27
+ # is equivalent to the generic configuration
28
+ # [source,ruby]
29
+ # filter {
30
+ # jdbc {
31
+ # jdbc_driver_library => "/path/to/mysql-connector-java-5.1.34-bin.jar"
32
+ # jdbc_driver_class => "com.mysql.jdbc.Driver"
33
+ # jdbc_connection_string => "jdbc:mysql://localhost:3306/mydatabase"
34
+ # jdbc_user => "me"
35
+ # jdbc_password => "secret"
36
+ # statement => "select * from WORLD.COUNTRY WHERE Code = :code"
37
+ # parameters => { "code" => "country_code"}
38
+ # target => "country_details"
39
+ # }
40
+ # }
41
+ #
42
+ class LogStash::Filters::JdbcMysql < LogStash::Filters::Base
43
+
44
+ config_name "jdbc_mysql"
45
+
46
+ # Host of the mysql server to connect to with jdbc
47
+ config :host, :validate => :string, :required => true
48
+
49
+ # Port of the mysql server to connect to with jdbc
50
+ config :port, :validate => :number, :default => 3306
51
+
52
+ # Database username
53
+ config :user, :validate => :string
54
+
55
+ # Database user password
56
+ config :password, :validate => :password
57
+
58
+ # Database default schema
59
+ config :default_schema, :validate => :string
60
+
61
+ # Statement to execute.
62
+ # To use parameters, use named parameter syntax, for example "SELECT * FROM MYTABLE WHERE ID = :id"
63
+ config :statement, :validate => :string, :required => true
64
+
65
+ # Hash of query parameter, for example `{ "id" => "id_field" }`
66
+ config :parameters, :validate => :hash, :default => {}
67
+
68
+ # Target field to store the result set.
69
+ # Field is overwritten if exists.
70
+ config :target, :validate => :string, :required => true
71
+
72
+ # Append values to the `tags` field if sql error occured
73
+ config :tag_on_failure, :validate => :array, :default => ["_jdbcfailure"]
74
+
75
+
76
+ public
77
+ def register
78
+ require "jdbc/mysql"
79
+ Jdbc::MySQL.load_driver
80
+ @jdbc_filter = LogStash::Filters::Jdbc.new(
81
+ "jdbc_driver_class" => "com.mysql.jdbc.Driver",
82
+ "jdbc_connection_string" => "jdbc:mysql://#{host}:#{port}/#{default_schema}",
83
+ "jdbc_user" => @user,
84
+ "jdbc_password" => @password.nil? ? nil : @password.value,
85
+ "statement" => @statement,
86
+ "parameters" => @parameters,
87
+ "target" => @target
88
+ )
89
+ @jdbc_filter.register
90
+ end # def register
91
+
92
+ public
93
+ def filter(event)
94
+ @jdbc_filter.filter(event)
95
+ end # def filter
96
+ end # class LogStash::Filters::JdbcMysql
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-jdbc_mysql'
3
+ s.version = '0.1.0'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = "This filter is a wrapper around the generic jdbc filter for simplified configuration to mysql database."
6
+ s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
7
+ s.authors = ["Elastic"]
8
+ s.email = 'info@elastic.co'
9
+ s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
10
+ s.require_paths = ["lib"]
11
+
12
+ # Files
13
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
14
+
15
+ # Tests
16
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
17
+
18
+ # Special flag to let us know this is actually a logstash plugin
19
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
20
+
21
+ # Gem dependencies
22
+ s.add_runtime_dependency "logstash-core", '>= 2.0.0.beta2', '< 5.0.0'
23
+ s.add_runtime_dependency 'jdbc-mysql'
24
+ s.add_runtime_dependency 'logstash-filter-jdbc'
25
+
26
+ s.add_development_dependency 'logstash-devutils'
27
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+ require "logstash/filters/jdbc_mysql"
3
+ describe LogStash::Filters::JdbcMysql do
4
+ end
5
+
@@ -0,0 +1 @@
1
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-jdbc_mysql
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Elastic
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-06 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.0.beta2
19
+ - - <
20
+ - !ruby/object:Gem::Version
21
+ version: 5.0.0
22
+ name: logstash-core
23
+ prerelease: false
24
+ type: :runtime
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.0.beta2
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: 5.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ name: jdbc-mysql
40
+ prerelease: false
41
+ type: :runtime
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ name: logstash-filter-jdbc
54
+ prerelease: false
55
+ type: :runtime
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ name: logstash-devutils
68
+ prerelease: false
69
+ type: :development
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ description: This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program
76
+ email: info@elastic.co
77
+ executables: []
78
+ extensions: []
79
+ extra_rdoc_files: []
80
+ files:
81
+ - Gemfile
82
+ - LICENSE
83
+ - README.md
84
+ - lib/logstash/filters/jdbc_mysql.rb
85
+ - logstash-filter-jdbc_mysql.gemspec
86
+ - spec/filters/jdbc_mysql_spec.rb
87
+ - spec/spec_helper.rb
88
+ homepage: http://www.elastic.co/guide/en/logstash/current/index.html
89
+ licenses:
90
+ - Apache License (2.0)
91
+ metadata:
92
+ logstash_plugin: 'true'
93
+ logstash_group: filter
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.8
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: This filter is a wrapper around the generic jdbc filter for simplified configuration to mysql database.
114
+ test_files:
115
+ - spec/filters/jdbc_mysql_spec.rb
116
+ - spec/spec_helper.rb