logstash-input-cloudwatch_logs 0.9.2

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: 09965d9df696c2fbbdde3e398313c24b03c63b66
4
+ data.tar.gz: 26c86a3ff42e46433b0e1b44f347b2beea61a238
5
+ SHA512:
6
+ metadata.gz: e01a4858692aaa157e92a58bbfb1e6a0612bdeccf2696f2462f08e6f47a0463cc4d9f7c2742d6959d3ccc24d1846c6d6604536a2dc3aa3b4fc6bb0cdd8ce9b87
7
+ data.tar.gz: 326d311a2d86292300dd39cae935c370672b630b59cad25702b21c62c9b1dc975e23706dd6e95874c22a11080d4caea9b54ae73058142c898e4d1e517c3d2d99
data/CHANGELOG.md ADDED
File without changes
data/CONTRIBUTORS ADDED
@@ -0,0 +1,20 @@
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
+ * Aaron Mildenstein (untergeek)
6
+ * Adam Tucker (adamjt)
7
+ * John Pariseau (ururk)
8
+ * Jordan Sissel (jordansissel)
9
+ * Mathieu Guillaume (mguillaume)
10
+ * Pier-Hugues Pellerin (ph)
11
+ * Richard Pijnenburg (electrical)
12
+ * Suyog Rao (suyograo)
13
+ * Ted Timmons (tedder)
14
+ * Ryan O'Keeffe (danielredoak)
15
+ * Luke Waite (lukewaite)
16
+
17
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
18
+ Logstash, and you aren't on the list above and want to be, please let us know
19
+ and we'll make sure you're here. Contributions from folks like you are what make
20
+ open source awesome.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012–2015 Elasticsearch <http://www.elastic.co>
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/NOTICE.TXT ADDED
@@ -0,0 +1,5 @@
1
+ Elasticsearch
2
+ Copyright 2012-2015 Elasticsearch
3
+
4
+ This product includes software developed by The Apache Software
5
+ Foundation (http://www.apache.org/).
data/README.md ADDED
@@ -0,0 +1,86 @@
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 https://discuss.elastic.co/c/logstash discussion forum.
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. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
26
+
27
+ - Install dependencies
28
+ ```sh
29
+ bundle install
30
+ ```
31
+
32
+ #### Test
33
+
34
+ - Update your dependencies
35
+
36
+ ```sh
37
+ bundle install
38
+ ```
39
+
40
+ - Run tests
41
+
42
+ ```sh
43
+ bundle exec rspec
44
+ ```
45
+
46
+ ### 2. Running your unpublished Plugin in Logstash
47
+
48
+ #### 2.1 Run in a local Logstash clone
49
+
50
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
51
+ ```ruby
52
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
53
+ ```
54
+ - Install plugin
55
+ ```sh
56
+ bin/plugin install --no-verify
57
+ ```
58
+ - Run Logstash with your plugin
59
+ ```sh
60
+ bin/logstash -e 'filter {awesome {}}'
61
+ ```
62
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
63
+
64
+ #### 2.2 Run in an installed Logstash
65
+
66
+ 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:
67
+
68
+ - Build your plugin gem
69
+ ```sh
70
+ gem build logstash-filter-awesome.gemspec
71
+ ```
72
+ - Install the plugin from the Logstash home
73
+ ```sh
74
+ bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
75
+ ```
76
+ - Start Logstash and proceed to test the plugin
77
+
78
+ ## Contributing
79
+
80
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
81
+
82
+ 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.
83
+
84
+ It is more important to the community that you are able to contribute.
85
+
86
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,206 @@
1
+ # encoding: utf-8
2
+ require "logstash/inputs/base"
3
+ require "logstash/namespace"
4
+ require "logstash/plugin_mixins/aws_config"
5
+ require "logstash/timestamp"
6
+ require "time"
7
+ require "tmpdir"
8
+ require "stud/interval"
9
+ require "stud/temporary"
10
+
11
+ # Stream events from ClougWatch Logs streams.
12
+ #
13
+ # Primarily designed to pull logs from Lambda's which are logging to
14
+ # CloudWatch Logs. Specify a log group, and this plugin will scan
15
+ # all log streams in that group, and pull in any new log events.
16
+ #
17
+ class LogStash::Inputs::CloudWatch_Logs < LogStash::Inputs::Base
18
+ include LogStash::PluginMixins::AwsConfig::V2
19
+
20
+ config_name "cloudwatch_logs"
21
+
22
+ default :codec, "plain"
23
+
24
+ # Log group to pull logs from for this plugin. Will pull in all
25
+ # streams inside of this log group.
26
+ config :log_group, :validate => :string, :required => true
27
+
28
+ # Where to write the since database (keeps track of the date
29
+ # the last handled file was added to S3). The default will write
30
+ # sincedb files to some path matching "$HOME/.sincedb*"
31
+ # Should be a path with filename not just a directory.
32
+ config :sincedb_path, :validate => :string, :default => nil
33
+
34
+ # Interval to wait between to check the file list again after a run is finished.
35
+ # Value is in seconds.
36
+ config :interval, :validate => :number, :default => 60
37
+
38
+ # def register
39
+ public
40
+ def register
41
+ require "digest/md5"
42
+ require "aws-sdk"
43
+
44
+ @logger.info("Registering cloudwatch_logs input", :log_group => @log_group)
45
+
46
+ Aws::ConfigService::Client.new(aws_options_hash)
47
+
48
+ @cloudwatch = Aws::CloudWatchLogs::Client.new(aws_options_hash)
49
+ end #def register
50
+
51
+ # def run
52
+ public
53
+ def run(queue)
54
+ while !stop?
55
+ process_group(queue)
56
+ Stud.stoppable_sleep(@interval)
57
+ end
58
+ end # def run
59
+
60
+ # def list_new_streams
61
+ public
62
+ def list_new_streams(token = nil, objects = [])
63
+ params = {
64
+ :log_group_name => @log_group,
65
+ :order_by => "LastEventTime",
66
+ :descending => false
67
+ }
68
+
69
+ if token != nil
70
+ params[:next_token] = token
71
+ end
72
+
73
+ streams = @cloudwatch.describe_log_streams(params)
74
+
75
+ objects.push(*streams.log_streams)
76
+ if streams.next_token == nil
77
+ @logger.debug("CloudWatch Logs hit end of tokens for streams")
78
+ objects
79
+ else
80
+ @logger.debug("CloudWatch Logs calling list_new_streams again on token", :token => streams.next_token)
81
+ list_new_streams(streams.next_token, objects)
82
+ end
83
+
84
+ end # def list_new_streams
85
+
86
+ # def process_log
87
+ private
88
+ def process_log(queue, log, stream)
89
+
90
+ @codec.decode(log.message.to_str) do |event|
91
+ event[LogStash::Event::TIMESTAMP] = parse_time(log.timestamp)
92
+ event["[cloudwatch][ingestion_time]"] = parse_time(log.ingestion_time)
93
+ event["[cloudwatch][log_group]"] = @log_group
94
+ event["[cloudwatch][log_stream]"] = stream.log_stream_name
95
+ decorate(event)
96
+
97
+ queue << event
98
+ end
99
+ end
100
+ # def process_log
101
+
102
+ # def parse_time
103
+ private
104
+ def parse_time(data)
105
+ LogStash::Timestamp.at(data.to_i / 1000, (data.to_i % 1000) * 1000)
106
+ end # def parse_time
107
+
108
+ # def process_group
109
+ public
110
+ def process_group(queue)
111
+ objects = list_new_streams
112
+
113
+ last_read = sincedb.read
114
+ current_window = DateTime.now.strftime('%Q')
115
+
116
+ if last_read < 0
117
+ last_read = 1
118
+ end
119
+
120
+ objects.each do |stream|
121
+ if stream.last_ingestion_time && stream.last_ingestion_time > last_read
122
+ process_log_stream(queue, stream, last_read, current_window)
123
+ end
124
+ end
125
+
126
+ sincedb.write(current_window)
127
+ end # def process_group
128
+
129
+ # def process_log_stream
130
+ private
131
+ def process_log_stream(queue, stream, last_read, current_window, token = nil)
132
+ @logger.debug("CloudWatch Logs processing stream",
133
+ :log_stream => stream.log_stream_name,
134
+ :log_group => @log_group,
135
+ :lastRead => last_read,
136
+ :currentWindow => current_window,
137
+ :token => token
138
+ )
139
+
140
+ params = {
141
+ :log_group_name => @log_group,
142
+ :log_stream_name => stream.log_stream_name,
143
+ :start_from_head => true
144
+ }
145
+
146
+ if token != nil
147
+ params[:next_token] = token
148
+ end
149
+
150
+ logs = @cloudwatch.get_log_events(params)
151
+
152
+ logs.events.each do |log|
153
+ if log.ingestion_time > last_read
154
+ process_log(queue, log, stream)
155
+ end
156
+ end
157
+
158
+ # if there are more pages, continue
159
+ if logs.events.count != 0 && logs.next_forward_token != nil
160
+ process_log_stream(queue, stream, last_read, current_window, logs.next_forward_token)
161
+ end
162
+ end # def process_log_stream
163
+
164
+ private
165
+ def sincedb
166
+ @sincedb ||= if @sincedb_path.nil?
167
+ @logger.info("Using default generated file for the sincedb", :filename => sincedb_file)
168
+ SinceDB::File.new(sincedb_file)
169
+ else
170
+ @logger.info("Using the provided sincedb_path",
171
+ :sincedb_path => @sincedb_path)
172
+ SinceDB::File.new(@sincedb_path)
173
+ end
174
+ end
175
+
176
+ private
177
+ def sincedb_file
178
+ File.join(ENV["HOME"], ".sincedb_" + Digest::MD5.hexdigest("#{@log_group}"))
179
+ end
180
+
181
+ module SinceDB
182
+ class File
183
+ def initialize(file)
184
+ @sincedb_path = file
185
+ end
186
+
187
+ def newer?(date)
188
+ date > read
189
+ end
190
+
191
+ def read
192
+ if ::File.exists?(@sincedb_path)
193
+ since = ::File.read(@sincedb_path).chomp.strip.to_i
194
+ else
195
+ since = 1
196
+ end
197
+ return since
198
+ end
199
+
200
+ def write(since = nil)
201
+ since = DateTime.now.strftime('%Q') if since.nil?
202
+ ::File.open(@sincedb_path, 'w') { |file| file.write(since.to_s) }
203
+ end
204
+ end
205
+ end
206
+ end # class LogStash::Inputs::CloudWatch_Logs
@@ -0,0 +1,33 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'logstash-input-cloudwatch_logs'
4
+ s.version = '0.9.2'
5
+ s.licenses = ['Apache License (2.0)']
6
+ s.summary = 'Stream events from CloudWatch Logs.'
7
+ 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'
8
+ s.authors = ['Luke Waite']
9
+ s.email = 'lwaite@gmail.com'
10
+ s.homepage = ''
11
+ s.require_paths = ['lib']
12
+
13
+ # Files
14
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
15
+
16
+ # Tests
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+
19
+ # Special flag to let us know this is actually a logstash plugin
20
+ s.metadata = { 'logstash_plugin' => 'true', 'logstash_group' => 'input' }
21
+
22
+ # Gem dependencies
23
+ s.add_runtime_dependency 'logstash-core', '>= 1.4.0', '< 3.0.0'
24
+ s.add_runtime_dependency 'logstash-mixin-aws'
25
+ s.add_runtime_dependency 'stud', '~> 0.0.22'
26
+ s.add_runtime_dependency 'aws-sdk', '~> 2.0'
27
+
28
+ s.add_development_dependency 'logstash-devutils', '>= 0.0.16'
29
+ s.add_development_dependency 'simplecov'
30
+ s.add_development_dependency 'coveralls'
31
+ s.add_development_dependency 'logstash-codec-json'
32
+ end
33
+
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-input-cloudwatch_logs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.2
5
+ platform: ruby
6
+ authors:
7
+ - Luke Waite
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-core
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.0
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.0
23
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: 1.4.0
28
+ - - <
29
+ - !ruby/object:Gem::Version
30
+ version: 3.0.0
31
+ prerelease: false
32
+ type: :runtime
33
+ - !ruby/object:Gem::Dependency
34
+ name: logstash-mixin-aws
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ prerelease: false
46
+ type: :runtime
47
+ - !ruby/object:Gem::Dependency
48
+ name: stud
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.0.22
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ version: 0.0.22
59
+ prerelease: false
60
+ type: :runtime
61
+ - !ruby/object:Gem::Dependency
62
+ name: aws-sdk
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: '2.0'
68
+ requirement: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ~>
71
+ - !ruby/object:Gem::Version
72
+ version: '2.0'
73
+ prerelease: false
74
+ type: :runtime
75
+ - !ruby/object:Gem::Dependency
76
+ name: logstash-devutils
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: 0.0.16
82
+ requirement: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: 0.0.16
87
+ prerelease: false
88
+ type: :development
89
+ - !ruby/object:Gem::Dependency
90
+ name: simplecov
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirement: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ prerelease: false
102
+ type: :development
103
+ - !ruby/object:Gem::Dependency
104
+ name: coveralls
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirement: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ prerelease: false
116
+ type: :development
117
+ - !ruby/object:Gem::Dependency
118
+ name: logstash-codec-json
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirement: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ prerelease: false
130
+ type: :development
131
+ 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
132
+ email: lwaite@gmail.com
133
+ executables: []
134
+ extensions: []
135
+ extra_rdoc_files: []
136
+ files:
137
+ - lib/logstash/inputs/cloudwatch_logs.rb
138
+ - spec/inputs/cloudwatch_logs_spec.rb
139
+ - logstash-input-cloudwatch_logs.gemspec
140
+ - CHANGELOG.md
141
+ - README.md
142
+ - CONTRIBUTORS
143
+ - Gemfile
144
+ - LICENSE
145
+ - NOTICE.TXT
146
+ homepage: ''
147
+ licenses:
148
+ - Apache License (2.0)
149
+ metadata:
150
+ logstash_plugin: 'true'
151
+ logstash_group: input
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 2.1.9
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: Stream events from CloudWatch Logs.
172
+ test_files:
173
+ - spec/inputs/cloudwatch_logs_spec.rb