logstash-codec-form 1.0.0

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: 00bad5d41ade7457f0b0dc3b085e93ed430b52d1
4
+ data.tar.gz: 4751fda129d80c4afe4ea463f325f838da97e00e
5
+ SHA512:
6
+ metadata.gz: c1d737ee02bf967d2123457450479f097e88c633b8c2ec4added347d4c452296c5f95966d3d7de8cc191ed69b6b4afe4f6c0f055eef60327b896dc8598c2f104
7
+ data.tar.gz: 9bca7fbf432c81c7526e663d7eac93e4beb6dfc520c39a9866f84a3e9c12b11f7dd4593ba590ea81ba8aa26504b4c2940aeebbe03f19cf75bff3527ab55e4906
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2016 Brendan ODonnell <brendan [at] b0d0nne11 [dot] com>
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
+ Brendan ODonnell
2
+ Copyright 2016 Brendan ODonnell
3
+
4
+ This product includes software developed by The Apache Software
5
+ Foundation (http://www.apache.org/).
data/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # Logstash Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elastic/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.elastic.co/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/elastic/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.
26
+
27
+ - Install dependencies
28
+ ```sh
29
+ bundle install
30
+ ```
31
+
32
+ #### Test
33
+
34
+ ```sh
35
+ bundle exec rspec
36
+ ```
37
+
38
+ The Logstash code required to run the tests/specs is specified in the `Gemfile` by the line similar to:
39
+ ```ruby
40
+ gem "logstash", :github => "elasticsearch/logstash", :branch => "1.5"
41
+ ```
42
+ To test against another version or a local Logstash, edit the `Gemfile` to specify an alternative location, for example:
43
+ ```ruby
44
+ gem "logstash", :github => "elasticsearch/logstash", :ref => "master"
45
+ ```
46
+ ```ruby
47
+ gem "logstash", :path => "/your/local/logstash"
48
+ ```
49
+
50
+ Then update your dependencies and run your tests:
51
+
52
+ ```sh
53
+ bundle install
54
+ bundle exec rspec
55
+ ```
56
+
57
+ ### 2. Running your unpublished Plugin in Logstash
58
+
59
+ #### 2.1 Run in a local Logstash clone
60
+
61
+ - Edit Logstash `tools/Gemfile` and add the local plugin path, for example:
62
+ ```ruby
63
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
64
+ ```
65
+ - Update Logstash dependencies
66
+ ```sh
67
+ rake vendor:gems
68
+ ```
69
+ - Run Logstash with your plugin
70
+ ```sh
71
+ bin/logstash -e 'filter {awesome {}}'
72
+ ```
73
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
74
+
75
+ #### 2.2 Run in an installed Logstash
76
+
77
+ - Build your plugin gem
78
+ ```sh
79
+ gem build logstash-filter-awesome.gemspec
80
+ ```
81
+ - Install the plugin from the Logstash home
82
+ ```sh
83
+ bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
84
+ ```
85
+ - Start Logstash and proceed to test the plugin
86
+
87
+ ## Contributing
88
+
89
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
90
+
91
+ 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.
92
+
93
+ It is more important to me that you are able to contribute.
94
+
95
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,69 @@
1
+ # encoding: utf-8
2
+ require 'logstash/codecs/base'
3
+ require 'logstash/codecs/line'
4
+ require 'uri'
5
+
6
+ class LogStash::Codecs::Form < LogStash::Codecs::Base
7
+
8
+ # This codec will encode or decode an event using the
9
+ # application/x-www-form-urlencoded format. It was originally intended to be
10
+ # used with the http input plugin to read values submitted via HTTP form
11
+ # submissions.
12
+ #
13
+ # https://www.w3.org/TR/2013/CR-html5-20130806/forms.html#url-encoded-form-data
14
+ #
15
+ # Usage:
16
+ # [source,ruby]
17
+ # input{
18
+ # http {
19
+ # additional_codecs => {"application/x-www-form-urlencoded"=>"form"}
20
+ # }
21
+ # }
22
+ # or
23
+ # [source,ruby]
24
+ # output {
25
+ # http {
26
+ # codec => "form"
27
+ # content_type => "application/x-www-form-urlencoded"
28
+ # }
29
+ # }
30
+ config_name 'form'
31
+
32
+ private
33
+ def parse(line)
34
+ event = {}
35
+ keypairs = URI.decode_www_form(line['message'])
36
+ keypairs.each do |keypair|
37
+ if event.has_key? keypair[0]
38
+ event[keypair[0]] << keypair[1]
39
+ else
40
+ event[keypair[0]] = [keypair[1]]
41
+ end
42
+ end
43
+ return event
44
+ end
45
+
46
+ private
47
+ def dump(event)
48
+ URI.encode_www_form(event.to_hash) + NL
49
+ end
50
+
51
+ public
52
+ def register
53
+ @lines = LogStash::Codecs::Line.new
54
+ @lines.charset = 'UTF-8'
55
+ end
56
+
57
+ public
58
+ def decode(payload)
59
+ @lines.decode(payload) do |line|
60
+ yield LogStash::Event.new(parse(line))
61
+ end
62
+ end
63
+
64
+ public
65
+ def encode(event)
66
+ @on_event.call(event, dump(event))
67
+ end
68
+
69
+ end
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-codec-form'
3
+ s.version = '1.0.0'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = "Read or write events in a application/x-www-form-urlencoded format."
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 = ["Brendan ODonnell"]
8
+ s.email = 'brendan@b0d0nne11.com'
9
+ s.homepage = "https://github.com/b0d0nne11/logstash-codec-form"
10
+ s.require_paths = ["lib"]
11
+
12
+ # Files
13
+ s.files = Dir['lib/**/*','spec/**/*','*.gemspec','*.md','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.beta2", "< 3.0.0"
23
+ s.add_runtime_dependency "logstash-codec-line", "~> 2.0", ">= 2.0.2"
24
+
25
+ s.add_development_dependency 'logstash-devutils'
26
+ end
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+
3
+ require 'logstash/devutils/rspec/spec_helper'
4
+ require 'logstash/codecs/form'
5
+ require 'logstash/event'
6
+ require 'uri'
7
+
8
+ describe LogStash::Codecs::Form do
9
+
10
+ subject do
11
+ next LogStash::Codecs::Form.new
12
+ end
13
+
14
+ context '#encode' do
15
+ let (:event) {LogStash::Event.new({'message' => 'hello world', 'host' => 'test'})}
16
+
17
+ it 'should return an application/x-www-form-urlencoded formatted line' do
18
+ expect(subject).to receive(:on_event).once.and_call_original
19
+ subject.on_event do |e, d|
20
+ insist {d} == "message=hello+world&host=test&%40version=1&%40timestamp=#{URI.encode_www_form_component(event.timestamp)}\n"
21
+ end
22
+ subject.encode(event)
23
+ end
24
+ end
25
+
26
+ context '#decode' do
27
+ it 'should return an event from an application/x-www-form-urlencoded string' do
28
+ decoded = false
29
+ subject.decode("message=hello+world&host=test\n") do |e|
30
+ decoded = true
31
+ insist { e.is_a?(LogStash::Event) }
32
+ insist { e['message'] } == ['hello world']
33
+ end
34
+ insist { decoded } == true
35
+ end
36
+ end
37
+
38
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-codec-form
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brendan ODonnell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-21 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.beta2
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.beta2
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: '2.0'
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: 2.0.2
42
+ name: logstash-codec-line
43
+ prerelease: false
44
+ type: :runtime
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: '2.0'
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: 2.0.2
53
+ - !ruby/object:Gem::Dependency
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ name: logstash-devutils
60
+ prerelease: false
61
+ type: :development
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ 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.
68
+ email: brendan@b0d0nne11.com
69
+ executables: []
70
+ extensions: []
71
+ extra_rdoc_files: []
72
+ files:
73
+ - Gemfile
74
+ - LICENSE
75
+ - NOTICE.TXT
76
+ - README.md
77
+ - lib/logstash/codecs/form.rb
78
+ - logstash-codec-form.gemspec
79
+ - spec/codecs/form_spec.rb
80
+ homepage: https://github.com/b0d0nne11/logstash-codec-form
81
+ licenses:
82
+ - Apache License (2.0)
83
+ metadata:
84
+ logstash_plugin: 'true'
85
+ logstash_group: codec
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.4.6
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Read or write events in a application/x-www-form-urlencoded format.
106
+ test_files:
107
+ - spec/codecs/form_spec.rb