logstash-input-elastic_jdbc 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +2 -0
- data/CONTRIBUTORS +10 -0
- data/DEVELOPER.md +2 -0
- data/Gemfile +12 -0
- data/LICENSE +11 -0
- data/README.md +107 -0
- data/lib/logstash/inputs/elastic_jdbc.rb +81 -0
- data/lib/logstash/inputs/value_tracking.rb +87 -0
- data/logstash-input-elastic-jdbc.gemspec +26 -0
- data/spec/inputs/elastic-jdbc_spec.rb +11 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 03f49ece3284c2f8e8d6ad338af961f25403ca08fc780aa2243aa2fb7a8c77cc
|
4
|
+
data.tar.gz: 50bbff1c78e0595d85a9d9f5b6a85d96e33ea7e94a4e2fb844c07165816ebf18
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2c4ed56a6b061da002ee7fe84dcf70fdf68af9271f18ed959e668922269253d55d75d25dba430705389e167e0d1549da62eabf959b560d321aba719122b83a38
|
7
|
+
data.tar.gz: 5cc7cd3fa424730b1eb69c6d4b75fc5d4678be93d9fbedd063fabebec15e5355bdf5b8b8733508ec09266aece6487c4c30d2c17c92b6ab48406bdbf10f5e1994
|
data/CHANGELOG.md
ADDED
data/CONTRIBUTORS
ADDED
@@ -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
|
+
* -
|
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.
|
data/DEVELOPER.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
gemspec
|
3
|
+
|
4
|
+
logstash_path = ENV["LOGSTASH_PATH"] || "../../logstash"
|
5
|
+
use_logstash_source = ENV["LOGSTASH_SOURCE"] && ENV["LOGSTASH_SOURCE"].to_s == "1"
|
6
|
+
|
7
|
+
if Dir.exist?(logstash_path) && use_logstash_source
|
8
|
+
gem 'logstash-core', :path => "#{logstash_path}/logstash-core"
|
9
|
+
gem 'logstash-core-plugin-api', :path => "#{logstash_path}/logstash-core-plugin-api"
|
10
|
+
end
|
11
|
+
|
12
|
+
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
# Logstash Plugin
|
2
|
+
[GitHub](https://github.com/ernesrocker/RubyGems).
|
3
|
+
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
4
|
+
|
5
|
+
It is fully free and fully open source.
|
6
|
+
|
7
|
+
## Documentation
|
8
|
+
This plugin inherit of elasticsearch input plugin, and added a tracking_column
|
9
|
+
using in jdbc input plugin for make a query to obtain the updates values
|
10
|
+
Sample :
|
11
|
+
input {
|
12
|
+
# Read all documents from Elasticsearch matching the given query
|
13
|
+
elastic_jdbc {
|
14
|
+
hosts => "localhost"
|
15
|
+
tracking_column => "last_update"
|
16
|
+
last_run_metadata_path => "/path_file"
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
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/).
|
21
|
+
|
22
|
+
- For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
|
23
|
+
- For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
|
24
|
+
|
25
|
+
## Need Help?
|
26
|
+
|
27
|
+
Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
|
28
|
+
|
29
|
+
## Developing
|
30
|
+
|
31
|
+
### 1. Plugin Developement and Testing
|
32
|
+
|
33
|
+
#### Code
|
34
|
+
- To get started, you'll need JRuby with the Bundler gem installed.
|
35
|
+
|
36
|
+
- 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).
|
37
|
+
|
38
|
+
- Install dependencies
|
39
|
+
```sh
|
40
|
+
bundle install
|
41
|
+
```
|
42
|
+
|
43
|
+
#### Test
|
44
|
+
|
45
|
+
- Update your dependencies
|
46
|
+
|
47
|
+
```sh
|
48
|
+
bundle install
|
49
|
+
```
|
50
|
+
|
51
|
+
- Run tests
|
52
|
+
|
53
|
+
```sh
|
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 `Gemfile` and add the local plugin path, for example:
|
62
|
+
```ruby
|
63
|
+
gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
|
64
|
+
```
|
65
|
+
- Install plugin
|
66
|
+
```sh
|
67
|
+
# Logstash 2.3 and higher
|
68
|
+
bin/logstash-plugin install --no-verify
|
69
|
+
|
70
|
+
# Prior to Logstash 2.3
|
71
|
+
bin/plugin install --no-verify
|
72
|
+
|
73
|
+
```
|
74
|
+
- Run Logstash with your plugin
|
75
|
+
```sh
|
76
|
+
bin/logstash -e 'filter {awesome {}}'
|
77
|
+
```
|
78
|
+
At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
|
79
|
+
|
80
|
+
#### 2.2 Run in an installed Logstash
|
81
|
+
|
82
|
+
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:
|
83
|
+
|
84
|
+
- Build your plugin gem
|
85
|
+
```sh
|
86
|
+
gem build logstash-filter-awesome.gemspec
|
87
|
+
```
|
88
|
+
- Install the plugin from the Logstash home
|
89
|
+
```sh
|
90
|
+
# Logstash 2.3 and higher
|
91
|
+
bin/logstash-plugin install --no-verify
|
92
|
+
|
93
|
+
# Prior to Logstash 2.3
|
94
|
+
bin/plugin install --no-verify
|
95
|
+
|
96
|
+
```
|
97
|
+
- Start Logstash and proceed to test the plugin
|
98
|
+
|
99
|
+
## Contributing
|
100
|
+
|
101
|
+
All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
|
102
|
+
|
103
|
+
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.
|
104
|
+
|
105
|
+
It is more important to the community that you are able to contribute.
|
106
|
+
|
107
|
+
For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/inputs/base"
|
3
|
+
require "logstash/inputs/elasticsearch"
|
4
|
+
require_relative "value_tracking"
|
5
|
+
require "json"
|
6
|
+
require "logstash/json"
|
7
|
+
require "time"
|
8
|
+
|
9
|
+
# This plugin is a simple extension of Elasticsearch input plugin. We added tracking_column property
|
10
|
+
# for search in elasticsearch query all hits that contains the 'last_update' value bigger that the value_tracker.
|
11
|
+
# The value_tracker contains the last consult to that index stored in a last run file created.
|
12
|
+
# We build the query based on the above described.
|
13
|
+
# This is a sample of elastic_jdbc plugin statement:
|
14
|
+
# input {
|
15
|
+
# # Read all documents from Elasticsearch matching the given query
|
16
|
+
# elastic_jdbc {
|
17
|
+
# hosts => "localhost"
|
18
|
+
# tracking_column => "last_update"
|
19
|
+
# last_run_metadata_path => "/opt/logstash/last_run/index_name"
|
20
|
+
# }
|
21
|
+
# }
|
22
|
+
#
|
23
|
+
class LogStash::Inputs::ElasticJdbc < LogStash::Inputs::Elasticsearch
|
24
|
+
config_name "elastic_jdbc"
|
25
|
+
|
26
|
+
#region tracking configuration
|
27
|
+
# Path to file with last run time
|
28
|
+
config :last_run_metadata_path, :validate => :string, :default => "#{ENV['HOME']}/.logstash_jdbc_last_run"
|
29
|
+
|
30
|
+
# If tracking column value rather than timestamp, the column whose value is to be tracked
|
31
|
+
config :tracking_column, :validate => :string
|
32
|
+
|
33
|
+
# Type of tracking column. Currently only "numeric" and "timestamp"
|
34
|
+
config :tracking_column_type, :validate => ['timestamp'], :default => 'timestamp'
|
35
|
+
|
36
|
+
# Whether the previous run state should be preserved
|
37
|
+
config :clean_run, :validate => :boolean, :default => false
|
38
|
+
|
39
|
+
# Whether to save state or not in last_run_metadata_path
|
40
|
+
config :record_last_run, :validate => :boolean, :default => true
|
41
|
+
|
42
|
+
#endregion
|
43
|
+
|
44
|
+
public
|
45
|
+
def register
|
46
|
+
super()
|
47
|
+
if @tracking_column.nil?
|
48
|
+
raise(LogStash::ConfigurationError, "Must set :tracking_column if :use_column_value is true.")
|
49
|
+
end
|
50
|
+
set_value_tracker(ValueTracking.build_last_value_tracker(self))
|
51
|
+
build_query()
|
52
|
+
end # def register
|
53
|
+
|
54
|
+
def set_value_tracker(instance)
|
55
|
+
@value_tracker = instance
|
56
|
+
end
|
57
|
+
|
58
|
+
def build_query
|
59
|
+
time_now = Time.now.utc
|
60
|
+
last_value = @value_tracker ? Time.parse(@value_tracker.value.to_s).iso8601 : Time.parse(time_now).iso8601
|
61
|
+
column = @tracking_column.to_s
|
62
|
+
query = {query: { range: {column => {gt: last_value.to_s}}}, sort: [{column => {order: "desc"}}]}
|
63
|
+
@query = query.to_json
|
64
|
+
@base_query = LogStash::Json.load(@query)
|
65
|
+
end
|
66
|
+
|
67
|
+
def run(queue)
|
68
|
+
begin
|
69
|
+
super(queue)
|
70
|
+
rescue => e
|
71
|
+
@logger.error("Failed running elastic_jdbc plugin", :exception => e)
|
72
|
+
else
|
73
|
+
@value_tracker.set_value(Time.now.to_s)
|
74
|
+
@value_tracker.write
|
75
|
+
end
|
76
|
+
end # def run
|
77
|
+
|
78
|
+
def stop
|
79
|
+
super()
|
80
|
+
end
|
81
|
+
end # class LogStash::Inputs::ElasticJdbc
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require "yaml" # persistence
|
2
|
+
class ValueTracking
|
3
|
+
|
4
|
+
def self.build_last_value_tracker(plugin)
|
5
|
+
handler = NullFileHandler.new(plugin.last_run_metadata_path)
|
6
|
+
if plugin.record_last_run
|
7
|
+
handler = FileHandler.new(plugin.last_run_metadata_path)
|
8
|
+
end
|
9
|
+
if plugin.clean_run
|
10
|
+
handler.clean
|
11
|
+
end
|
12
|
+
instance = DateTimeValueTracker.new(handler)
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :value
|
16
|
+
|
17
|
+
def initialize(handler)
|
18
|
+
@file_handler = handler
|
19
|
+
set_value(get_initial)
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_initial
|
23
|
+
# override in subclass
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_value(value)
|
27
|
+
# override in subclass
|
28
|
+
end
|
29
|
+
|
30
|
+
def write
|
31
|
+
@file_handler.write(@value.to_s)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
class DateTimeValueTracker < ValueTracking
|
37
|
+
def get_initial
|
38
|
+
@file_handler.read || DateTime.new(1970)
|
39
|
+
end
|
40
|
+
|
41
|
+
def set_value(value)
|
42
|
+
if value.respond_to?(:to_datetime)
|
43
|
+
@value = value.to_datetime
|
44
|
+
else
|
45
|
+
@value = DateTime.parse(value)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class FileHandler
|
51
|
+
def initialize(path)
|
52
|
+
@path = path
|
53
|
+
@exists = ::File.exist?(@path)
|
54
|
+
end
|
55
|
+
|
56
|
+
def clean
|
57
|
+
return unless @exists
|
58
|
+
::File.delete(@path)
|
59
|
+
@exists = false
|
60
|
+
end
|
61
|
+
|
62
|
+
def read
|
63
|
+
return unless @exists
|
64
|
+
YAML.load(::File.read(@path))
|
65
|
+
end
|
66
|
+
|
67
|
+
def write(value)
|
68
|
+
::File.write(@path, YAML.dump(value))
|
69
|
+
@exists = true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class NullFileHandler
|
74
|
+
def initialize(path)
|
75
|
+
end
|
76
|
+
|
77
|
+
def clean
|
78
|
+
end
|
79
|
+
|
80
|
+
def read
|
81
|
+
end
|
82
|
+
|
83
|
+
def write(value)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.name = 'logstash-input-elastic_jdbc'
|
4
|
+
s.version = '0.1.0'
|
5
|
+
s.licenses = ['Apache-2.0']
|
6
|
+
s.summary = 'Logstash elastic_jdbc'
|
7
|
+
s.description = 'This plugin inherit of elasticsearch input plugin, but added tracking_column like jdbc input plugin.'
|
8
|
+
s.homepage = 'https://github.com/ernesrocker/RubyGems'
|
9
|
+
s.authors = ['Ernesto Soler Calaña']
|
10
|
+
s.email = 'ernes920825@gmail.com'
|
11
|
+
s.require_paths = ['lib']
|
12
|
+
|
13
|
+
# Files
|
14
|
+
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
|
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" => "input" }
|
20
|
+
|
21
|
+
# Gem dependencies
|
22
|
+
s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
|
23
|
+
s.add_runtime_dependency 'logstash-codec-plain'
|
24
|
+
s.add_runtime_dependency 'stud', '>= 0.0.22'
|
25
|
+
s.add_development_dependency 'logstash-devutils', '~> 0.0', '>= 0.0.16'
|
26
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/devutils/rspec/spec_helper"
|
3
|
+
require "logstash/inputs/elastic_jdbc"
|
4
|
+
|
5
|
+
describe LogStash::Inputs::ElasticJdbc do
|
6
|
+
|
7
|
+
it_behaves_like "an interruptible input plugin" do
|
8
|
+
let(:config) { { "interval" => 100 } }
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-input-elastic_jdbc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ernesto Soler Calaña
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: logstash-core-plugin-api
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
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
|
+
name: logstash-codec-plain
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: stud
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.0.22
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.0.22
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: logstash-devutils
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.0'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 0.0.16
|
65
|
+
type: :development
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0.0'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.0.16
|
75
|
+
description: This plugin inherit of elasticsearch input plugin, but added tracking_column
|
76
|
+
like jdbc input plugin.
|
77
|
+
email: ernes920825@gmail.com
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- CHANGELOG.md
|
83
|
+
- CONTRIBUTORS
|
84
|
+
- DEVELOPER.md
|
85
|
+
- Gemfile
|
86
|
+
- LICENSE
|
87
|
+
- README.md
|
88
|
+
- lib/logstash/inputs/elastic_jdbc.rb
|
89
|
+
- lib/logstash/inputs/value_tracking.rb
|
90
|
+
- logstash-input-elastic-jdbc.gemspec
|
91
|
+
- spec/inputs/elastic-jdbc_spec.rb
|
92
|
+
homepage: https://github.com/ernesrocker/RubyGems
|
93
|
+
licenses:
|
94
|
+
- Apache-2.0
|
95
|
+
metadata:
|
96
|
+
logstash_plugin: 'true'
|
97
|
+
logstash_group: input
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.7.6
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: Logstash elastic_jdbc
|
118
|
+
test_files:
|
119
|
+
- spec/inputs/elastic-jdbc_spec.rb
|