logstash-filter-duration 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 185427ecadb15b4cf23a17e71f3375177735bbce
4
- data.tar.gz: c871c9ee0ff0b8061fb0fe893bd04f3556dc73b8
3
+ metadata.gz: ab55a4ea7b39341646e72f66d37652be2a9201c2
4
+ data.tar.gz: 7caa0ee795fa4aed277efc0ecef9db61975749aa
5
5
  SHA512:
6
- metadata.gz: 324a1f7c112cf4816771de866572d14267c561fc2303e45298031bb571908341a0fdcacb4207994f2ea459686f2d3e51dad3ac5ed37f78a9f005cf01f975a87e
7
- data.tar.gz: 53b93592e9d100bad34e9249a1f0f2a774d22c38d48517ff1c3b6f99ca31b2324aba87635c722e66ba4841309c67a736a1588523b4a587884c1ae126c1dbd4a7
6
+ metadata.gz: 8c834aade409026f1c7521afff4d8f1223cc75f655fee179e9f5183e84cfba1488609130ca8f76364165a7710472e12dd4b7723f894eabca3a12335a397db3b5
7
+ data.tar.gz: 3687f4919d6262d6b8f53961724e7702fe364c68c221ee79ca6412c5d185114c3d623aae47143d726cb38d1819b7ba4077042c0ac4d4173a00fce504f279b605
data/README.md CHANGED
@@ -1,98 +1,18 @@
1
- # Logstash Plugin
1
+ # Logstash Duration Filter
2
2
 
3
- [![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-filter-example.svg)](https://travis-ci.org/logstash-plugins/logstash-filter-example)
3
+ [![Travis Build Status](https://travis-ci.org/funkwerk/logstash-filter-duration.svg)](https://travis-ci.org/funkwerk/logstash-filter-duration)
4
4
 
5
5
  This is a plugin for [Logstash](https://github.com/elastic/logstash).
6
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.
7
+ ## Usage
8
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
9
  ```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
10
+ grok {
11
+ match => {'message' => 'delay=(?<delay>.*)'}
12
+ }
13
+ if [delay] {
14
+ duration {
15
+ iso => 'delay'
16
+ }
17
+ }
78
18
  ```
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.
@@ -1,47 +1,45 @@
1
1
  # encoding: utf-8
2
- require "logstash/filters/base"
3
- require "logstash/namespace"
2
+ require 'logstash/filters/base'
3
+ require 'logstash/namespace'
4
4
 
5
5
  class LogStash::Filters::Duration < LogStash::Filters::Base
6
6
 
7
- config_name "duration"
7
+ config_name 'duration'
8
8
 
9
- config :iso, :validate => :string, :default => "", :required => true
9
+ config :iso, :validate => :string, :default => '', :required => true
10
10
 
11
11
  public
12
12
  def register
13
- end # def register
13
+ end
14
14
 
15
15
  public
16
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
-
17
+ return unless @iso
18
+ event.set('duration', parse(event.get(@iso)))
34
19
  filter_matched(event)
35
- end # def filter
20
+ end
36
21
 
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
22
+ def parse(value)
23
+ match = match_pattern value
24
+ return 0 if match.nil?
25
+
26
+ duration = total_seconds(
27
+ match[:days].to_i,
28
+ match[:hours].to_i,
29
+ match[:minutes].to_i,
30
+ match[:seconds].to_i
31
+ )
32
+ duration = -duration if match[:negate] == '-'
33
+ duration
34
+ end
35
+
36
+ def match_pattern(value)
37
+ pattern = /^(?<negate>-)?P((?<days>\d+)D)?(T((?<hours>\d+)H)?((?<minutes>\d+)M)?((?<seconds>\d+)(.(?<milliseconds>\d+))?S)?)?$/
41
38
 
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)?)+$)/]
39
+ value.match pattern
45
40
  end
46
41
 
47
- end # class LogStash::Filters::Duration
42
+ def total_seconds(days, hours, minutes, seconds)
43
+ seconds + 60 * (minutes + 60 * (hours + 24 * days))
44
+ end
45
+ end
@@ -1,21 +1,14 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-filter-duration'
3
- s.version = '0.1.1'
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"]
3
+ s.version = '0.2.0'
4
+ s.licenses = ['Apache License 2.0']
5
+ s.summary = 'This filter parses ISO durations and converts it into seconds.'
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
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
10
+ s.files = Dir['lib/**/*', 'spec/**/*', '*.gemspec', '*.md', 'Gemfile']
14
11
  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
12
+ s.metadata = { 'logstash_plugin' => 'true', 'logstash_group' => 'filter' }
20
13
  s.add_development_dependency 'logstash-devutils'
21
14
  end
@@ -1,9 +1,9 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
- require "logstash/filters/duration"
3
+ require 'logstash/filters/duration'
4
4
 
5
5
  describe LogStash::Filters::Duration do
6
- describe "Parse duration in ISO format" do
6
+ describe 'Parse duration in ISO format' do
7
7
  let(:config) do <<-CONFIG
8
8
  filter {
9
9
  duration {
@@ -13,32 +13,32 @@ describe LogStash::Filters::Duration do
13
13
  CONFIG
14
14
  end
15
15
 
16
- sample('iso' => "PT1H2M3S") do
17
- expect(subject.get("duration")).to eq(total_seconds(days=0, hours=1, minutes=2, seconds=3))
16
+ sample('iso' => 'P1D') do
17
+ expect(subject.get('duration')).to eq(total_seconds(days: 1))
18
18
  end
19
19
 
20
- sample('iso' => "PT1H2M3S1000MS") do
21
- expect(subject.get("duration")).to eq(total_seconds(days=0, hours=1, minutes=2, seconds=3))
20
+ sample('iso' => 'PT1H') do
21
+ expect(subject.get('duration')).to eq(total_seconds(hours: 1))
22
22
  end
23
23
 
24
- sample('iso' => "-PT1H2M3S") do
25
- expect(subject.get("duration")).to eq(-total_seconds(days=0, hours=1, minutes=2, seconds=3))
24
+ sample('iso' => 'PT1M') do
25
+ expect(subject.get('duration')).to eq(total_seconds(minutes: 1))
26
26
  end
27
27
 
28
- sample('iso' => "P1D") do
29
- expect(subject.get("duration")).to eq(total_seconds(days=1))
28
+ sample('iso' => 'PT1S') do
29
+ expect(subject.get('duration')).to eq(total_seconds(seconds: 1))
30
30
  end
31
31
 
32
- sample('iso' => "P1DT2H3M4S") do
33
- expect(subject.get("duration")).to eq(total_seconds(days=1, hours=2, minutes=3, seconds=4))
32
+ sample('iso' => 'PT1.2S') do
33
+ expect(subject.get('duration')).to eq(total_seconds(seconds: 1))
34
34
  end
35
35
 
36
- sample('iso' => "P1M") do
37
- expect(subject.get("duration")).to eq(total_seconds())
36
+ sample('iso' => 'P1DT2H3M4S') do
37
+ expect(subject.get('duration')).to eq(total_seconds(days: 1, hours: 2, minutes: 3, seconds: 4))
38
38
  end
39
39
 
40
- sample('iso' => "PT2M1H3S") do
41
- expect(subject.get("duration")).to eq(total_seconds())
40
+ sample('iso' => '-P1DT2H3M4S') do
41
+ expect(subject.get('duration')).to eq(-total_seconds(days: 1, hours: 2, minutes: 3, seconds: 4))
42
42
  end
43
43
  end
44
44
  end
@@ -1,6 +1,11 @@
1
1
  # encoding: utf-8
2
2
  require "logstash/devutils/rspec/spec_helper"
3
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
4
+ def total_seconds(duration = {})
5
+ duration[:days] ||= 0
6
+ duration[:hours] ||= 0
7
+ duration[:minutes] ||= 0
8
+ duration[:seconds] ||= 0
9
+
10
+ duration[:seconds] + 60 * (duration[:minutes] + 60 * (duration[:hours] + 24 * duration[:days]))
11
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-duration
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Funkwerk AG
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-23 00:00:00.000000000 Z
11
+ date: 2016-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-devutils
@@ -32,12 +32,7 @@ executables: []
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
- - CHANGELOG.md
36
- - CONTRIBUTORS
37
- - DEVELOPER.md
38
35
  - Gemfile
39
- - LICENSE
40
- - NOTICE.TXT
41
36
  - README.md
42
37
  - lib/logstash/filters/duration.rb
43
38
  - logstash-filter-duration.gemspec
@@ -45,7 +40,7 @@ files:
45
40
  - spec/spec_helper.rb
46
41
  homepage: https://github.com/funkwerk/logstash-duration-filter/
47
42
  licenses:
48
- - Apache License (2.0)
43
+ - Apache License 2.0
49
44
  metadata:
50
45
  logstash_plugin: 'true'
51
46
  logstash_group: filter
@@ -68,7 +63,7 @@ rubyforge_project:
68
63
  rubygems_version: 2.2.2
69
64
  signing_key:
70
65
  specification_version: 4
71
- summary: This filter parses duration in ISO format.
66
+ summary: This filter parses ISO durations and converts it into seconds.
72
67
  test_files:
73
68
  - spec/filters/duration_spec.rb
74
69
  - spec/spec_helper.rb
@@ -1,5 +0,0 @@
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
-
@@ -1,11 +0,0 @@
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.
@@ -1,2 +0,0 @@
1
- # logstash-filter-example
2
- Example filter plugin. This should help bootstrap your effort to write your own filter plugin!
data/LICENSE DELETED
@@ -1,13 +0,0 @@
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 DELETED
@@ -1,5 +0,0 @@
1
- Elasticsearch
2
- Copyright 2012-2015 Elasticsearch
3
-
4
- This product includes software developed by The Apache Software
5
- Foundation (http://www.apache.org/).