logstash-codec-fieldselect 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +6 -0
- data/DEVELOPER.md +3 -0
- data/Gemfile +2 -0
- data/LICENSE +13 -0
- data/NOTICE.TXT +5 -0
- data/README.md +95 -0
- data/lib/logstash/codecs/fieldselect.rb +68 -0
- data/logstash-codec-fieldselect.gemspec +30 -0
- data/spec/codecs/fieldselect_spec.rb +55 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a075afdb1663756aaa56fd54f12274f2b7a43e44
|
4
|
+
data.tar.gz: 5f06c6c4d8948b949386acb3cd5a645aff3cebcd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f3a0ee904f10aefde40d22bae58591c7bde9da51f1a053e2fd995de36bf7392b4dbba72c64cb98b795fcbc678f21781a174c4d7d87ccf5408a09bb9235e41c1f
|
7
|
+
data.tar.gz: af046b760da653ff6123a9548be4719cc0b88cbdde50eabbe225db66abf7cf6d0aaee974e9770278119bc38737b4260c76f8090f1e79ef1fec466d4305619508
|
data/CHANGELOG.md
ADDED
data/DEVELOPER.md
ADDED
data/Gemfile
ADDED
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.
|
data/NOTICE.TXT
ADDED
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,68 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/codecs/base"
|
3
|
+
require "logstash/codecs/line"
|
4
|
+
|
5
|
+
class LogStash::Codecs::Fieldselect < LogStash::Codecs::Base
|
6
|
+
|
7
|
+
# This codec will select only the fields listed or default
|
8
|
+
# to only selecting message
|
9
|
+
#
|
10
|
+
# input {
|
11
|
+
# stdin { codec => fieldselect { fields => [] }
|
12
|
+
# }
|
13
|
+
#
|
14
|
+
# or
|
15
|
+
#
|
16
|
+
# output {
|
17
|
+
# stdout { codec => fieldselect { fields => [] }
|
18
|
+
# }
|
19
|
+
config_name "fieldselect"
|
20
|
+
|
21
|
+
# Select fields to output, concated with a comma
|
22
|
+
config :fields, :validate => :array, :default => ['message']
|
23
|
+
|
24
|
+
public
|
25
|
+
def register
|
26
|
+
@lines = LogStash::Codecs::Line.new
|
27
|
+
@lines.charset = "UTF-8"
|
28
|
+
end
|
29
|
+
|
30
|
+
public
|
31
|
+
def decode(data)
|
32
|
+
@lines.decode(data) do |line|
|
33
|
+
logger.debug? and @logger.debug("Running fieldselect codec", :data => data)
|
34
|
+
selected = field_selector(line)
|
35
|
+
logger.debug? and @logger.debug("Fieldselect codec ran", :selected => selected)
|
36
|
+
yield LogStash::Event.new(selected)
|
37
|
+
end
|
38
|
+
end # def decode
|
39
|
+
|
40
|
+
public
|
41
|
+
def encode(event)
|
42
|
+
encoded = field_concater(event)
|
43
|
+
@on_event.call(event, encoded)
|
44
|
+
end # def encode
|
45
|
+
|
46
|
+
private
|
47
|
+
def field_selector(data)
|
48
|
+
selected = {}
|
49
|
+
@fields.each do |field|
|
50
|
+
selected[field] = data[field]
|
51
|
+
end
|
52
|
+
return selected
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def field_concater(data)
|
57
|
+
concated = ""
|
58
|
+
@fields.each do |field|
|
59
|
+
if data[field] == nil
|
60
|
+
concated += ","
|
61
|
+
next
|
62
|
+
end
|
63
|
+
concated += data[field].to_s + ", "
|
64
|
+
end
|
65
|
+
concated.chomp!(", ")
|
66
|
+
return concated + "\n"
|
67
|
+
end
|
68
|
+
end # class LogStash::Codecs::Fieldselect
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
|
3
|
+
s.name = 'logstash-codec-fieldselect'
|
4
|
+
s.version = '0.0.2'
|
5
|
+
s.licenses = ['Apache License (2.0)']
|
6
|
+
s.summary = "This codec was created to select certain fields for output"
|
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 = ["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" => "output" }
|
21
|
+
|
22
|
+
# Gem dependencies
|
23
|
+
s.add_runtime_dependency "logstash-core", ">= 2.0.0.beta2", "< 3.0.0"
|
24
|
+
s.add_runtime_dependency 'logstash-mixin-aws'
|
25
|
+
s.add_runtime_dependency 'stud', '~> 0.0.22'
|
26
|
+
s.add_development_dependency 'logstash-devutils'
|
27
|
+
s.add_development_dependency 'logstash-input-generator'
|
28
|
+
s.add_development_dependency 'logstash-codec-line'
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "logstash/devutils/rspec/spec_helper"
|
4
|
+
require "logstash/codecs/fieldselect"
|
5
|
+
require "logstash/event"
|
6
|
+
|
7
|
+
describe LogStash::Codecs::Fieldselect do
|
8
|
+
context "default settings" do
|
9
|
+
subject do
|
10
|
+
next LogStash::Codecs::Fieldselect.new
|
11
|
+
end
|
12
|
+
|
13
|
+
context "#encode" do
|
14
|
+
let (:event) {LogStash::Event.new({"message" => "hello world", "host" => "test", "leggo" => "my eggo"})}
|
15
|
+
|
16
|
+
it "should return only the default select field, message" do
|
17
|
+
expect(subject).to receive(:on_event).once.and_call_original
|
18
|
+
subject.on_event do |e, d|
|
19
|
+
insist {d} == event['message'] + "\n"
|
20
|
+
end
|
21
|
+
subject.encode(event)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "#decode" do
|
26
|
+
it "should return only the default select field, message" do
|
27
|
+
decoded = false
|
28
|
+
subject.decode("hello world\n") do |e|
|
29
|
+
decoded = true
|
30
|
+
insist { e.is_a?(LogStash::Event) }
|
31
|
+
insist { e["message"] } == "hello world"
|
32
|
+
insist { e["host"] } == nil
|
33
|
+
end
|
34
|
+
insist { decoded } == true
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "select specific fields" do
|
41
|
+
subject do
|
42
|
+
next LogStash::Codecs::Fieldselect.new({'fields' => ['message', 'leggo']})
|
43
|
+
end
|
44
|
+
|
45
|
+
context "#encode" do
|
46
|
+
it "should return both selected fields, message and leggo" do
|
47
|
+
expect(subject).to receive(:on_event).once.and_call_original
|
48
|
+
subject.on_event do |e, d|
|
49
|
+
insist {d} == event['message'] + ", " + event['leggo'] + "\n"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-codec-fieldselect
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Elastic
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-30 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: '0'
|
39
|
+
name: logstash-mixin-aws
|
40
|
+
prerelease: false
|
41
|
+
type: :runtime
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ~>
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 0.0.22
|
53
|
+
name: stud
|
54
|
+
prerelease: false
|
55
|
+
type: :runtime
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.0.22
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
name: logstash-devutils
|
68
|
+
prerelease: false
|
69
|
+
type: :development
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
name: logstash-input-generator
|
82
|
+
prerelease: false
|
83
|
+
type: :development
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
requirement: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
name: logstash-codec-line
|
96
|
+
prerelease: false
|
97
|
+
type: :development
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
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
|
104
|
+
email: info@elastic.co
|
105
|
+
executables: []
|
106
|
+
extensions: []
|
107
|
+
extra_rdoc_files: []
|
108
|
+
files:
|
109
|
+
- CHANGELOG.md
|
110
|
+
- DEVELOPER.md
|
111
|
+
- Gemfile
|
112
|
+
- LICENSE
|
113
|
+
- NOTICE.TXT
|
114
|
+
- README.md
|
115
|
+
- lib/logstash/codecs/fieldselect.rb
|
116
|
+
- logstash-codec-fieldselect.gemspec
|
117
|
+
- spec/codecs/fieldselect_spec.rb
|
118
|
+
homepage: http://www.elastic.co/guide/en/logstash/current/index.html
|
119
|
+
licenses:
|
120
|
+
- Apache License (2.0)
|
121
|
+
metadata:
|
122
|
+
logstash_plugin: 'true'
|
123
|
+
logstash_group: output
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - '>='
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.4.8
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: This codec was created to select certain fields for output
|
144
|
+
test_files:
|
145
|
+
- spec/codecs/fieldselect_spec.rb
|