logstash-filter-yaml 0.1.1

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: 068772ddb5786e465e7fcf687745e0fd388c96ee
4
+ data.tar.gz: 07ed043a0d06d2730f139a7c4fd77c9fa81ee870
5
+ SHA512:
6
+ metadata.gz: 2cc42648efdfa4ec8eeda26c039469f63968ead2b85af3d672ac284b91a200ee7e6b767971db4daadd73fcaeb1fc79468612b70159ba46f379f450eb87a57178
7
+ data.tar.gz: 63e8db5a84e53b99ea43b5c4943bd043d36cc16b93d804a3bf5e73a7c4ad789afdcb12b05ce45f4b457afb5510bf6ae2a981c6f7603f1afd8e2f4399b9ec99a6
@@ -0,0 +1,5 @@
1
+ ## 2.0.0
2
+ - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
3
+ instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
4
+ - Dependency on logstash-core update to 2.0
5
+
@@ -0,0 +1,4 @@
1
+ logstash-filter-yaml
2
+ ====================
3
+
4
+ This is an empty placeholder.
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ logstash_path = ENV["LOGSTASH_PATH"] || "../../logstash"
6
+ use_logstash_source = ENV["LOGSTASH_SOURCE"] && ENV["LOGSTASH_SOURCE"].to_s == "1"
7
+
8
+ if Dir.exist?(logstash_path) && use_logstash_source
9
+ gem 'logstash-core', :path => "#{logstash_path}/logstash-core"
10
+ gem 'logstash-core-plugin-api', :path => "#{logstash_path}/logstash-core-plugin-api"
11
+ end
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012–2016 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,103 @@
1
+ # Logstash Plugin
2
+
3
+ [![Build
4
+ Status](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Filters/job/logstash-plugin-filter-yaml-unit/badge/icon)](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Filters/job/logstash-plugin-filter-yaml-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
+ # Logstash 2.3 and higher
87
+ bin/logstash-plugin install --no-verify
88
+
89
+ # Prior to Logstash 2.3
90
+ bin/plugin install --no-verify
91
+
92
+ ```
93
+ - Start Logstash and proceed to test the plugin
94
+
95
+ ## Contributing
96
+
97
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
98
+
99
+ 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.
100
+
101
+ It is more important to me that you are able to contribute.
102
+
103
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,103 @@
1
+ :plugin: yaml
2
+ :type: filter
3
+
4
+ ///////////////////////////////////////////
5
+ START - GENERATED VARIABLES, DO NOT EDIT!
6
+ ///////////////////////////////////////////
7
+ :version: %VERSION%
8
+ :release_date: %RELEASE_DATE%
9
+ :changelog_url: %CHANGELOG_URL%
10
+ :include_path: ../../../../logstash/docs/include
11
+ ///////////////////////////////////////////
12
+ END - GENERATED VARIABLES, DO NOT EDIT!
13
+ ///////////////////////////////////////////
14
+
15
+ [id="plugins-{type}-{plugin}"]
16
+
17
+ === Yaml filter plugin
18
+
19
+ include::{include_path}/plugin_header.asciidoc[]
20
+
21
+ ==== Description
22
+
23
+ This is a YAML parsing filter. It takes an existing field which contains YAML and
24
+ expands it into an actual data structure within the Logstash event.
25
+
26
+ By default it will place the parsed YAML in the root (top level) of the Logstash event, but this
27
+ filter can be configured to place the YAML into any arbitrary event field, using the
28
+ `target` configuration.
29
+
30
+ [id="plugins-{type}s-{plugin}-options"]
31
+ ==== Yaml Filter Configuration Options
32
+
33
+ This plugin supports the following configuration options plus the <<plugins-{type}s-{plugin}-common-options>> described later.
34
+
35
+ [cols="<,<,<",options="header",]
36
+ |=======================================================================
37
+ |Setting |Input type|Required
38
+ | <<plugins-{type}s-{plugin}-source>> |<<string,string>>|Yes
39
+ | <<plugins-{type}s-{plugin}-target>> |<<string,string>>|No
40
+ |=======================================================================
41
+
42
+ Also see <<plugins-{type}s-{plugin}-common-options>> for a list of options supported by all
43
+ filter plugins.
44
+
45
+ &nbsp;
46
+
47
+ [id="plugins-{type}s-{plugin}-exclude_tags"]
48
+ ===== `exclude_tags` (DEPRECATED)
49
+
50
+ * DEPRECATED WARNING: This configuration item is deprecated and may not be available in future versions.
51
+ * Value type is <<array,array>>
52
+ * Default value is `[]`
53
+
54
+ Only handle events without any of these tags.
55
+ Optional.
56
+
57
+ [id="plugins-{type}s-{plugin}-source"]
58
+ ===== `source`
59
+
60
+ * This is a required setting.
61
+ * Value type is <<string,string>>
62
+ * There is no default value for this setting.
63
+
64
+ The configuration for the YAML filter:
65
+ [source,ruby]
66
+ source => source_field
67
+
68
+ For example, if you have YAML data in the @message field:
69
+ [source,ruby]
70
+ filter {
71
+ yaml {
72
+ source => "message"
73
+ }
74
+ }
75
+
76
+ The above would parse the yaml from the @message field
77
+
78
+ [id="plugins-{type}s-{plugin}-target"]
79
+ ===== `target`
80
+
81
+ * Value type is <<string,string>>
82
+ * There is no default value for this setting.
83
+
84
+ Define the target field for placing the parsed data. If this setting is
85
+ omitted, the YAML data will be stored at the root (top level) of the event.
86
+
87
+ For example, if you want the data to be put in the `doc` field:
88
+ [source,ruby]
89
+ filter {
90
+ yaml {
91
+ target => "doc"
92
+ }
93
+ }
94
+
95
+ YAML in the value of the `source` field will be expanded into a
96
+ data structure in the `target` field.
97
+
98
+ NOTE: if the `target` field already exists, it will be overwritten!
99
+
100
+
101
+
102
+ [id="plugins-{type}s-{plugin}-common-options"]
103
+ include::{include_path}/{type}.asciidoc[]
@@ -0,0 +1,100 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require "logstash/namespace"
4
+ require "logstash/timestamp"
5
+
6
+ # This is a YAML parsing filter. It takes an existing field which contains YAML and
7
+ # expands it into an actual data structure within the Logstash event.
8
+ #
9
+ # By default it will place the parsed YAML in the root (top level) of the Logstash event, but this
10
+ # filter can be configured to place the YAML into any arbitrary event field, using the
11
+ # `target` configuration.
12
+ class LogStash::Filters::Yaml < LogStash::Filters::Base
13
+
14
+ config_name "yaml"
15
+
16
+ # The configuration for the YAML filter:
17
+ # [source,ruby]
18
+ # source => source_field
19
+ #
20
+ # For example, if you have YAML data in the @message field:
21
+ # [source,ruby]
22
+ # filter {
23
+ # yaml {
24
+ # source => "message"
25
+ # }
26
+ # }
27
+ #
28
+ # The above would parse the yaml from the @message field
29
+ config :source, :validate => :string, :required => true
30
+
31
+ # Define the target field for placing the parsed data. If this setting is
32
+ # omitted, the YAML data will be stored at the root (top level) of the event.
33
+ #
34
+ # For example, if you want the data to be put in the `doc` field:
35
+ # [source,ruby]
36
+ # filter {
37
+ # yaml {
38
+ # target => "doc"
39
+ # }
40
+ # }
41
+ #
42
+ # YAML in the value of the `source` field will be expanded into a
43
+ # data structure in the `target` field.
44
+ #
45
+ # NOTE: if the `target` field already exists, it will be overwritten!
46
+ config :target, :validate => :string
47
+
48
+ public
49
+ def register
50
+ require 'yaml'
51
+ end # def register
52
+
53
+ public
54
+ def filter(event)
55
+ return unless filter?(event)
56
+
57
+ @logger.debug("Running yaml filter", :event => event)
58
+
59
+ return unless event.include?(@source)
60
+
61
+ source = event[@source]
62
+
63
+ if @target.nil?
64
+ # Default is to write to the root of the event.
65
+ dest = event.to_hash
66
+ else
67
+ if @target == @source
68
+ # Overwrite source
69
+ event[@target] = {}
70
+ else
71
+ event[@target] ||= {}
72
+ end
73
+ dest = event[@target]
74
+ end
75
+
76
+ begin
77
+ dest.merge!(YAML::load(source))
78
+
79
+ # If no target, we target the root of the event object. This can allow
80
+ # you to overwrite @timestamp and this will typically happen for yaml
81
+ # LogStash Event deserialized here.
82
+ if !@target && event.timestamp.is_a?(String)
83
+ event.timestamp = LogStash::Timestamp.parse_iso8601(event.timestamp)
84
+ end
85
+
86
+ filter_matched(event)
87
+ rescue => e
88
+ tag = "_yamlparsefailure"
89
+ event["tags"] ||= []
90
+ event["tags"] << tag unless event["tags"].include?(tag)
91
+ @logger.warn("Trouble parsing yaml", :source => @source,
92
+ :raw => event[@source], :exception => e)
93
+ return
94
+ end
95
+
96
+ @logger.debug("Event after yaml filter", :event => event)
97
+
98
+ end # def filter
99
+
100
+ end # class LogStash::Filters::Yaml
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'logstash-filter-yaml'
4
+ s.version = '0.1.1'
5
+ s.licenses = ['Apache License (2.0)']
6
+ s.summary = "This is a YAML parsing filter. It takes an existing field which contains YAML and expands it into an actual data structure within the Logstash event."
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 = ["Jean-Philippe Briend"]
9
+ s.email = 'jeanphilippe.briend@gmail.com'
10
+ s.homepage = "http://www.elasticsearch.org/guide/en/logstash/current/index.html"
11
+ s.require_paths = ["lib"]
12
+
13
+ # Files
14
+ s.files = Dir["lib/**/*","spec/**/*","*.gemspec","*.md","CONTRIBUTORS","Gemfile","LICENSE","NOTICE.TXT", "vendor/jar-dependencies/**/*.jar", "vendor/jar-dependencies/**/*.rb", "VERSION", "docs/**/*"]
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" => "filter" }
21
+
22
+ # Gem dependencies
23
+ s.add_runtime_dependency 'logstash-core', '>= 1.4.0', '< 2.0.0'
24
+
25
+ s.add_development_dependency 'logstash-devutils'
26
+ end
27
+
@@ -0,0 +1,89 @@
1
+ require "logstash/devutils/rspec/spec_helper"
2
+ require "logstash/filters/yaml"
3
+ require "logstash/timestamp"
4
+
5
+ describe LogStash::Filters::Yaml do
6
+
7
+ describe "parse message into the event" do
8
+ config <<-CONFIG
9
+ filter {
10
+ yaml {
11
+ # Parse message as YAML
12
+ source => "message"
13
+ }
14
+ }
15
+ CONFIG
16
+
17
+ sample '{ hello: "world", list: [ 1, 2, 3 ], hash: { k: v }, sometime: "2013-10-19T00:14:32.996Z" }' do
18
+ insist { subject["hello"] } == "world"
19
+ insist { subject["list" ].to_a } == [1,2,3] # to_a for JRuby + JrJacksom which creates Java ArrayList
20
+ insist { subject["hash"] } == { "k" => "v" }
21
+ end
22
+ end
23
+
24
+ describe "parse message into a target field" do
25
+ config <<-CONFIG
26
+ filter {
27
+ yaml {
28
+ # Parse message as YAML, store the results in the 'data' field'
29
+ source => "message"
30
+ target => "data"
31
+ }
32
+ }
33
+ CONFIG
34
+
35
+ sample '{ hello: "world", list: [ 1, 2, 3 ], "hash": { k: v } }' do
36
+ insist { subject["data"]["hello"] } == "world"
37
+ insist { subject["data"]["list" ].to_a } == [1,2,3] # to_a for JRuby + JrJacksom which creates Java ArrayList
38
+ insist { subject["data"]["hash"] } == { "k" => "v" }
39
+ end
40
+ end
41
+
42
+ describe "tag invalid yaml" do
43
+ config <<-CONFIG
44
+ filter {
45
+ yaml {
46
+ # Parse message as YAML, store the results in the 'data' field'
47
+ source => "message"
48
+ target => "data"
49
+ }
50
+ }
51
+ CONFIG
52
+
53
+ sample "invalid yaml" do
54
+ insist { subject["tags"] }.include?("_yamlparsefailure")
55
+ end
56
+ end
57
+
58
+ describe "testing @timestamp" do
59
+ config <<-CONFIG
60
+ filter {
61
+ yaml {
62
+ source => "message"
63
+ }
64
+ }
65
+ CONFIG
66
+
67
+ sample "{ \"@timestamp\": \"2013-10-19T00:14:32.996Z\" }" do
68
+ insist { subject["@timestamp"] }.is_a?(LogStash::Timestamp)
69
+ insist { YAML::dump(subject["@timestamp"]) } == "--- !ruby/object:LogStash::Timestamp\ntime: 2013-10-19 00:14:32.996000000 Z\n"
70
+ end
71
+ end
72
+
73
+ describe "source == target" do
74
+ config <<-CONFIG
75
+ filter {
76
+ yaml {
77
+ source => "example"
78
+ target => "example"
79
+ }
80
+ }
81
+ CONFIG
82
+
83
+ sample({ "example" => "{ hello: world }" }) do
84
+ insist { subject["example"] }.is_a?(Hash)
85
+ insist { subject["example"]["hello"] } == "world"
86
+ end
87
+ end
88
+
89
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-yaml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Jean-Philippe Briend
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-23 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.4.0
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: 2.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: 1.4.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.0
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/plugin install gemname. This gem is not a stand-alone program
48
+ email: jeanphilippe.briend@gmail.com
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
+ - docs/index.asciidoc
60
+ - lib/logstash/filters/yaml.rb
61
+ - logstash-filter-yaml.gemspec
62
+ - spec/filters/yaml_spec.rb
63
+ homepage: http://www.elasticsearch.org/guide/en/logstash/current/index.html
64
+ licenses:
65
+ - Apache License (2.0)
66
+ metadata:
67
+ logstash_plugin: 'true'
68
+ logstash_group: filter
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.4.8
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: This is a YAML parsing filter. It takes an existing field which contains YAML and expands it into an actual data structure within the Logstash event.
89
+ test_files:
90
+ - spec/filters/yaml_spec.rb