logstash-codec-cloudwatch_logs 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: c93c61a0f6290abeaa6435db7b5abd7eaea0e431
4
+ data.tar.gz: 2f24162de1251bad7eeeb8dfcaf0bc40de815dab
5
+ SHA512:
6
+ metadata.gz: a942cf6850c35d2675bbad4304168157134a5c0883cc2b1350f4e2516ee199575a8f3be1da913f17804a45c1242f2510d27a0a7f30b6e9120d69af739e1dc8fc
7
+ data.tar.gz: 75b69c66dde11669ee7b97d05e1473f3e2873a5fcd17708392b76575e18f74f636bac0741726fe310132444d9f1b632e26cd1f2626616937733c15a8dd8c43b6
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (c) 2015 Anthony M.
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.
14
+
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # Logstash Cloudwatch Logs Codec
2
+
3
+ [![Travis Build Status](https://travis-ci.org/threadwaste/logstash-codec-cloudwatch_logs.svg)](https://travis-ci.org/threadwaste/logstash-codec-cloudwatch_logs)
4
+
5
+ Parse [CloudWatch Logs subscriptions](http://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/Subscriptions.html#DestinationKinesisExample) sent to Kinesis.
6
+
7
+ ## Usage
8
+
9
+ ```
10
+ input {
11
+ kinesis {
12
+ kinesis_stream_name => "stream"
13
+ codec => cloudwatch_logs
14
+ }
15
+ }
16
+ ```
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+ require "logstash/codecs/base"
3
+ require 'logstash/json'
4
+ require 'zlib'
5
+
6
+
7
+ # Parse CloudWatch Logs
8
+ class LogStash::Codecs::CloudWatchLogs < LogStash::Codecs::Base
9
+ config_name "cloudwatch_logs"
10
+
11
+ public
12
+ def register; end
13
+
14
+ def decode(data, &block)
15
+ data = decompress(StringIO.new(data))
16
+ parse(LogStash::Json.load(data), &block)
17
+ end
18
+
19
+ private
20
+ def decompress(data)
21
+ gz = Zlib::GzipReader.new(data)
22
+ gz.read
23
+ rescue Zlib::Error, Zlib::GzipFile::Error => e
24
+ @logger.error("Error decompressing CloudWatch Logs data: #{e}")
25
+ end
26
+
27
+ def parse(json, &block)
28
+ base = json.reject { |k,_| k == "logEvents" }.freeze
29
+ events = json["logEvents"]
30
+
31
+ events.each do |event|
32
+ yield LogStash::Event.new(base.merge(event))
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-codec-cloudwatch_logs'
3
+ s.version = '0.0.1'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = "Parse CloudWatch Logs subscription data"
6
+ s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
7
+ s.authors = ["Anthony M."]
8
+ s.email = 'tony@threadwaste.com'
9
+ s.homepage = "https://github.com/threadwaste/logstash-codec-cloudwatchlogs"
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" => "codec" }
20
+
21
+ # Gem dependencies
22
+ s.add_runtime_dependency "logstash-core", ">= 2.0.0", "< 3.0.0"
23
+
24
+ s.add_development_dependency 'logstash-devutils', '>= 0.0.16'
25
+ end
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/codecs/cloudwatch_logs"
4
+
5
+ describe LogStash::Codecs::CloudWatchLogs do
6
+ let!(:raw_data) do
7
+ data = StringIO.new
8
+ data << '{'
9
+ data << '"owner":"123456789012",'
10
+ data << '"logGroup":"CloudTrail",'
11
+ data << '"logStream":"123456789012_CloudTrail_us-east-1",'
12
+ data << '"subscriptionFilters":["RootAccess"],"messageType":"DATA_MESSAGE","logEvents":[{"id":"31953106606966983378809025079804211143289615424298221568","timestamp":1432826855000,"message":"first"},{"id":"31953106606966983378809025079804211143289615424298221569","timestamp":1432826855000,"message":"second"},{"id":"31953106606966983378809025079804211143289615424298221570","timestamp":1432826855000,"message":"third"}]}'
13
+
14
+ data.rewind
15
+ data
16
+ end
17
+
18
+ describe '#decode' do
19
+ it 'decompresses and parses CloudWatch Logs data' do
20
+ events = []
21
+
22
+ zipped = StringIO.new('', 'r+b')
23
+ zipper = Zlib::GzipWriter.new(zipped)
24
+ zipper.write(raw_data.read)
25
+ zipper.finish
26
+
27
+ zipped.rewind
28
+
29
+ subject.decode(zipped.string) do |event|
30
+ events << event
31
+ end
32
+
33
+ expect(events.size).to eq 3
34
+
35
+ events.each do |event|
36
+ expect(event['owner']).to eq '123456789012'
37
+ expect(event['logGroup']).to eq 'CloudTrail'
38
+ expect(event['logStream']).to eq '123456789012_CloudTrail_us-east-1'
39
+ expect(event['subscriptionFilters']).to eq ['RootAccess']
40
+ expect(event['messageType']).to eq 'DATA_MESSAGE'
41
+ end
42
+
43
+ messages = events.map { |e| e["message"] }
44
+ expect(messages).to eq ["first", "second", "third"]
45
+ end
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-codec-cloudwatch_logs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Anthony M.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-01 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
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: 3.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
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: 0.0.16
39
+ name: logstash-devutils
40
+ prerelease: false
41
+ type: :development
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.0.16
47
+ description: This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program
48
+ email: tony@threadwaste.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - Gemfile
54
+ - LICENSE
55
+ - README.md
56
+ - lib/logstash/codecs/cloudwatch_logs.rb
57
+ - logstash-codec-cloudwatch_logs.gemspec
58
+ - spec/codecs/cloudwatch_logs_spec.rb
59
+ homepage: https://github.com/threadwaste/logstash-codec-cloudwatchlogs
60
+ licenses:
61
+ - Apache License (2.0)
62
+ metadata:
63
+ logstash_plugin: 'true'
64
+ logstash_group: codec
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.4.8
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Parse CloudWatch Logs subscription data
85
+ test_files:
86
+ - spec/codecs/cloudwatch_logs_spec.rb