logstash-filter-dynamodb 0.0.2

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: b8dffe1ac71ebf37b039e705d45b7af56d547466
4
+ data.tar.gz: 7435ef7c7fe25b654d4673fa15d751a09e5b64d1
5
+ SHA512:
6
+ metadata.gz: bfba589d7d1423b262982f349661cc24661fb741a62324b6b5bd8d22fe5cde748238deef572f517a80015338760514d031bfca8f59dd8938b6e2570b1a717322
7
+ data.tar.gz: 91b8856e1ca93a1105ac4af0dafc173b3820bb00a599b34cbc8e271c59b9818853a3c0b8844505b534fb6e4b31021688a90d22796a18be36b8c3bc3392fbfb91
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ Gemfile.lock
3
+ Gemfile.bak
4
+ .bundle
5
+ vendor
File without changes
@@ -0,0 +1,11 @@
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
+ * Jonathan Leibiusky (xetorthio)
6
+ * Marcos Lilljedahl (marcosnils)
7
+
8
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
9
+ Logstash, and you aren't on the list above and want to be, please let us know
10
+ and we'll make sure you're here. Contributions from folks like you are what make
11
+ open source awesome.
@@ -0,0 +1,2 @@
1
+ # logstash-filter-example
2
+ Example filter plugin. This should help bootstrap your effort to write your own filter plugin!
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 Mantika <http://www.mantika.ca>
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.
@@ -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/).
@@ -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 @@
1
+ require "logstash/devutils/rake"
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require "logstash/namespace"
4
+ require 'bigdecimal'
5
+ require 'stringio'
6
+ require 'set'
7
+ require 'json'
8
+
9
+ require 'bigdecimal'
10
+ require 'stringio'
11
+ require 'set'
12
+ require 'json'
13
+
14
+
15
+ class LogStash::Filters::DynamoDB < LogStash::Filters::Base
16
+
17
+
18
+
19
+ class Unmarshaler
20
+ def format(obj)
21
+ type, value = extract_type_and_value(obj)
22
+ case type.downcase
23
+ when :m
24
+ value.each.with_object({}) do |(k, v), map|
25
+ map[k.to_s] = format(v)
26
+ end
27
+ when :l then value.map { |v| format(v) }
28
+ when :s then value
29
+ when :n then BigDecimal.new(value)
30
+ when :b then StringIO.new(value)
31
+ when :null then nil
32
+ when :bool then value
33
+ when :ss then Array.new(value)
34
+ when :ns then Array.new(value.map { |n| BigDecimal.new(n) })
35
+ when :bs then Array.new(value.map { |b| StringIO.new(b) })
36
+ else
37
+ raise ArgumentError, "unhandled type #{type.inspect}"
38
+ end
39
+ end
40
+
41
+ def extract_type_and_value(obj)
42
+ case obj
43
+ when Hash then obj.to_a.first
44
+ when Struct
45
+ obj.members.each do |key|
46
+ value = obj[key]
47
+ return [key, value] unless value.nil?
48
+ end
49
+ else
50
+ raise ArgumentError, "unhandled type #{obj.inspect}"
51
+ end
52
+ end
53
+ end
54
+
55
+
56
+
57
+
58
+ config_name "dynamodb"
59
+
60
+ #config :message, :validate => :string, :default => "Hello World!"
61
+
62
+ public
63
+ def register
64
+ @unmarshaller = Unmarshaler.new
65
+ end
66
+
67
+ public
68
+ def filter(event)
69
+ doc = JSON.parse(event['message'], :symbolize_names => true)
70
+
71
+ doc[:dynamodb][:newImage].each do |key, value|
72
+ event[key.to_s] = @unmarshaller.format(value)
73
+ end
74
+
75
+ filter_matched(event)
76
+ end
77
+ end
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-dynamodb'
3
+ s.version = '0.0.2'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = "This plugin unmarshals a DynamoDB stream message and populates the corresponding ElasticSearch fields so the get indexed properly "
6
+ 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"
7
+ s.authors = ["Mantika"]
8
+ s.email = 'info@mantika.ca'
9
+ s.homepage = "https://www.mantika.ca"
10
+ s.require_paths = ["lib"]
11
+
12
+ # Files
13
+ s.files = `git ls-files`.split($\)
14
+ # Tests
15
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
+
17
+ # Special flag to let us know this is actually a logstash plugin
18
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
19
+
20
+ # Gem dependencies
21
+ s.add_runtime_dependency "logstash-core", '>= 1.4.0', '< 2.0.0'
22
+ s.add_development_dependency 'logstash-devutils'
23
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require "logstash/filters/dynamodb"
3
+
4
+ describe LogStash::Filters::DynamoDB do
5
+ describe "Check convertions" do
6
+ let(:config) do <<-CONFIG
7
+ filter {
8
+ dynamodb { }
9
+ }
10
+ CONFIG
11
+ end
12
+
13
+ sample('message' => '{"eventID":"0","eventName":"INSERT","eventVersion":"1.0","eventSource":"aws:dynamodb","awsRegion":{},"dynamodb":{"keys":{"id":{"S":"809c2aad-bdb1-43a4-8f67-d56589e4058d"}},"newImage":{"criterias":{"SS":["a","b"]},"id":{"S":"809c2aad-bdb1-43a4-8f67-d56589e4058d"},"labels":{"M":{"foo":{"S":"bar"}}}}}}') do
14
+ expect(subject).to include("id")
15
+ expect(subject['id']).to eq('809c2aad-bdb1-43a4-8f67-d56589e4058d')
16
+
17
+ expect(subject).to include("criterias")
18
+ expect(subject['criterias']).to eq(['a', 'b'])
19
+
20
+ expect(subject).to include("labels")
21
+ expect(subject['labels']).to eq({'foo' => 'bar'})
22
+ end
23
+ end
24
+ end
@@ -0,0 +1 @@
1
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-dynamodb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Mantika
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-core
15
+ requirement: !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: 2.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 1.4.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: logstash-devutils
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: This gem is a logstash plugin required to be installed on top of the
48
+ Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not
49
+ a stand-alone program
50
+ email: info@mantika.ca
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - ".gitignore"
56
+ - CHANGELOG.md
57
+ - CONTRIBUTORS
58
+ - DEVELOPER.md
59
+ - Gemfile
60
+ - LICENSE
61
+ - NOTICE.TXT
62
+ - README.md
63
+ - Rakefile
64
+ - lib/logstash/filters/dynamodb.rb
65
+ - logstash-filter-dynamodb.gemspec
66
+ - spec/filters/dynamodb_spec.rb
67
+ - spec/spec_helper.rb
68
+ homepage: https://www.mantika.ca
69
+ licenses:
70
+ - Apache License (2.0)
71
+ metadata:
72
+ logstash_plugin: 'true'
73
+ logstash_group: filter
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.4.8
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: This plugin unmarshals a DynamoDB stream message and populates the corresponding
94
+ ElasticSearch fields so the get indexed properly
95
+ test_files:
96
+ - spec/filters/dynamodb_spec.rb
97
+ - spec/spec_helper.rb