logstash-filter-contains 1.0.0-java

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: 34c2672e7b79ed2fade7c9eaa406023435edae44
4
+ data.tar.gz: 987c6c08d7ec7b1e8729eba02ef16f0b9712f7b9
5
+ SHA512:
6
+ metadata.gz: d12a48998e71d7228a178a29c785fdb9ef011cf438a586c2f65a09769af7f1f9a4dadc7fade39fafccc568e3acfce8b79fc9213712b945877d16779fff64302e
7
+ data.tar.gz: 37746e2b3f644f4aa3e7e533f7e44f1591754ecdd8100fde9db8249a90fbfd633ff51902ecbed02efff533e6a76d12ec6dd993a3aa93e279bc875fa0945ab80e
data/CONTRIBUTORS ADDED
@@ -0,0 +1,5 @@
1
+ The following people (name and/or nickname and/or GitHub id) have contributed code
2
+ patches or helped out in other ways to the Logstash Filter Contains project:
3
+
4
+ Contributors:
5
+ * donghyeon kim (EastBright) (inaz1502)
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.
data/README.md ADDED
@@ -0,0 +1,96 @@
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
+ # Logstash 2.3 and higher
57
+ bin/logstash-plugin install --no-verify
58
+
59
+ # Prior to Logstash 2.3
60
+ bin/plugin install --no-verify
61
+
62
+ ```
63
+ - Run Logstash with your plugin
64
+ ```sh
65
+ bin/logstash -e 'filter {awesome {}}'
66
+ ```
67
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
68
+
69
+ #### 2.2 Run in an installed Logstash
70
+
71
+ 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:
72
+
73
+ - Build your plugin gem
74
+ ```sh
75
+ gem build logstash-filter-awesome.gemspec
76
+ ```
77
+ - Install the plugin from the Logstash home
78
+ ```sh
79
+ # Logstash 2.3 and higher
80
+ bin/logstash-plugin install --no-verify
81
+
82
+ # Prior to Logstash 2.3
83
+ bin/plugin install --no-verify
84
+
85
+ ```
86
+ - Start Logstash and proceed to test the plugin
87
+
88
+ ## Contributing
89
+
90
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
91
+
92
+ 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.
93
+
94
+ It is more important to the community that you are able to contribute.
95
+
96
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,111 @@
1
+ :plugin: contains
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}s-{plugin}"]
16
+
17
+ === Contains filter plugin
18
+
19
+ include::{include_path}/plugin_header.asciidoc[]
20
+
21
+ ==== Description
22
+
23
+ filter to check if value is contains
24
+
25
+ [id="plugins-{type}s-{plugin}-options"]
26
+ ==== Contains Filter Configuration Options
27
+
28
+ This plugin supports the following configuration options plus the <<plugins-{type}s-{plugin}-common-options>> described later.
29
+
30
+ [cols="<,<,<",options="header",]
31
+ |=======================================================================
32
+ |Setting |Input type|Required
33
+ | <<plugins-{type}s-{plugin}-field>> |<<array,array>>|No
34
+ | <<plugins-{type}s-{plugin}-value>> |<<array,array>>|No
35
+ | <<plugins-{type}s-{plugin}-value_path>> |a valid filesystem path|No
36
+ | <<plugins-{type}s-{plugin}-refresh_interval>>| <<number,number>>|No
37
+ | <<plugins-{type}s-{plugin}-separator>> |<<string,string>>|No
38
+ |=======================================================================
39
+
40
+ Also see <<plugins-{type}s-{plugin}-common-options>> for a list of options supported by all
41
+ filter plugins.
42
+
43
+ &nbsp;
44
+
45
+ [id="plugins-{type}s-{plugin}-field"]
46
+ ===== `field`
47
+
48
+ * Value type is <<array,array>>
49
+ * Default value is `[]`
50
+
51
+ The field[s] to check with. Example:
52
+ [source,ruby]
53
+ filter {
54
+ contains {
55
+ add_tag => [ "fruits" ]
56
+ field => [ "%{a}", "%{b}" ]
57
+ value => [ "apple" ]
58
+ }
59
+ }
60
+
61
+ [id="plugins-{type}s-{plugin}-value"]
62
+ ===== `value`
63
+
64
+ * Value type is <<array,array>>
65
+ * Default value is `[]`
66
+
67
+ The value(s) to check against. Example:
68
+ [source,ruby]
69
+ filter {
70
+ contains {
71
+ add_tag => [ "fruits" ]
72
+ field => [ "%{a}" ]
73
+ value => [ "banana" ]
74
+ }
75
+ }
76
+
77
+
78
+ [id="plugins-{type}s-{plugin}-value_path"]
79
+ ===== `value_path`
80
+
81
+ * Value type is <<path,path>>
82
+ * There is no default value for this setting.
83
+
84
+ The full path of the external file containing the values the filter should check with.
85
+ Values are separated by a separator character defined in `separator`.
86
+ [source,ruby]
87
+ apple
88
+ banana
89
+ NOTE: It is an error to specify both `value` and `value_path`.
90
+
91
+ [id="plugins-{type}s-{plugin}-refresh_interval"]
92
+ ===== `refresh_interval`
93
+
94
+ * Value type is <<number,number>>
95
+ * Default value is `600`
96
+
97
+ When using an external file, this setting will indicate how frequently
98
+ (in seconds) Logstash will check the file for updates.
99
+
100
+
101
+ [id="plugins-{type}s-{plugin}-separator"]
102
+ ===== `separator`
103
+
104
+ * Value type is <<string,string>>
105
+ * Default value is `\n`
106
+
107
+ Separator character used for parsing values from the external file
108
+ specified by `value_path`. Defaults to newline `\n` character.
109
+
110
+ [id="plugins-{type}s-{plugin}-common-options"]
111
+ include::{include_path}/{type}.asciidoc[]
@@ -0,0 +1,155 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require "logstash/namespace"
4
+ require "set"
5
+
6
+ java_import 'java.util.concurrent.locks.ReentrantReadWriteLock'
7
+
8
+ class LogStash::Filters::CONTAINS < LogStash::Filters::Base
9
+
10
+ config_name "contains"
11
+
12
+ # The field(s) to check with. Example:
13
+ # [source,ruby]
14
+ # filter {
15
+ # %PLUGIN% {
16
+ # add_tag => [ "fruits" ]
17
+ # field => [ "%{a}" ]
18
+ # value => [ "apple" ]
19
+ # }
20
+ # }
21
+ config :field, :validate => :array, :default => []
22
+
23
+ # The value(s) to check against. Example:
24
+ # [source,ruby]
25
+ # filter {
26
+ # %PLUGIN% {
27
+ # add_tag => [ "fruits" ]
28
+ # field => [ "%{a}" ]
29
+ # value => [ "banana" ]
30
+ # }
31
+ # }
32
+ config :value, :validate => :array, :default => []
33
+
34
+ # The full path of the external file containing the value(s) to check against. Example:
35
+ # [source,ruby]
36
+ # filter {
37
+ # %PLUGIN% {
38
+ # add_tag => [ "fruits" ]
39
+ # field => [ "%{a}" ]
40
+ # value_path => "/etc/logstash/fruits"
41
+ # }
42
+ # }
43
+ # NOTE: it is an error to specify both 'value' and 'value_path'.
44
+ config :value_path, :validate => :path
45
+
46
+ # When using a network list from a file, this setting will indicate
47
+ # how frequently (in seconds) Logstash will check the file for
48
+ # updates.
49
+ config :refresh_interval, :validate => :number, :default => 600
50
+
51
+ # The separator character used in the encoding of the external file
52
+ # pointed by value_path.
53
+ config :separator, :validate => :string, :default => "\n"
54
+
55
+ public
56
+ def register
57
+ rw_lock = java.util.concurrent.locks.ReentrantReadWriteLock.new
58
+ @read_lock = rw_lock.readLock
59
+ @write_lock = rw_lock.writeLock
60
+
61
+ if @value_path && !@value.empty? #checks if both value and value_path are defined in configuration options
62
+ raise LogStash::ConfigurationError, I18n.t(
63
+ "logstash.agent.configuration.invalid_plugin_register",
64
+ :plugin => "filter",
65
+ :type => "contains",
66
+ :error => "The configuration options 'value' and 'value_path' are mutually exclusive"
67
+ )
68
+ end
69
+
70
+ if !@value.empty?
71
+ @value_set = @value.to_set
72
+ end
73
+
74
+ if @value_path
75
+ @next_refresh = Time.now + @refresh_interval
76
+ lock_for_write { load_file }
77
+ end
78
+ end # def register
79
+
80
+ def lock_for_write
81
+ @write_lock.lock
82
+ begin
83
+ yield
84
+ ensure
85
+ @write_lock.unlock
86
+ end
87
+ end # def lock_for_write
88
+
89
+ def lock_for_read #ensuring only one thread updates the network block list
90
+ @read_lock.lock
91
+ begin
92
+ yield
93
+ ensure
94
+ @read_lock.unlock
95
+ end
96
+ end #def lock_for_read
97
+
98
+ def needs_refresh?
99
+ @next_refresh < Time.now
100
+ end # def needs_refresh
101
+
102
+ def load_file
103
+ begin
104
+ temporary = File.open(@value_path, "r") {|file| file.read.split(@separator)}
105
+ if !temporary.empty? #ensuring the file was parsed correctly
106
+ @value_set = temporary.to_set
107
+ else
108
+ @value_set = set
109
+ end
110
+ rescue
111
+ if @value_set #if the list was parsed successfully before
112
+ @logger.error("Error while opening/parsing the file")
113
+ else
114
+ raise LogStash::ConfigurationError, I18n.t(
115
+ "logstash.agent.configuration.invalid_plugin_register",
116
+ :plugin => "filter",
117
+ :type => "contains",
118
+ :error => "The file containing the network list is invalid, please check the separator character or permissions for the file."
119
+ )
120
+ end
121
+ end
122
+ end #def load_file
123
+
124
+ public
125
+ def filter(event)
126
+ field = @field.collect do |f|
127
+ begin
128
+ event.sprintf(f)
129
+ rescue ArgumentError => e
130
+ @logger.warn("Invalid field, skipping", :field => f, :event => event)
131
+ nil
132
+ end
133
+ end
134
+ field.compact!
135
+
136
+ if @value_path #in case we are getting values from an external file
137
+ if needs_refresh?
138
+ lock_for_write do
139
+ if needs_refresh?
140
+ load_file
141
+ @next_refresh = Time.now() + @refresh_interval
142
+ end
143
+ end #end lock
144
+ end #end refresh from file
145
+ end
146
+
147
+ field.each do |f|
148
+ @logger.debug("Checking value contains", :field => f, :value => @value_set)
149
+ if @value_set.member?(f)
150
+ filter_matched(event)
151
+ return
152
+ end
153
+ end
154
+ end # def filter
155
+ end # class LogStash::Filters::CONTAINS
@@ -0,0 +1,28 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'logstash-filter-contains'
4
+ s.version = '1.0.0'
5
+ s.platform = 'java'
6
+ s.licenses = ['Apache License (2.0)']
7
+ s.summary = "filter to check if value is contains"
8
+ 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"
9
+ s.authors = ["donghyeon kim"]
10
+ s.email = 'wjstk2650@gmail.com'
11
+ s.homepage = ""
12
+ s.require_paths = ["lib"]
13
+
14
+ # Files
15
+ s.files = Dir["lib/**/*","spec/**/*","*.gemspec","*.md","CONTRIBUTORS","Gemfile","LICENSE", "vendor/jar-dependencies/**/*.jar", "vendor/jar-dependencies/**/*.rb", "VERSION", "docs/**/*"]
16
+
17
+ # Tests
18
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
19
+
20
+ # Special flag to let us know this is actually a logstash plugin
21
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
22
+
23
+ # Gem dependencies
24
+ s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
25
+
26
+ s.add_development_dependency 'logstash-devutils'
27
+ end
28
+
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-contains
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: java
6
+ authors:
7
+ - donghyeon kim
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-11-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-core-plugin-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.60'
20
+ - - "<="
21
+ - !ruby/object:Gem::Version
22
+ version: '2.99'
23
+ type: :runtime
24
+ prerelease: false
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
+ name: logstash-devutils
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
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
48
+ Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
49
+ gem is not a stand-alone program
50
+ email: wjstk2650@gmail.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - CONTRIBUTORS
56
+ - Gemfile
57
+ - LICENSE
58
+ - README.md
59
+ - docs/index.asciidoc
60
+ - lib/logstash/filters/contains.rb
61
+ - logstash-filter-contains.gemspec
62
+ homepage: ''
63
+ licenses:
64
+ - Apache License (2.0)
65
+ metadata:
66
+ logstash_plugin: 'true'
67
+ logstash_group: filter
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.5.2
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: filter to check if value is contains
88
+ test_files: []