logstash-filter-dateparts 2.2-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: 53d8f553407a492ff6bf37d272462d8220099191
4
+ data.tar.gz: 60fbf0d9c3bb24eaecf5fb85e18bc7777f0c45b1
5
+ SHA512:
6
+ metadata.gz: 526e61252008b1d2c490246af41ec537609431ec06a5f7b0d18053218713930870dd89f5c8819f88e0661175a3f8ccfba95fc4174c0e883d46f7b803f6a21cc1
7
+ data.tar.gz: 243c275861bda07cde358e4a12e1b9daa9cb2526fb48ef17b38eec34860695618ce98994bc5f3b69906aaeed0d4a192377aff001c4bcf72cbc7ab84c72d9a122
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # 2.2
2
+ - Changes for new logstash devel gem
3
+ - Make updates for travis ci to fix https://github.com/mikebski/logstash-filter-datepart/issues/5
4
+
5
+ # 2.1.1
6
+ - Added support for caluclating a duration - https://github.com/mikebski/logstash-filter-datepart/issues/4
7
+ - Added support for DateTime and other objects with a to_date method
8
+ - Added TravisCI build hook
9
+
10
+ # 2.0.1
11
+ - Removed extraneous output statement from
12
+ https://github.com/mikebski/logstash-filter-datepart/issues/3
13
+
14
+ # 2.0.0
15
+ - Breaking: Updated plugin to use new Java Event APIs
16
+
17
+ # 1.0.1
18
+ - Updated dependencies to avoid being tied to Logstash major release.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+ gem "codeclimate-test-reporter", group: :test, require: nil
4
+
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2014–2016 Mike Baranski <http://www.mikeski.net>
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,140 @@
1
+ # Logstash Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
+
5
+ The source for this plugin can be [found here on github](https://github.com/mikebski/logstash-datepart-plugin.git)
6
+
7
+ Author: Mike Baranski (mike.baranski@gmail.com). Contributions are welcome.
8
+
9
+ [![Gem Version](https://badge.fury.io/rb/logstash-filter-dateparts.svg)](https://badge.fury.io/rb/logstash-filter-dateparts)
10
+ [![Build Status](https://travis-ci.org/mikebski/logstash-filter-datepart.svg?branch=master)](https://travis-ci.org/mikebski/logstash-filter-datepart)
11
+ [![Test Coverage](https://codeclimate.com/github/mikebski/logstash-filter-datepart/badges/coverage.svg?reload=1)](https://codeclimate.com/github/mikebski/logstash-filter-datepart/coverage)
12
+ [![Code Climate](https://codeclimate.com/github/mikebski/logstash-filter-datepart/badges/gpa.svg?reload=1)](https://codeclimate.com/github/mikebski/logstash-filter-datepart)
13
+ [![Issue Count](https://codeclimate.com/github/mikebski/logstash-filter-datepart/badges/issue_count.svg?reload=1)](https://codeclimate.com/github/mikebski/logstash-filter-datepart)
14
+
15
+ ## License ##
16
+
17
+ Copyright (c) 2014–2016 Mike Baranski <http://www.mikeski.net>
18
+
19
+ Licensed under the Apache License, Version 2.0 (the "License");
20
+ you may not use this file except in compliance with the License.
21
+ You may obtain a copy of the License at
22
+
23
+ http://www.apache.org/licenses/LICENSE-2.0
24
+
25
+ Unless required by applicable law or agreed to in writing, software
26
+ distributed under the License is distributed on an "AS IS" BASIS,
27
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
+ See the License for the specific language governing permissions and
29
+ limitations under the License.
30
+
31
+ ## About
32
+
33
+ This plugin is useful if you want to easily query Logstash data on *day of week*, *hour of day*, or other parts of a date. See the usage below for details on the output of the plugin. The date parts that can be generated are:
34
+
35
+ * day
36
+ * wday
37
+ * mday
38
+ * yday
39
+ * month
40
+ * year
41
+ * hour
42
+ * min
43
+ * sec
44
+
45
+ ## Documentation
46
+
47
+ ### Installation
48
+
49
+ To manually install the plugin, download the gem and run:
50
+
51
+ `bin/plugin install --no-verify logstash-filter-dateparts-1.0.0.gem`
52
+
53
+ ### Usage
54
+
55
+ To see the most basic usage, you can run the following (on Linux):
56
+
57
+ `echo "HI" | bin/logstash -e 'input { stdin {} } filter {dateparts { }} output { stdout { codec=> rubydebug}}'`
58
+
59
+ You could also use the logstash generator:
60
+
61
+ `bin/logstash -e 'input { generator { lines => ["HI"] count => 1 } } filter {dateparts { }} output { stdout { codec=> rubydebug}}'`
62
+
63
+ Here is the sample output:
64
+
65
+ {
66
+ "message" => "HI",
67
+ "@version" => "1",
68
+ "@timestamp" => "2015-11-20T12:24:40.217Z",
69
+ "host" => "mike-VirtualBox",
70
+ "day" => 20,
71
+ "wday" => 5,
72
+ "yday" => 324,
73
+ "month" => 11,
74
+ "year" => 2015,
75
+ "hour" => 12,
76
+ "min" => 24,
77
+ "sec" => 40
78
+ }
79
+
80
+
81
+ This uses the default configuration, which generates the following fields from the `@timestamp` field of the event:
82
+
83
+ * day
84
+ * wday
85
+ * yday
86
+ * month
87
+ * year
88
+ * hour
89
+ * min
90
+ * sec
91
+
92
+ ### Configuration
93
+
94
+ #### Fields
95
+
96
+ The generated fields are based on the date functions available in the [Ruby time class](http://ruby-doc.org/core-2.2.0/Time.html). You can specify any valid function and it will be added to the event.
97
+
98
+ For example, this will add 2 fields, *sec* corresponding to `time.sec()` and *hour* corresponding to `time.hour()`:
99
+
100
+ filter {
101
+ dateparts {
102
+ "fields" => ["sec", "hour"]
103
+ }
104
+ }
105
+
106
+ #### Time Field
107
+
108
+ By default, the plugin will use the *@timestamp* field, but you can specify a different one:
109
+
110
+ filter {
111
+ dateparts {
112
+ "time_field" => "some_other_field"
113
+ }
114
+ }
115
+
116
+ #### Duration Field (new in 2.1)
117
+
118
+ 2.1 provides the ability to calculate a duration (in seconds.milliseconds) based on 2 field.s
119
+ The value of the duration is a float with millisecond precision.
120
+
121
+ The input values must both be time values, and you specify an output field for the result
122
+
123
+ filter {
124
+ 'fields' => %w(mday),
125
+ 'duration' => {
126
+ 'start_field' => 'tstart',
127
+ 'end_field' => 'tend',
128
+ 'result_field' => 'duration'
129
+ }
130
+ }
131
+
132
+ #### Error Tags
133
+
134
+ By default, the tag *_dateparts_error* is added on exception. You can specify different tag(s) like so:
135
+
136
+ filter {
137
+ dateparts {
138
+ "error_tags" => ["bad_dates", "xyz"]
139
+ }
140
+ }
@@ -0,0 +1,99 @@
1
+ # encoding: utf-8
2
+ # Copyright (c) 2014–2016 Mike Baranski <http://www.mikeski.net>
3
+
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # encoding: utf-8
17
+ require 'logstash/filters/base'
18
+ require 'logstash/namespace'
19
+
20
+ # This filter will add date parts to your record based on
21
+ # the timestamp field.
22
+ #
23
+ class LogStash::Filters::DateParts < LogStash::Filters::Base
24
+ # Setting the config_name here is required. This is how you
25
+ # configure this filter from your Logstash config.
26
+ #
27
+ # filter {
28
+ # dateparts {
29
+ #
30
+ # }
31
+ # }
32
+ #
33
+ config_name 'dateparts'
34
+ config :fields, :validate => :array, :default => %w(day wday yday mday month year hour min sec), :required => true
35
+ config :time_field, :validate => :string, :default => '@timestamp', :required => true
36
+ config :error_tags, :validate => :array, :default => ['_dateparts_error'], :required => true
37
+ config :duration, :validate => :hash, :required => false
38
+
39
+ def register
40
+ logger.debug? and logger.debug('DateParts filter registered')
41
+ end
42
+
43
+ def plugin_error(message, event)
44
+ logger.error("DatePart filter error: #{message}")
45
+ LogStash::Util::Decorators.add_tags(@error_tags, event, "filters/#{self.class.name}")
46
+ end
47
+
48
+ def get_time_from_field(f)
49
+ if f.class == Time
50
+ f
51
+ elsif f.respond_to?('time')
52
+ f.time
53
+ elsif f.respond_to?('to_time')
54
+ f.to_time
55
+ else
56
+ nil
57
+ end
58
+ end
59
+
60
+ def get_hash_value(hash, key, default)
61
+ if (hash[key] == nil)
62
+ default
63
+ else
64
+ hash[key]
65
+ end
66
+ end
67
+
68
+ def filter(event)
69
+ event_time = get_time_from_field(event.get(@time_field))
70
+ if event_time == nil
71
+ plugin_error("Invalid time field #{@time_field}; Time field must be an instance of Time or provide a time method that returns one", event)
72
+ return
73
+ end
74
+ logger.debug? and logger.debug("DateParts plugin filtering #{@time_field} time_field and adding fields: " + @fields.join(', '))
75
+ @fields.each do |field|
76
+ begin
77
+ event.set(field, event_time.send(field))
78
+ rescue
79
+ plugin_error("No such method: #{field}\n", event)
80
+ end
81
+ end
82
+ if @duration != nil
83
+ start_time = get_time_from_field(event.get(get_hash_value(@duration, 'start_field', '@timestamp')))
84
+ end_time = get_time_from_field(event.get(get_hash_value(@duration, 'end_field', '@timestamp')))
85
+
86
+ begin
87
+ result_field = get_hash_value(@duration, 'result_field', 'duration_result')
88
+ duration = end_time - start_time
89
+ event.set(result_field, duration)
90
+ rescue
91
+ plugin_error('Invalid start or end for duration. Time fields must be an instance of Time or provide a time method that returns one', event)
92
+ return
93
+ end
94
+ end
95
+
96
+ filter_matched(event)
97
+ end # def filter
98
+
99
+ end # class LogStash::Filters::DateParts
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ # Copyright (c) 2014–2016 Mike Baranski <http://www.mikeski.net>
4
+
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ Gem::Specification.new do |s|
18
+ s.name = 'logstash-filter-dateparts'
19
+ s.version = '2.2'
20
+ s.licenses = ['Apache License (2.0)']
21
+ s.summary = 'This dateparts fileter adds date information to your event based on your timestamp'
22
+ s.description = 'This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program'
23
+ s.authors = ['Mike Baranski']
24
+ s.email = 'ike.baranski@gmail.com'
25
+ s.homepage = 'http://mikeski.net'
26
+ s.require_paths = ['lib']
27
+ s.platform = "java"
28
+
29
+ # Files
30
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','Gemfile','LICENSE']
31
+ # Tests
32
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
33
+
34
+ # Special flag to let us know this is actually a logstash plugin
35
+ s.metadata = { 'logstash_plugin' => 'true', 'logstash_group' => 'filter' }
36
+
37
+ # Gem dependencies
38
+ s.add_runtime_dependency 'logstash-core-plugin-api', '>= 1.60', '<= 2.99'
39
+
40
+ s.add_development_dependency 'jar-dependencies', '0.3.5'
41
+
42
+ s.add_development_dependency 'ruby-maven', '~> 3.3'
43
+
44
+ s.add_development_dependency 'logstash-devutils'
45
+ end
@@ -0,0 +1,295 @@
1
+ # coding: utf-8
2
+ # Copyright (c) 2014–2016 Mike Baranski <http://www.mikeski.net>
3
+
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require 'spec_helper'
17
+ require 'logstash/logging/logger'
18
+ require 'logstash/filters/dateparts'
19
+ require 'logstash/timestamp'
20
+ require 'logstash/event'
21
+
22
+ def get_event(contents = {})
23
+ contents['@timestamp'] = LogStash::Timestamp.new
24
+ LogStash::Event.new(contents)
25
+ end
26
+
27
+ describe LogStash::Filters::DateParts do
28
+ default_ts = '@timestamp'
29
+ alt_ts_field = 'zxlk'
30
+
31
+ it 'Get time from field should work with Time' do
32
+ f = LogStash::Filters::DateParts.new({})
33
+ field_to_test = Time.new
34
+ val = f.get_time_from_field(field_to_test);
35
+ expect(val.class).to be(Time)
36
+ end
37
+
38
+ it 'Get time from field should work with DateTime' do
39
+ f = LogStash::Filters::DateParts.new({})
40
+ field_to_test = DateTime.new
41
+ val = f.get_time_from_field(field_to_test);
42
+ expect(val.class).to be(Time)
43
+ end
44
+
45
+ it 'Default config should result in filter with 8 functions, one error tag and @timestamp as the time field' do
46
+ f = LogStash::Filters::DateParts.new({})
47
+
48
+ expect(f.class).to eq(LogStash::Filters::DateParts)
49
+ expect(f.fields.length).to eq(9)
50
+ expect(f.time_field).to eq(default_ts)
51
+ expect(f.error_tags.length).to eq(1)
52
+ end
53
+
54
+ it 'Config should result in filter with 2 functions and the alt timestamp field' do
55
+ f = LogStash::Filters::DateParts.new({
56
+ 'fields' => %w(sec hour),
57
+ 'time_field' => alt_ts_field
58
+ })
59
+
60
+ expect(f.class).to eq(LogStash::Filters::DateParts)
61
+ expect(f.fields.length).to eq(2)
62
+ expect(f.fields[0]).to eq('sec')
63
+ expect(f.time_field).to eq(alt_ts_field)
64
+ end
65
+
66
+ it 'Should generate the default fields (8 of them)' do
67
+ event = get_event
68
+ count = event.to_hash.count
69
+ f = LogStash::Filters::DateParts.new({})
70
+ f.filter(event)
71
+
72
+ #puts(event.to_hash)
73
+ expect(event.to_hash.count).to eq(count + 10)
74
+ expect(event.get('sec')).to be_truthy
75
+ expect(event.get('hour')).to be_truthy
76
+ expect(event.get('min')).to be_truthy
77
+ expect(event.get('month')).to be_truthy
78
+ expect(event.get('year')).to be_truthy
79
+ expect(event.get('day')).to be_truthy
80
+ expect(event.get('wday')).to be_truthy
81
+ expect(event.get('mday')).to be_truthy
82
+ expect(event.get('yday')).to be_truthy
83
+ #expect(event.get('tags')).to be_falsy
84
+ end
85
+
86
+ it 'Should generate only the specified fields' do
87
+ event = get_event
88
+ count = event.to_hash.count
89
+ f = LogStash::Filters::DateParts.new({
90
+ 'fields' => %w(sec hour)
91
+ })
92
+ f.filter(event)
93
+ expect(event.to_hash.count).to eq(count + 3)
94
+ expect(event.get('sec')).to be_truthy
95
+ expect(event.get('hour')).to be_truthy
96
+ expect(event.get('min')).to be_nil
97
+ expect(event.get('month')).to be_nil
98
+ expect(event.get('year')).to be_nil
99
+ expect(event.get('day')).to be_nil
100
+ expect(event.get('wday')).to be_nil
101
+ expect(event.get('mday')).to be_nil
102
+ expect(event.get('yday')).to be_nil
103
+ #expect(event.get('tags')).to be_falsy
104
+ end
105
+
106
+ it 'Should set the error tag on an invalid time field' do
107
+ event = get_event
108
+ f = LogStash::Filters::DateParts.new({'time_field' => alt_ts_field})
109
+
110
+ f.filter(event)
111
+ expect(event.get('tags').include? '_dateparts_error').to eq(true)
112
+ end
113
+
114
+ it 'Should bail on an invalid date part' do
115
+ event = get_event
116
+ f = LogStash::Filters::DateParts.new({
117
+ 'fields' => %w(seczzz zzhour)
118
+ })
119
+ f.filter(event)
120
+ expect(event.get('tags').include? '_dateparts_error').to eq(true)
121
+ end
122
+
123
+ it 'Should calculate a duration' do
124
+ event = get_event
125
+ f = LogStash::Filters::DateParts.new({
126
+ 'duration' => {
127
+ 'start_field' => '@timestamp',
128
+ 'end_field' => 'sometime',
129
+ 'result_field' => 'duration'
130
+ }
131
+ })
132
+ event.set('sometime', Time.new)
133
+ f.filter(event)
134
+ #expect(event.get('tags')).to be_falsy
135
+ expect(event.get('duration')).to be > 0
136
+ end
137
+
138
+ it 'Should calculate a duration using 2 fields' do
139
+ event = get_event
140
+ f = LogStash::Filters::DateParts.new({
141
+ 'duration' => {
142
+ 'start_field' => 'tstart',
143
+ 'end_field' => 'tend',
144
+ 'result_field' => 'duration'
145
+ }
146
+ })
147
+ event.set('tstart', DateTime.new(2016, 1, 1, 12, 0, 0).to_time)
148
+ event.set('tend', DateTime.new(2016, 1, 1, 12, 0, 0).to_time)
149
+ f.filter(event)
150
+ #expect(event.get('tags')).to be_falsy
151
+ expect(event.get('duration')).to eq(0.0)
152
+ end
153
+
154
+ it 'Should calculate a duration of 1 second using 2 fields' do
155
+ event = get_event
156
+ f = LogStash::Filters::DateParts.new({
157
+ 'duration' => {
158
+ 'start_field' => 'tstart',
159
+ 'end_field' => 'tend',
160
+ 'result_field' => 'duration'
161
+ }
162
+ })
163
+
164
+ event.set('tstart', DateTime.new(2016, 1, 1, 23, 0, 0).to_time)
165
+ event.set('tend', DateTime.new(2016, 1, 1, 23, 0, 1).to_time)
166
+ f.filter(event)
167
+ #expect(event.get('tags')).to be_falsy
168
+ expect(event.get('duration')).to eq(1.0)
169
+ end
170
+
171
+ it 'Should calculate a duration of 3600 seconds using 2 fields and calculate datepart' do
172
+ event = get_event
173
+ f = LogStash::Filters::DateParts.new({
174
+ #'fields' => %w(mday),
175
+ 'duration' => {
176
+ 'start_field' => 'tstart',
177
+ 'end_field' => 'tend',
178
+ 'result_field' => 'duration'
179
+ }
180
+ })
181
+
182
+ event.set('tstart', DateTime.new(2016, 1, 1, 20, 0, 0).to_time)
183
+ event.set('tend', DateTime.new(2016, 1, 1, 21, 0, 0).to_time)
184
+ f.filter(event)
185
+ #expect(event.get('tags')).to be_falsy
186
+ expect(event.get('duration')).to eq(3600.0)
187
+ expect(event.get('mday')).to be > -1
188
+
189
+ end
190
+
191
+ it 'Should warn and return 0.0 if start and end are the same field' do
192
+ event = get_event
193
+ f = LogStash::Filters::DateParts.new({
194
+ 'duration' => {
195
+ 'start_field' => 'tstart',
196
+ 'end_field' => 'tstart',
197
+ 'result_field' => 'duration'
198
+ }
199
+ })
200
+
201
+ event.set('tstart', DateTime.new(2016, 1, 1, 20, 0, 0).to_time)
202
+ f.filter(event)
203
+ #expect(event.get('tags')).to be_falsy
204
+ expect(event.get('duration')).to eq(0.0)
205
+ expect(event.get('mday')).to be > -1
206
+ end
207
+
208
+ it 'Should return an error on nil start time' do
209
+ event = get_event
210
+ f = LogStash::Filters::DateParts.new({
211
+ 'duration' => {
212
+ 'start_field' => 'tstart',
213
+ 'end_field' => 'tend',
214
+ 'result_field' => 'duration'
215
+ }
216
+ })
217
+
218
+ event.set('tstart', nil)
219
+ event.set('tend', DateTime.new(2016, 1, 1, 23, 0, 1).to_time)
220
+ f.filter(event)
221
+ expect(event.get('tags').include? '_dateparts_error').to eq(true)
222
+ end
223
+
224
+ it 'Should return an error on nil end time' do
225
+ event = get_event
226
+ f = LogStash::Filters::DateParts.new({
227
+ 'duration' => {
228
+ 'start_field' => 'tstart',
229
+ 'end_field' => 'tend',
230
+ 'result_field' => 'duration'
231
+ }
232
+ })
233
+
234
+ event.set('tstart', DateTime.new(2016, 1, 1, 23, 0, 1).to_time)
235
+ event.set('tend', nil)
236
+ f.filter(event)
237
+ expect(event.get('tags').include? '_dateparts_error').to eq(true)
238
+ end
239
+
240
+ it 'Should use duration_result as the result field if it is not set' do
241
+ event = get_event
242
+ f = LogStash::Filters::DateParts.new({
243
+ 'duration' => {
244
+ 'start_field' => 'tstart',
245
+ 'end_field' => 'tend',
246
+ }
247
+ })
248
+
249
+ event.set('tstart', DateTime.new(2016, 1, 1, 23, 0, 0).to_time)
250
+ event.set('tend', DateTime.new(2016, 1, 1, 23, 0, 1).to_time)
251
+ f.filter(event)
252
+ #expect(event.get('tags')).to be_falsy
253
+ expect(event.get('duration_result')).to eq(1.0)
254
+ end
255
+
256
+ it 'Should hit debugging statement' do
257
+ event = get_event
258
+ f = LogStash::Filters::DateParts.new({
259
+ 'duration' => {
260
+ 'start_field' => 'tstart',
261
+ 'end_field' => 'tend',
262
+ }
263
+ })
264
+ #f.logger.setLevel(Level.valueOf('DEBUG'))
265
+ event.set('tstart', DateTime.new(2016, 1, 1, 23, 0, 0).to_time)
266
+ event.set('tend', DateTime.new(2016, 1, 1, 23, 0, 1).to_time)
267
+ f.filter(event)
268
+ #expect(event.get('tags')).to be_falsy
269
+ expect(event.get('duration_result')).to eq(1.0)
270
+ end
271
+
272
+ it 'Should return value from hash' do
273
+ f = LogStash::Filters::DateParts.new({
274
+ 'duration' => {
275
+ 'start_field' => 'tstart',
276
+ 'end_field' => 'tend',
277
+ }
278
+ })
279
+ test_hash = {'val_name' => 1}
280
+ val = f.get_hash_value(test_hash, 'val_name', 'blah');
281
+ expect(val).to eq(1)
282
+ end
283
+
284
+ it 'Should return default value from hash' do
285
+ f = LogStash::Filters::DateParts.new({
286
+ 'duration' => {
287
+ 'start_field' => 'tstart',
288
+ 'end_field' => 'tend',
289
+ }
290
+ })
291
+ test_hash = {'val_name' => 1}
292
+ val = f.get_hash_value(test_hash, 'xyza', 2);
293
+ expect(val).to eq(2)
294
+ end
295
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ # Copyright (c) 2014–2016 Mike Baranski <http://www.mikeski.net>
3
+
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # Fix for CC 1.0 per notes at:
17
+ # https://github.com/codeclimate/ruby-test-reporter/blob/master/CHANGELOG.md#v100-2016-11-03
18
+ require 'simplecov'
19
+ SimpleCov.start
20
+
21
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-dateparts
3
+ version: !ruby/object:Gem::Version
4
+ version: '2.2'
5
+ platform: java
6
+ authors:
7
+ - Mike Baranski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-17 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: jar-dependencies
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '='
38
+ - !ruby/object:Gem::Version
39
+ version: 0.3.5
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '='
45
+ - !ruby/object:Gem::Version
46
+ version: 0.3.5
47
+ - !ruby/object:Gem::Dependency
48
+ name: ruby-maven
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: '3.3'
61
+ - !ruby/object:Gem::Dependency
62
+ name: logstash-devutils
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ description: This gem is a logstash plugin required to be installed on top of the
76
+ Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not
77
+ a stand-alone program
78
+ email: ike.baranski@gmail.com
79
+ executables: []
80
+ extensions: []
81
+ extra_rdoc_files: []
82
+ files:
83
+ - lib/logstash/filters/dateparts.rb
84
+ - spec/filters/dateparts_spec.rb
85
+ - spec/spec_helper.rb
86
+ - logstash-filter-dateparts.gemspec
87
+ - CHANGELOG.md
88
+ - README.md
89
+ - Gemfile
90
+ - LICENSE
91
+ homepage: http://mikeski.net
92
+ licenses:
93
+ - Apache License (2.0)
94
+ metadata:
95
+ logstash_plugin: 'true'
96
+ logstash_group: filter
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.0.14.1
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: This dateparts fileter adds date information to your event based on your
117
+ timestamp
118
+ test_files:
119
+ - spec/filters/dateparts_spec.rb
120
+ - spec/spec_helper.rb