logstash-filter-range 3.0.0-java

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: a85a9c8c75a462fa30ba0bb41b2013d5c49f2a0d
4
+ data.tar.gz: aa692005e83af7745461bb17212598bfd7fe4fc2
5
+ SHA512:
6
+ metadata.gz: fe599119d01d1a33e1342ca01741c6585c86145930743f1da24d83ec715a26c16c00a978c0739ea8addf4e4c7eb69fa1a12acc72497667f76485abc247a6928c
7
+ data.tar.gz: 39c70678585bdeef28b7a84753760a0e398d9722845d6a8e5a9028ce2c34756ea151971105a7172a97e99c329b5b7347b1c0253cd744697187bb107621e41ab0
@@ -0,0 +1,14 @@
1
+ ## 3.0.0
2
+ - breaking: Updated plugin to use new Java Event APIs
3
+
4
+ ## 2.0.4
5
+ - internal,deps: Depend on logstash-core-plugin-api instead of logstash-core, removing the need to mass update plugins on major releases of logstash
6
+
7
+ ## 2.0.3
8
+ - internal,deps: New dependency requirements for logstash-core for the 5.0 release
9
+
10
+ ## 2.0.0
11
+ - internal: Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
12
+ instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
13
+ - internal,deps: Dependency on logstash-core update to 2.0
14
+
@@ -0,0 +1,17 @@
1
+ The following is a list of people who have contributed ideas, code, bug
2
+ reports, or in general have helped logstash along its way.
3
+
4
+ Contributors:
5
+ * Aaron Mildenstein (untergeek)
6
+ * Danny Berger (dpb587)
7
+ * Jordan Sissel (jordansissel)
8
+ * Nick Ethier (nickethier)
9
+ * Pier-Hugues Pellerin (ph)
10
+ * Richard Pijnenburg (electrical)
11
+ * Suyog Rao (suyograo)
12
+ * piavlo
13
+
14
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
15
+ Logstash, and you aren't on the list above and want to be, please let us know
16
+ and we'll make sure you're here. Contributions from folks like you are what make
17
+ open source awesome.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
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,98 @@
1
+ # Logstash Plugin
2
+
3
+ [![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-filter-range.svg)](https://travis-ci.org/logstash-plugins/logstash-filter-range)
4
+
5
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
6
+
7
+ 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.
8
+
9
+ ## Documentation
10
+
11
+ 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/).
12
+
13
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
14
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
15
+
16
+ ## Need Help?
17
+
18
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
19
+
20
+ ## Developing
21
+
22
+ ### 1. Plugin Developement and Testing
23
+
24
+ #### Code
25
+ - To get started, you'll need JRuby with the Bundler gem installed.
26
+
27
+ - 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).
28
+
29
+ - Install dependencies
30
+ ```sh
31
+ bundle install
32
+ ```
33
+
34
+ #### Test
35
+
36
+ - Update your dependencies
37
+
38
+ ```sh
39
+ bundle install
40
+ ```
41
+
42
+ - Run tests
43
+
44
+ ```sh
45
+ bundle exec rspec
46
+ ```
47
+
48
+ ### 2. Running your unpublished Plugin in Logstash
49
+
50
+ #### 2.1 Run in a local Logstash clone
51
+
52
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
53
+ ```ruby
54
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
55
+ ```
56
+ - Install plugin
57
+ ```sh
58
+ # Logstash 2.3 and higher
59
+ bin/logstash-plugin install --no-verify
60
+
61
+ # Prior to Logstash 2.3
62
+ bin/plugin install --no-verify
63
+
64
+ ```
65
+ - Run Logstash with your plugin
66
+ ```sh
67
+ bin/logstash -e 'filter {awesome {}}'
68
+ ```
69
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
70
+
71
+ #### 2.2 Run in an installed Logstash
72
+
73
+ 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:
74
+
75
+ - Build your plugin gem
76
+ ```sh
77
+ gem build logstash-filter-awesome.gemspec
78
+ ```
79
+ - Install the plugin from the Logstash home
80
+ ```sh
81
+ # Logstash 2.3 and higher
82
+ bin/logstash-plugin install --no-verify
83
+
84
+ # Prior to Logstash 2.3
85
+ bin/plugin install --no-verify
86
+
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 the community 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,140 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require "logstash/namespace"
4
+
5
+
6
+ # This filter is used to check that certain fields are within expected size/length ranges.
7
+ # Supported types are numbers and strings.
8
+ # Numbers are checked to be within numeric value range.
9
+ # Strings are checked to be within string length range.
10
+ # More than one range can be specified for same fieldname, actions will be applied incrementally.
11
+ # When field value is within a specified range an action will be taken.
12
+ # Supported actions are drop event, add tag, or add field with specified value.
13
+ #
14
+ # Example use cases are for histogram-like tagging of events
15
+ # or for finding anomaly values in fields or too big events that should be dropped.
16
+
17
+ class LogStash::Filters::Range < LogStash::Filters::Base
18
+ config_name "range"
19
+
20
+ # An array of field, min, max, action tuples.
21
+ # Example:
22
+ # [source,ruby]
23
+ # filter {
24
+ # %PLUGIN% {
25
+ # ranges => [ "message", 0, 10, "tag:short",
26
+ # "message", 11, 100, "tag:medium",
27
+ # "message", 101, 1000, "tag:long",
28
+ # "message", 1001, 1e1000, "drop",
29
+ # "duration", 0, 100, "field:latency:fast",
30
+ # "duration", 101, 200, "field:latency:normal",
31
+ # "duration", 201, 1000, "field:latency:slow",
32
+ # "duration", 1001, 1e1000, "field:latency:outlier",
33
+ # "requests", 0, 10, "tag:too_few_%{host}_requests" ]
34
+ # }
35
+ # }
36
+ #
37
+ # Supported actions are drop tag or field with specified value.
38
+ # Added tag names and field names and field values can have `%{dynamic}` values.
39
+ #
40
+ config :ranges, :validate => :array, :default => []
41
+
42
+ # Negate the range match logic, events should be outsize of the specified range to match.
43
+ config :negate, :validate => :boolean, :default => false
44
+
45
+ public
46
+ def register
47
+ if @ranges.length % 4 != 0
48
+ raise "#{self.class.name}: ranges array should consist of 4 field tuples (field,min,max,action)"
49
+ end
50
+
51
+ @range_tuples = {}
52
+
53
+ while !@ranges.empty?
54
+ fieldname, min, max, action = @ranges.shift(4)
55
+
56
+ raise "#{self.class.name}: range field name value should be a string" if !fieldname.is_a?(String)
57
+ raise "#{self.class.name}: range min value should be a number" if !min.is_a?(Integer) and !min.is_a?(Float)
58
+ raise "#{self.class.name}: range max value should be a number" if !max.is_a?(Integer) and !max.is_a?(Float)
59
+ raise "#{self.class.name}: range action value should be a string" if !action.is_a?(String)
60
+
61
+ action = action.split(':')
62
+
63
+ case action.first
64
+ when "drop"
65
+ raise "#{self.class.name}: drop action does not accept any parameters" unless action.length == 1
66
+ action = { :name => :drop }
67
+ when "tag"
68
+ raise "#{self.class.name}: tag action accepts exactly one arg which is a tag name" unless action.length == 2
69
+ action = { :name => :add_tag, :tag => action.last }
70
+ when "field"
71
+ raise "#{self.class.name}: field action accepts exactly 2 args which are a field name and field value" unless action.length == 3
72
+ if action.last == action.last.to_i.to_s
73
+ value = action.last.to_i
74
+ elsif action.last == action.last.to_f.to_s
75
+ value = action.last.to_f
76
+ else
77
+ value = action.last
78
+ end
79
+ action = { :name => :add_field, :field => action[1], :value => value }
80
+ else
81
+ raise "#{self.class.name}: unsupported action #{action}"
82
+ end
83
+
84
+ @range_tuples[fieldname] ||= []
85
+ @range_tuples[fieldname] << { :min => min, :max => max, :action => action }
86
+ end
87
+ end # def register
88
+
89
+
90
+ public
91
+ def filter(event)
92
+
93
+
94
+ @range_tuples.each_key do |fieldname|
95
+ if event.include?(fieldname)
96
+ @range_tuples[fieldname].each do |range|
97
+ matched = false
98
+
99
+ field = event.get(fieldname)
100
+ case field
101
+ when Integer
102
+ matched = field.between?(range[:min], range[:max])
103
+ when Float
104
+ matched = field.between?(range[:min], range[:max])
105
+ when String
106
+ matched = field.length.between?(range[:min], range[:max])
107
+ else
108
+ @logger.warn("#{self.class.name}: action field value has unsupported type")
109
+ end
110
+
111
+ matched = !matched if @negate
112
+ next unless matched
113
+
114
+ case range[:action][:name]
115
+ when :drop
116
+ @logger.debug? and @logger.debug("#{self.class.name}: dropping event due to range match", :event => event)
117
+ event.cancel
118
+ return
119
+ when :add_tag
120
+ @logger.debug? and @logger.debug("#{self.class.name}: adding tag due to range match",
121
+ :event => event, :tag => range[:action][:tag] )
122
+ event.tag(event.sprintf(range[:action][:tag]))
123
+ when :add_field
124
+ @logger.debug? and @logger.debug("#{self.class.name}: adding field due to range match",
125
+ :event => event, :field => range[:action][:field], :value => range[:action][:value])
126
+ new_field = event.sprintf(range[:action][:field])
127
+ if event.get(new_field)
128
+ event.set(new_field, [event.get(new_field)]) if !event.get(new_field).is_a?(Array)
129
+ event.set(new_field, event.get(new_field) << event.sprintf(range[:action][:value]))
130
+ else
131
+ event.set(new_field, range[:action][:value].is_a?(String) ? event.sprintf(range[:action][:value]) : range[:action][:value])
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
137
+
138
+ filter_matched(event)
139
+ end # def filter
140
+ end # class LogStash::Filters::Range
@@ -0,0 +1,28 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'logstash-filter-range'
4
+ s.version = '3.0.0'
5
+ s.platform = 'java'
6
+ s.licenses = ['Apache License (2.0)']
7
+ s.summary = "This filter is used to check that certain fields are within expected size/length ranges."
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 = ["Elastic"]
10
+ s.email = 'info@elastic.co'
11
+ s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
12
+ s.require_paths = ["lib"]
13
+
14
+ # Files
15
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
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
+
@@ -0,0 +1,169 @@
1
+ require "logstash/devutils/rspec/spec_helper"
2
+ require "logstash/filters/range"
3
+
4
+ describe LogStash::Filters::Range do
5
+
6
+
7
+ describe "range match integer field on tag action" do
8
+ config <<-CONFIG
9
+ filter {
10
+ range {
11
+ ranges => [ "duration", 10, 100, "tag:cool",
12
+ "duration", 1, 1, "tag:boring" ]
13
+ }
14
+ }
15
+ CONFIG
16
+
17
+ sample("duration" => 50) do
18
+ insist { subject.get("tags") }.include?("cool")
19
+ reject { subject.get("tags") }.include?("boring")
20
+ end
21
+ end
22
+
23
+ describe "range match float field on tag action" do
24
+ config <<-CONFIG
25
+ filter {
26
+ range {
27
+ ranges => [ "duration", 0, 100, "tag:cool",
28
+ "duration", 0, 1, "tag:boring" ]
29
+ }
30
+ }
31
+ CONFIG
32
+
33
+ sample("duration" => 50.0) do
34
+ insist { subject.get("tags") }.include?("cool")
35
+ reject { subject.get("tags") }.include?("boring")
36
+ end
37
+ end
38
+
39
+ describe "range match string field on tag action" do
40
+ config <<-CONFIG
41
+ filter {
42
+ range {
43
+ ranges => [ "length", 0, 10, "tag:cool",
44
+ "length", 0, 1, "tag:boring" ]
45
+ }
46
+ }
47
+ CONFIG
48
+
49
+ sample("length" => "123456789") do
50
+ insist { subject.get("tags") }.include?("cool")
51
+ reject { subject.get("tags") }.include?("boring")
52
+ end
53
+ end
54
+
55
+ describe "range match with negation" do
56
+ config <<-CONFIG
57
+ filter {
58
+ range {
59
+ ranges => [ "length", 0, 10, "tag:cool",
60
+ "length", 0, 1, "tag:boring" ]
61
+ negate => true
62
+ }
63
+ }
64
+ CONFIG
65
+
66
+ sample("length" => "123456789") do
67
+ reject { subject.get("tags") }.include?("cool")
68
+ insist { subject.get("tags") }.include?("boring")
69
+ end
70
+ end
71
+
72
+ describe "range match on drop action" do
73
+ config <<-CONFIG
74
+ filter {
75
+ range {
76
+ ranges => [ "length", 0, 10, "drop" ]
77
+ }
78
+ }
79
+ CONFIG
80
+
81
+ sample("length" => "123456789") do
82
+ insist { subject }.nil?
83
+ end
84
+ end
85
+
86
+ describe "range match on field action with string value" do
87
+ config <<-CONFIG
88
+ filter {
89
+ range {
90
+ ranges => [ "duration", 10, 100, "field:cool:foo",
91
+ "duration", 1, 1, "field:boring:foo" ]
92
+ }
93
+ }
94
+ CONFIG
95
+
96
+ sample("duration" => 50) do
97
+ insist { subject }.include?("cool")
98
+ insist { subject.get("cool") } == "foo"
99
+ reject { subject }.include?("boring")
100
+ end
101
+ end
102
+
103
+ describe "range match on field action with integer value" do
104
+ config <<-CONFIG
105
+ filter {
106
+ range {
107
+ ranges => [ "duration", 10, 100, "field:cool:666",
108
+ "duration", 1, 1, "field:boring:666" ]
109
+ }
110
+ }
111
+ CONFIG
112
+
113
+ sample("duration" => 50) do
114
+ insist { subject }.include?("cool")
115
+ insist { subject.get("cool") } == 666
116
+ reject { subject }.include?("boring")
117
+ end
118
+ end
119
+
120
+ describe "range match on field action with float value" do
121
+ config <<-CONFIG
122
+ filter {
123
+ range {
124
+ ranges => [ "duration", 10, 100, "field:cool:3.14",
125
+ "duration", 1, 1, "field:boring:3.14" ]
126
+ }
127
+ }
128
+ CONFIG
129
+
130
+ sample("duration" => 50) do
131
+ insist { subject }.include?("cool")
132
+ insist { subject.get("cool") } == 3.14
133
+ reject { subject }.include?("boring")
134
+ end
135
+ end
136
+
137
+ describe "range match on tag action with dynamic string value" do
138
+ config <<-CONFIG
139
+ filter {
140
+ range {
141
+ ranges => [ "duration", 10, 100, "tag:cool_%{dynamic}_dynamic",
142
+ "duration", 1, 1, "tag:boring_%{dynamic}_dynamic" ]
143
+ }
144
+ }
145
+ CONFIG
146
+
147
+ sample("duration" => 50, "dynamic" => "and") do
148
+ insist { subject.get("tags") }.include?("cool_and_dynamic")
149
+ reject { subject.get("tags") }.include?("boring_and_dynamic")
150
+ end
151
+ end
152
+
153
+ describe "range match on field action with dynamic string field and value" do
154
+ config <<-CONFIG
155
+ filter {
156
+ range {
157
+ ranges => [ "duration", 10, 100, "field:cool_%{dynamic}_dynamic:foo_%{dynamic}_bar",
158
+ "duration", 1, 1, "field:boring_%{dynamic}_dynamic:foo_%{dynamic}_bar" ]
159
+ }
160
+ }
161
+ CONFIG
162
+
163
+ sample("duration" => 50, "dynamic" => "and") do
164
+ insist { subject }.include?("cool_and_dynamic")
165
+ insist { subject.get("cool_and_dynamic") } == "foo_and_bar"
166
+ reject { subject }.include?("boring_and_dynamic")
167
+ end
168
+ end
169
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-range
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
5
+ platform: java
6
+ authors:
7
+ - Elastic
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-08 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
+ - CONTRIBUTORS
55
+ - Gemfile
56
+ - LICENSE
57
+ - NOTICE.TXT
58
+ - README.md
59
+ - lib/logstash/filters/range.rb
60
+ - logstash-filter-range.gemspec
61
+ - spec/filters/range_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: 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.4.8
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: This filter is used to check that certain fields are within expected size/length ranges.
88
+ test_files:
89
+ - spec/filters/range_spec.rb