logstash-filter-remove_key_pattern 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +2 -0
- data/LICENSE +11 -0
- data/README.md +86 -0
- data/lib/logstash/filters/remove_key_pattern.rb +66 -0
- data/logstash-filter-remove_key_pattern.gemspec +22 -0
- data/spec/filters/remove_key_pattern_spec.rb +98 -0
- data/spec/spec_helper.rb +2 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fdea4c729036149c31577a3da38c119fcbd32412
|
4
|
+
data.tar.gz: 53598fbdb3513c2f009bd1b5ff6311d1e9daf5e9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7b22d733cc9eb7bf767b179f93ae1cb36ebdcf90fef91fae0d3ba70f5a4851b227841d0c338c5c34383de0616a2cd2ec8c6838247e5dcb65710c976b943f6505
|
7
|
+
data.tar.gz: 445d1b9a17298e4fccc6b516bdc29f806d38954fcd1528dc866abb0acd231f3c2374d74726b3cef91c82d7dcc4da570a7ff3fbabd3bb11fe20eae8c25adfc845
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
2
|
+
you may not use this file except in compliance with the License.
|
3
|
+
You may obtain a copy of the License at
|
4
|
+
|
5
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
6
|
+
|
7
|
+
Unless required by applicable law or agreed to in writing, software
|
8
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
9
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
10
|
+
See the License for the specific language governing permissions and
|
11
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
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. 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/logstash-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/logstash-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/elastic/logstash/blob/master/CONTRIBUTING.md) file.
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/filters/base"
|
3
|
+
require "logstash/namespace"
|
4
|
+
require "logstash/json"
|
5
|
+
|
6
|
+
# Remove key pattern filter. Receives a parent key and an array
|
7
|
+
# with multiple patterns to remove from it's children
|
8
|
+
#
|
9
|
+
# For example, if you have a parent named 'haystack', and you want to
|
10
|
+
# remove all his children that contains a digit(\d) or 'needle', do this:
|
11
|
+
# [source, ruby]
|
12
|
+
# filter {
|
13
|
+
# remove_key_pattern {
|
14
|
+
# parent_keys => ["haystack1", "haystack2"]
|
15
|
+
# pattern => ["\\d", "needle"]
|
16
|
+
# keep_only_ids => "true"
|
17
|
+
# }
|
18
|
+
# }
|
19
|
+
#
|
20
|
+
class LogStash::Filters::RemoveKeyPattern < LogStash::Filters::Base
|
21
|
+
|
22
|
+
config_name "remove_key_pattern"
|
23
|
+
|
24
|
+
# Array of parent keys to remove from
|
25
|
+
config :parent_keys, :validate => :array, :required => true
|
26
|
+
|
27
|
+
# Array of patterns to remove
|
28
|
+
config :pattern, :validate => :array, :required => true
|
29
|
+
|
30
|
+
# Boolean to set if the filter should prevent everything besides the ids that are not in the patterns to pass
|
31
|
+
config :keep_only_ids, :validate => :boolean, :required => true, :default => false
|
32
|
+
|
33
|
+
public
|
34
|
+
def register
|
35
|
+
begin
|
36
|
+
@pattern = Regexp.new(@pattern.join('|'))
|
37
|
+
rescue
|
38
|
+
@logger.error("One or more keys are invalid", :pattern => @pattern.join(', '))
|
39
|
+
raise "Bad pattern, aborting"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
public
|
44
|
+
def filter(event)
|
45
|
+
@parent_keys.each do |key|
|
46
|
+
remove_pattern(event, key) unless event.get(key).nil?
|
47
|
+
end
|
48
|
+
filter_matched(event)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
def remove_pattern(event, key)
|
53
|
+
hash = {}
|
54
|
+
event.get(key).each do |k, v|
|
55
|
+
unless (k =~ @pattern)
|
56
|
+
if @keep_only_ids && (k == 'id' or k =~ /.*_id$/)
|
57
|
+
hash[k] = v
|
58
|
+
elsif !@keep_only_ids
|
59
|
+
hash[k] = v
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
event.set("#{key}_json", LogStash::Json.dump(event.get(key)))
|
64
|
+
event.set(key, hash)
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'logstash-filter-remove_key_pattern'
|
3
|
+
s.version = '0.1.0'
|
4
|
+
s.licenses = ['Apache-2.0']
|
5
|
+
s.summary = 'Remove all keys that match pattern'
|
6
|
+
s.authors = ['Arthur Alfredo']
|
7
|
+
s.email = 'a.alfredo@miceportal.com'
|
8
|
+
s.require_paths = ['lib']
|
9
|
+
s.homepage = 'http://github.com/miceportal/logstash_filter_remove_key_pattern'
|
10
|
+
|
11
|
+
# Files
|
12
|
+
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','Gemfile','LICENSE']
|
13
|
+
# Tests
|
14
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
15
|
+
|
16
|
+
# Special flag to let us know this is actually a logstash plugin
|
17
|
+
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
|
18
|
+
|
19
|
+
# Gem dependencies
|
20
|
+
s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
|
21
|
+
s.add_development_dependency 'logstash-devutils', "~> 1.3", ">= 1.3.0"
|
22
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require_relative '../spec_helper'
|
3
|
+
require "logstash/filters/remove_key_pattern"
|
4
|
+
|
5
|
+
describe LogStash::Filters::RemoveKeyPattern do
|
6
|
+
|
7
|
+
describe "remove a pattern from parent keys keeping only ids" do
|
8
|
+
config <<-CONFIG
|
9
|
+
filter {
|
10
|
+
remove_key_pattern {
|
11
|
+
parent_keys => ["haystack2", "haystack"]
|
12
|
+
pattern => ["needle", "\\d"]
|
13
|
+
keep_only_ids => "true"
|
14
|
+
}
|
15
|
+
}
|
16
|
+
CONFIG
|
17
|
+
|
18
|
+
hash = {
|
19
|
+
"hello" => {
|
20
|
+
"numbers" => ["one", "two", "three"],
|
21
|
+
"47" => ["2", "3", "7"],
|
22
|
+
},
|
23
|
+
"haystack" => {
|
24
|
+
"key1_id" => ["value1", "value2", "value3"],
|
25
|
+
"id" => ["value1", "value2", "value3"],
|
26
|
+
"key4_id" => ["value1", "value2", "value3"],
|
27
|
+
"key_four_id" => ["value1", "value2", "value3"],
|
28
|
+
"needle" => ["value1", "value2", "value3"],
|
29
|
+
},
|
30
|
+
"haystack2" => {
|
31
|
+
"key_one_id" => ["value1", "value2", "value3"],
|
32
|
+
"id" => ["value1", "value2", "value3"],
|
33
|
+
"key4_id" => ["value1", "value2", "value3"],
|
34
|
+
"key" => ["value1", "value2", "value3"],
|
35
|
+
"foobar" => ["value1", "value2", "value3"],
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
sample(hash) do
|
40
|
+
insist { subject.get("hello") }.include?("numbers")
|
41
|
+
insist { subject.get("haystack") }.include?("id")
|
42
|
+
insist { subject.get("haystack") }.include?("key_four_id")
|
43
|
+
reject { subject.get("haystack") }.include?("key4_id")
|
44
|
+
reject { subject.get("haystack2") }.include?("needle")
|
45
|
+
insist { subject.get("haystack2") }.include?("key_one_id")
|
46
|
+
reject { subject.get("haystack2") }.include?("key4_id")
|
47
|
+
reject { subject.get("haystack2") }.include?("key")
|
48
|
+
reject { subject.get("haystack2") }.include?("foobar")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "remove a pattern from parent keys without keeping only ids" do
|
53
|
+
config <<-CONFIG
|
54
|
+
filter {
|
55
|
+
remove_key_pattern {
|
56
|
+
parent_keys => ["haystack2", "haystack"]
|
57
|
+
pattern => ["needle", "\\d"]
|
58
|
+
keep_only_ids => "false"
|
59
|
+
}
|
60
|
+
}
|
61
|
+
CONFIG
|
62
|
+
|
63
|
+
hash = {
|
64
|
+
"hello" => {
|
65
|
+
"numbers" => ["one", "two", "three"],
|
66
|
+
"47" => ["2", "3", "7"],
|
67
|
+
},
|
68
|
+
"haystack" => {
|
69
|
+
"key1_id" => ["value1", "value2", "value3"],
|
70
|
+
"id" => ["value1", "value2", "value3"],
|
71
|
+
"key4_id" => ["value1", "value2", "value3"],
|
72
|
+
"key_four_id" => ["value1", "value2", "value3"],
|
73
|
+
"needle" => ["value1", "value2", "value3"],
|
74
|
+
},
|
75
|
+
"haystack2" => {
|
76
|
+
"key_one_id" => ["value1", "value2", "value3"],
|
77
|
+
"id" => ["value1", "value2", "value3"],
|
78
|
+
"key4_id" => ["value1", "value2", "value3"],
|
79
|
+
"key" => ["value1", "value2", "value3"],
|
80
|
+
"foobar" => ["value1", "value2", "value3"],
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
sample(hash) do
|
85
|
+
insist { subject.get("hello") }.include?("numbers")
|
86
|
+
insist { subject.get("haystack") }.include?("id")
|
87
|
+
insist { subject.get("haystack") }.include?("key_four_id")
|
88
|
+
reject { subject.get("haystack") }.include?("key4_id")
|
89
|
+
reject { subject.get("haystack2") }.include?("needle")
|
90
|
+
insist { subject.get("haystack2") }.include?("key_one_id")
|
91
|
+
reject { subject.get("haystack2") }.include?("key4_id")
|
92
|
+
insist { subject.get("haystack2") }.include?("key")
|
93
|
+
insist { subject.get("haystack2") }.include?("foobar")
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-filter-remove_key_pattern
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Arthur Alfredo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-01 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: '1.3'
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.3.0
|
42
|
+
name: logstash-devutils
|
43
|
+
prerelease: false
|
44
|
+
type: :development
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.3'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.3.0
|
53
|
+
description:
|
54
|
+
email: a.alfredo@miceportal.com
|
55
|
+
executables: []
|
56
|
+
extensions: []
|
57
|
+
extra_rdoc_files: []
|
58
|
+
files:
|
59
|
+
- Gemfile
|
60
|
+
- LICENSE
|
61
|
+
- README.md
|
62
|
+
- lib/logstash/filters/remove_key_pattern.rb
|
63
|
+
- logstash-filter-remove_key_pattern.gemspec
|
64
|
+
- spec/filters/remove_key_pattern_spec.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
homepage: http://github.com/miceportal/logstash_filter_remove_key_pattern
|
67
|
+
licenses:
|
68
|
+
- Apache-2.0
|
69
|
+
metadata:
|
70
|
+
logstash_plugin: 'true'
|
71
|
+
logstash_group: filter
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.6.8
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Remove all keys that match pattern
|
92
|
+
test_files:
|
93
|
+
- spec/filters/remove_key_pattern_spec.rb
|
94
|
+
- spec/spec_helper.rb
|