logstash-codec-csv2 0.1.0

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: 62f67592dae768baa1f4bb5524f029c86fc7b02a
4
+ data.tar.gz: 5267b6b1a29d09e07b39ed18b71dfc3f73c311b0
5
+ SHA512:
6
+ metadata.gz: 562f561534bb92a34d53aea7c1e5770e00b9840dd0859e9211b03d461ae8675177532ee0b54e579ea927374b5cea255a94dbe2d9c4bd2bff8b5a3be0fd1f8576
7
+ data.tar.gz: 7376a60e92ef74caca49bc9fc2551972accda9de1d8720b486a98d4dbd765059cd0d9d17c4cbe4256f87d1c8e6983d5df62e5d990fcbe7dbf9d249c326972717
@@ -0,0 +1,3 @@
1
+ ## 0.1.0
2
+ - Initial release
3
+
@@ -0,0 +1 @@
1
+ # logstash-codec-csv
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ group :development, :test do
5
+ gem 'rspec'
6
+ end
7
+
8
+
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.
@@ -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,98 @@
1
+ # Logstash Plugin
2
+
3
+ [![Build
4
+ Status](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Codecs/job/logstash-plugin-codec-example-unit/badge/icon)](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Codecs/job/logstash-plugin-codec-example-unit/)
5
+
6
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
7
+
8
+ 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.
9
+
10
+ ## Documentation
11
+
12
+ 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/).
13
+
14
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
15
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
16
+
17
+ ## Need Help?
18
+
19
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
20
+
21
+ ## Developing
22
+
23
+ ### 1. Plugin Developement and Testing
24
+
25
+ #### Code
26
+ - To get started, you'll need JRuby with the Bundler gem installed.
27
+
28
+ - Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization.
29
+
30
+ - Install dependencies
31
+ ```sh
32
+ bundle install
33
+ ```
34
+
35
+ #### Test
36
+
37
+ ```sh
38
+ bundle exec rspec
39
+ ```
40
+
41
+ The Logstash code required to run the tests/specs is specified in the `Gemfile` by the line similar to:
42
+ ```ruby
43
+ gem "logstash", :github => "elasticsearch/logstash", :branch => "1.5"
44
+ ```
45
+ To test against another version or a local Logstash, edit the `Gemfile` to specify an alternative location, for example:
46
+ ```ruby
47
+ gem "logstash", :github => "elasticsearch/logstash", :ref => "master"
48
+ ```
49
+ ```ruby
50
+ gem "logstash", :path => "/your/local/logstash"
51
+ ```
52
+
53
+ Then update your dependencies and run your tests:
54
+
55
+ ```sh
56
+ bundle install
57
+ bundle exec rspec
58
+ ```
59
+
60
+ ### 2. Running your unpublished Plugin in Logstash
61
+
62
+ #### 2.1 Run in a local Logstash clone
63
+
64
+ - Edit Logstash `tools/Gemfile` and add the local plugin path, for example:
65
+ ```ruby
66
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
67
+ ```
68
+ - Update Logstash dependencies
69
+ ```sh
70
+ rake vendor:gems
71
+ ```
72
+ - Run Logstash with your plugin
73
+ ```sh
74
+ bin/logstash -e 'filter {awesome {}}'
75
+ ```
76
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
77
+
78
+ #### 2.2 Run in an installed Logstash
79
+
80
+ - Build your plugin gem
81
+ ```sh
82
+ gem build logstash-filter-awesome.gemspec
83
+ ```
84
+ - Install the plugin from the Logstash home
85
+ ```sh
86
+ bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
87
+ ```
88
+ - Start Logstash and proceed to test the plugin
89
+
90
+ ## Contributing
91
+
92
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
93
+
94
+ 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.
95
+
96
+ It is more important to me that you are able to contribute.
97
+
98
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ require "csv"
3
+ require "logstash/codecs/base"
4
+ require "logstash/util/charset"
5
+
6
+ # The "plain" codec is for plain text with no delimiting between events.
7
+ #
8
+ # This is mainly useful on inputs and outputs that already have a defined
9
+ # framing in their transport protocol (such as zeromq, rabbitmq, redis, etc)
10
+ class LogStash::Codecs::CSV2 < LogStash::Codecs::Base
11
+ config_name "csv2"
12
+
13
+
14
+ config :csv_options, :validate => :hash, :required => false, :default => Hash.new
15
+ config :spreadsheet_safe, :validate => :boolean, :default => true
16
+ config :fields, :validate => :array, :required => true
17
+
18
+ public
19
+ def register
20
+ @csv_options = Hash[@csv_options.map{|(k, v)|[k.to_sym, v]}]
21
+ end
22
+
23
+ public
24
+ #def decode(data)
25
+ # yield LogStash::Event.new("message" => @converter.convert(data))
26
+ #end # def decode
27
+
28
+ public
29
+ def encode(event)
30
+ csv_values = @fields.map {|name| get_value(name, event)}
31
+ @on_event.call(event,csv_values.to_csv(@csv_options))
32
+ end # def encode
33
+
34
+ private
35
+ def get_value(name, event)
36
+ val = event.get(name)
37
+ val.is_a?(Hash) ? LogStash::Json.dump(val) : escape_csv(val)
38
+ end
39
+
40
+ private
41
+ def escape_csv(val)
42
+ (spreadsheet_safe && val.is_a?(String) && val.start_with?("=")) ? "'#{val}" : val
43
+ end
44
+ end # class LogStash::Codecs::Plain
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'logstash-codec-csv2'
4
+ s.version = '0.1.0'
5
+ s.licenses = ['Apache License (2.0)']
6
+ s.summary = "The csv codec is for writing csv output messages. Is does not support input."
7
+ 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"
8
+ s.authors = ["Elastic"]
9
+ s.email = 'info@elastic.co'
10
+ s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
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" => "codec" }
21
+
22
+ # Gem dependencies
23
+ s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
24
+
25
+ s.add_development_dependency 'logstash-devutils'
26
+ end
27
+
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/codecs/csv2"
4
+
5
+
6
+ describe LogStash::Codecs::CSV2 do
7
+ describe "['test1','test2','test3']" do
8
+ subject do
9
+ LogStash::Codecs::CSV2.new({ "fields" => ["test1","test2","test3"]})
10
+ end
11
+ it 'should output empty fields if field is missing' do
12
+ event = LogStash::Event.new({"test1" => "myvalue"})
13
+
14
+ subject.on_event do |ev,output|
15
+ expect(output).to match(/myvalue,,/)
16
+ end
17
+
18
+ subject.encode(event)
19
+ end
20
+
21
+ it 'should output empty fields when no fields are given' do
22
+ event = LogStash::Event.new({})
23
+
24
+ subject.on_event do |ev,output|
25
+ expect(output).to match(/,,/)
26
+ end
27
+
28
+ subject.encode(event)
29
+ end
30
+
31
+ it 'should output correct field in correct place' do
32
+ event = LogStash::Event.new({"test3" => "testvalue"})
33
+
34
+ subject.on_event do |ev,output|
35
+ expect(output).to match(/,,testvalue/)
36
+ end
37
+
38
+ subject.encode(event)
39
+ end
40
+ end
41
+ describe "col_sep" do
42
+ subject do
43
+ LogStash::Codecs::CSV2.new({ "fields" => ["test1","test2","test3"],"csv_options" => {"col_sep" => ";"}})
44
+ end
45
+ it 'should output correct sep' do
46
+ event = LogStash::Event.new({"test3" => "testvalue3","test2" => "testvalue2","test1" => "testvalue1"})
47
+
48
+ subject.on_event do |ev,output|
49
+ expect(output).to match(/testvalue1;testvalue2;testvalue/)
50
+ end
51
+
52
+ subject.encode(event)
53
+ end
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-codec-csv2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Elastic
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-04 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: '1.60'
19
+ - - "<="
20
+ - !ruby/object:Gem::Version
21
+ version: '2.99'
22
+ name: logstash-core-plugin-api
23
+ prerelease: false
24
+ type: :runtime
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.60'
30
+ - - "<="
31
+ - !ruby/object:Gem::Version
32
+ version: '2.99'
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
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'
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: info@elastic.co
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - CHANGELOG.md
54
+ - DEVELOPER.md
55
+ - Gemfile
56
+ - LICENSE
57
+ - NOTICE.TXT
58
+ - README.md
59
+ - lib/logstash/codecs/csv2.rb
60
+ - logstash-codec-csv2.gemspec
61
+ - spec/codecs/csv_spec.rb
62
+ homepage: http://www.elastic.co/guide/en/logstash/current/index.html
63
+ licenses:
64
+ - Apache License (2.0)
65
+ metadata:
66
+ logstash_plugin: 'true'
67
+ logstash_group: codec
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.4.8
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: The csv codec is for writing csv output messages. Is does not support input.
88
+ test_files:
89
+ - spec/codecs/csv_spec.rb