logstash-filter-duration 0.1.0

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: 16905a9ccb926147412043b68a11f0356846a19f
4
+ data.tar.gz: 9a916f0519f9000632d73e05aa7ad6881c10ccb4
5
+ SHA512:
6
+ metadata.gz: 4b7feb4a61c23d143471b431e218025c2aaaf8805714658f7d706f8a967a7bdb617a442a4a92b8d6a8083b707c4ec62a9f657bec60f88d12bfacb8c4fb27eedd
7
+ data.tar.gz: f4ca220a3b5138126cba08e6e1fdf44523282ecbce21402b003235caf833a2ec0a6bf54e45a042369ca0e741a6d6ba8a96b297e5c5827cd10116da4794133126
data/CHANGELOG.md ADDED
@@ -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
+
data/CONTRIBUTORS ADDED
@@ -0,0 +1,11 @@
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
+ * Pier-Hugues Pellerin (ph)
7
+
8
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
9
+ Logstash, and you aren't on the list above and want to be, please let us know
10
+ and we'll make sure you're here. Contributions from folks like you are what make
11
+ open source awesome.
data/DEVELOPER.md ADDED
@@ -0,0 +1,2 @@
1
+ # logstash-filter-example
2
+ Example filter plugin. This should help bootstrap your effort to write your own filter plugin!
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
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/NOTICE.TXT ADDED
@@ -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/).
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # Logstash Plugin
2
+
3
+ [![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-filter-example.svg)](https://travis-ci.org/logstash-plugins/logstash-filter-example)
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,47 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require "logstash/namespace"
4
+
5
+ class LogStash::Filters::Duration < LogStash::Filters::Base
6
+
7
+ config_name "duration"
8
+
9
+ config :iso, :validate => :string, :default => "", :required => true
10
+
11
+ public
12
+ def register
13
+ end # def register
14
+
15
+ public
16
+ def filter(event)
17
+ if @iso
18
+ value = event.get(@iso)
19
+ if not valid(value)
20
+ return event.set("duration", 0)
21
+ end
22
+ days = value[/([0-9]+)D/, 1].to_i
23
+ hours = value[/([0-9]+)H/, 1].to_i
24
+ minutes = value[/([0-9]+)M/, 1].to_i
25
+ seconds = value[/([0-9]+)S/, 1].to_i
26
+ duration = total_seconds(days, hours, minutes, seconds)
27
+ if value[/^-/]
28
+ duration *= -1
29
+ end
30
+
31
+ event.set("duration", duration)
32
+ end
33
+
34
+ filter_matched(event)
35
+ end # def filter
36
+
37
+ private
38
+ def total_seconds(days=0, hours=0, minutes=0, seconds=0)
39
+ seconds + 60 * (minutes + 60 * (hours + 24 * days))
40
+ end # def total_seconds
41
+
42
+ private
43
+ def valid(value)
44
+ value[/^(-)?(P([0-9]+D)+(T([0-9]+H)?([0-9]+M)?([0-9]+S)?([0-9]+MS)?)?$|P([0-9]+D)?(T([0-9]+H)?([0-9]+M)?([0-9]+S)?([0-9]+MS)?)+$)/]
45
+ end
46
+
47
+ end # class LogStash::Filters::Duration
@@ -0,0 +1,22 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-duration'
3
+ s.version = '0.1.0'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = "This filter parses duration in ISO format."
6
+ 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"
7
+ s.authors = ["Funkwerk AG"]
8
+ s.require_paths = ["lib"]
9
+ s.homepage = 'https://github.com/funkwerk/logstash-duration-filter/'
10
+
11
+ # Files
12
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
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", "~> 2.0"
21
+ s.add_development_dependency 'logstash-devutils'
22
+ end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require "logstash/filters/duration"
4
+
5
+ describe LogStash::Filters::Duration do
6
+ describe "Parse duration in ISO format" do
7
+ let(:config) do <<-CONFIG
8
+ filter {
9
+ duration {
10
+ iso => 'iso'
11
+ }
12
+ }
13
+ CONFIG
14
+ end
15
+
16
+ sample('iso' => "PT1H2M3S") do
17
+ expect(subject.get("duration")).to eq(total_seconds(days=0, hours=1, minutes=2, seconds=3))
18
+ end
19
+
20
+ sample('iso' => "PT1H2M3S1000MS") do
21
+ expect(subject.get("duration")).to eq(total_seconds(days=0, hours=1, minutes=2, seconds=3))
22
+ end
23
+
24
+ sample('iso' => "-PT1H2M3S") do
25
+ expect(subject.get("duration")).to eq(-total_seconds(days=0, hours=1, minutes=2, seconds=3))
26
+ end
27
+
28
+ sample('iso' => "P1D") do
29
+ expect(subject.get("duration")).to eq(total_seconds(days=1))
30
+ end
31
+
32
+ sample('iso' => "P1DT2H3M4S") do
33
+ expect(subject.get("duration")).to eq(total_seconds(days=1, hours=2, minutes=3, seconds=4))
34
+ end
35
+
36
+ sample('iso' => "P1M") do
37
+ expect(subject.get("duration")).to eq(total_seconds())
38
+ end
39
+
40
+ sample('iso' => "PT2M1H3S") do
41
+ expect(subject.get("duration")).to eq(total_seconds())
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+
4
+ def total_seconds(days=0, hours=0, minutes=0, seconds=0)
5
+ seconds + 60 * (minutes + 60 * (hours + 24 * days))
6
+ end # def total_seconds
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-duration
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Funkwerk AG
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-22 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: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: logstash-devutils
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: This gem is a Logstash plugin required to be installed on top of the
42
+ Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
43
+ gem is not a stand-alone program
44
+ email:
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - CHANGELOG.md
50
+ - CONTRIBUTORS
51
+ - DEVELOPER.md
52
+ - Gemfile
53
+ - LICENSE
54
+ - NOTICE.TXT
55
+ - README.md
56
+ - lib/logstash/filters/duration.rb
57
+ - logstash-filter-duration.gemspec
58
+ - spec/filters/duration_spec.rb
59
+ - spec/spec_helper.rb
60
+ homepage: https://github.com/funkwerk/logstash-duration-filter/
61
+ licenses:
62
+ - Apache License (2.0)
63
+ metadata:
64
+ logstash_plugin: 'true'
65
+ logstash_group: filter
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.2.2
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: This filter parses duration in ISO format.
86
+ test_files:
87
+ - spec/filters/duration_spec.rb
88
+ - spec/spec_helper.rb