logstash-input-multirds 0.0.1

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: e397a301602ab70c6241f3e12f97f0b748868ca3
4
+ data.tar.gz: fb55e7f3bccd472bbef7a8fc3a02b1277bf812d6
5
+ SHA512:
6
+ metadata.gz: 3ae26cdbf5cbab8f1a863a7cce692351b7775b1af471360c3df2e808c85a8b9c4828deaff09d4caca909e375094f9999533819b1f9427ecf990668e50ffb5f61
7
+ data.tar.gz: bc3d45b3f9fad096079233c7c766e66ff80060b1993dfb2f6f0361f11413404b083d6d6c2a9c496e95bc25debfc067671c783c2c8c02de92fcd6da614e4ea67a
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ 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.
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # Logstash Input Multi-RDS
2
+
3
+ Forked from discourse/logstash-input-rds I needed competing consumer and multi-db support
4
+ input {
5
+ rds {
6
+ region => "us-west-2"
7
+ instance_name_pattern => ".*"
8
+ log_file_name_pattern => ".*"
9
+ group_name => "rds"
10
+ }
11
+ }
@@ -0,0 +1,12 @@
1
+ require 'aws-sdk'
2
+
3
+ begin
4
+ old_stderr = $stderr
5
+ $stderr = StringIO.new
6
+
7
+ module Aws
8
+ const_set(:RDS, Aws::RDS)
9
+ end
10
+ ensure
11
+ $stderr = old_stderr
12
+ end
@@ -0,0 +1,100 @@
1
+ # encoding: utf-8
2
+ require "logstash/inputs/base"
3
+ require "logstash/namespace"
4
+ require "stud/interval"
5
+ require "aws-sdk"
6
+ require "logstash/inputs/rds/patch"
7
+ require "logstash/plugin_mixins/aws_config"
8
+ require "time"
9
+
10
+ Aws.eager_autoload!
11
+
12
+ class LogStash::Inputs::Multirds < LogStash::Inputs::Base
13
+ include LogStash::PluginMixins::AwsConfig::V2
14
+
15
+ config_name "multirds"
16
+ milestone 1
17
+ default :codec, "plain"
18
+
19
+ config :instance_name_pattern, :validate => :string, :required => true
20
+ config :log_file_name_pattern, :validate => :string, :required => true
21
+ config :polling_frequency, :validate => :number, :default => 600
22
+ config :group_name, :validate => :string, :required => true
23
+
24
+ def register
25
+ # @logger.info "Registering multi-RDS input", :region => @region, :instance => @instance_name, :log_file => @log_file_name
26
+ # @database = Aws::RDS::DBInstance.new @instance_name, aws_options_hash
27
+ # path = @sincedb_path || File.join(ENV["HOME"], ".sincedb_" + Digest::MD5.hexdigest("#{@instance_name}+#{@log_file_name}"))
28
+ # @sincedb = SinceDB::File.new path
29
+ @logger.info "Registering multi-rds input", :instance_name_pattern => @instance_name_pattern, :log_file_name_pattern => @log_file_name_pattern, :group_name = @group_name
30
+ @db = Aws::DynamoDB::Client.new
31
+ @rds = Aws::RDS::Client.new
32
+ # TODO: Auto-create dynamodb table here -- should that be a param?
33
+ end
34
+
35
+ def run(queue)
36
+ @thread = Thread.current
37
+ Stud.interval(@polling_frequency) do
38
+ @logger.debug "finding #{@log_file_name} for #{@instance_name} starting #{@sincedb.read} (#{@sincedb.read.to_i * 1000})"
39
+ begin
40
+ logfiles = @database.log_files({
41
+ filename_contains: @log_file_name,
42
+ file_last_written: @sincedb.read.to_i * 1000,
43
+ })
44
+ logfiles.each do |logfile|
45
+ @logger.debug "downloading #{logfile.name} for #{@instance_name}"
46
+ more = true
47
+ marker = "0"
48
+ while more do
49
+ response = logfile.download({marker: marker})
50
+ response[:log_file_data].lines.each do |line|
51
+ @codec.decode(line) do |event|
52
+ decorate event
53
+ event.set "rds_instance", @instance_name
54
+ event.set "log_file", @log_file_name
55
+ queue << event
56
+ end
57
+ end
58
+ more = response[:additional_data_pending]
59
+ marker = response[:marker]
60
+ end
61
+ @sincedb.write (filename2datetime logfile.name)
62
+ end
63
+ rescue Aws::RDS::Errors::ServiceError
64
+ # the next iteration will resume at the same location
65
+ @logger.warn "caught AWS service error"
66
+ end
67
+ end
68
+ end
69
+
70
+ def stop
71
+ Stud.stop! @thread
72
+ end
73
+
74
+ def filename2datetime(name)
75
+ parts = name.match /(\d{4})-(\d{2})-(\d{2})-(\d{2})$/
76
+ Time.utc parts[1], parts[2], parts[3], parts[4]
77
+ end
78
+
79
+ private
80
+ module SinceDB
81
+ class File
82
+ def initialize(file)
83
+ @db = file
84
+ end
85
+
86
+ def read
87
+ if ::File.exists?(@db)
88
+ content = ::File.read(@db).chomp.strip
89
+ return content.empty? ? Time.new : Time.parse(content)
90
+ else
91
+ return Time.new("1999-01-01")
92
+ end
93
+ end
94
+
95
+ def write(time)
96
+ ::File.open(@db, 'w') { |file| file.write time.to_s }
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-input-multirds'
3
+ s.version = '0.0.1'
4
+ s.summary = 'Ingest RDS log files to Logstash with competing consumers and multiple databases'
5
+
6
+ s.authors = ['Robert Labrie']
7
+ s.email = ['robert.labrie@gmail.com']
8
+ s.homepage = 'https://github.com/robertlabrie/logstash-input-multi-rds'
9
+
10
+ s.require_paths = ['lib']
11
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
12
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
13
+
14
+ # Special flag to let us know this is actually a logstash plugin
15
+ s.metadata = { 'logstash_plugin' => 'true', 'logstash_group' => 'input' }
16
+
17
+ # Gem dependencies
18
+ s.add_runtime_dependency 'logstash-core-plugin-api', '~> 2.0'
19
+ s.add_runtime_dependency 'logstash-codec-plain'
20
+ s.add_runtime_dependency 'logstash-mixin-aws'
21
+ s.add_runtime_dependency 'stud', '>= 0.0.22'
22
+ s.add_development_dependency 'logstash-devutils', '>= 0.0.16'
23
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-input-multirds
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Robert Labrie
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-11-21 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: logstash-mixin-aws
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: stud
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.22
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.0.22
69
+ - !ruby/object:Gem::Dependency
70
+ name: logstash-devutils
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.0.16
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.0.16
83
+ description:
84
+ email:
85
+ - robert.labrie@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - Gemfile
91
+ - LICENSE
92
+ - README.md
93
+ - lib/logstash/inputs/multirds.rb
94
+ - lib/logstash/inputs/multirds/patch.rb
95
+ - logstash-input-multirds.gemspec
96
+ homepage: https://github.com/robertlabrie/logstash-input-multi-rds
97
+ licenses: []
98
+ metadata:
99
+ logstash_plugin: 'true'
100
+ logstash_group: input
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.5.1
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Ingest RDS log files to Logstash with competing consumers and multiple databases
121
+ test_files: []