logstash-input-multi-rds 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2366e33966ca9870dccb4c8cfe8cd9b602768826
4
+ data.tar.gz: 56fa909e95dea9d5e4b7bd897bec4f9fab278162
5
+ SHA512:
6
+ metadata.gz: edb4d85011faae0b2ae3245a45b917ee03e1791f7f592477ada815b0368c91fab19a41ca949d3e11a6fea3eec422513a2cbc49f2b17349ee85b4223dcb5fcb51
7
+ data.tar.gz: 98ad2db65c5db075ea7534af7f27841b91d58ec03cb1f4e60c24786c7afb8218c442e777de7157eaa80cf1c3e48a7fe46340446e239c7e38193f98224e3a389d
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.
@@ -0,0 +1,10 @@
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 => "development"
8
+ log_file_name => "error/postgresql.log"
9
+ }
10
+ }
@@ -0,0 +1,97 @@
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, :validate => :string, :required => true
20
+ config :log_file_name, :validate => :string, :required => true
21
+ config :polling_frequency, :validate => :number, :default => 600
22
+ config :sincedb_path, :validate => :string, :default => nil
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
+
28
+ # path = @sincedb_path || File.join(ENV["HOME"], ".sincedb_" + Digest::MD5.hexdigest("#{@instance_name}+#{@log_file_name}"))
29
+ # @sincedb = SinceDB::File.new path
30
+ end
31
+
32
+ def run(queue)
33
+ @thread = Thread.current
34
+ Stud.interval(@polling_frequency) do
35
+ @logger.debug "finding #{@log_file_name} for #{@instance_name} starting #{@sincedb.read} (#{@sincedb.read.to_i * 1000})"
36
+ begin
37
+ logfiles = @database.log_files({
38
+ filename_contains: @log_file_name,
39
+ file_last_written: @sincedb.read.to_i * 1000,
40
+ })
41
+ logfiles.each do |logfile|
42
+ @logger.debug "downloading #{logfile.name} for #{@instance_name}"
43
+ more = true
44
+ marker = "0"
45
+ while more do
46
+ response = logfile.download({marker: marker})
47
+ response[:log_file_data].lines.each do |line|
48
+ @codec.decode(line) do |event|
49
+ decorate event
50
+ event.set "rds_instance", @instance_name
51
+ event.set "log_file", @log_file_name
52
+ queue << event
53
+ end
54
+ end
55
+ more = response[:additional_data_pending]
56
+ marker = response[:marker]
57
+ end
58
+ @sincedb.write (filename2datetime logfile.name)
59
+ end
60
+ rescue Aws::RDS::Errors::ServiceError
61
+ # the next iteration will resume at the same location
62
+ @logger.warn "caught AWS service error"
63
+ end
64
+ end
65
+ end
66
+
67
+ def stop
68
+ Stud.stop! @thread
69
+ end
70
+
71
+ def filename2datetime(name)
72
+ parts = name.match /(\d{4})-(\d{2})-(\d{2})-(\d{2})$/
73
+ Time.utc parts[1], parts[2], parts[3], parts[4]
74
+ end
75
+
76
+ private
77
+ module SinceDB
78
+ class File
79
+ def initialize(file)
80
+ @db = file
81
+ end
82
+
83
+ def read
84
+ if ::File.exists?(@db)
85
+ content = ::File.read(@db).chomp.strip
86
+ return content.empty? ? Time.new : Time.parse(content)
87
+ else
88
+ return Time.new("1999-01-01")
89
+ end
90
+ end
91
+
92
+ def write(time)
93
+ ::File.open(@db, 'w') { |file| file.write time.to_s }
94
+ end
95
+ end
96
+ end
97
+ end
@@ -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,23 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-input-multi-rds'
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-multi-rds
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-multi-rds.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: []