fluent-plugin-grep 0.3.2 → 0.3.3

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: f8ed5698594f518f8856725be943ebe18632086e
4
- data.tar.gz: c52945cd2644ff09ec8ca4ed71d3d4196fa76768
3
+ metadata.gz: b28e2f9df47ff5255ba541d237af0803507d0b54
4
+ data.tar.gz: 6f3d5af7d9893d5cdc27a20499273f0030c507f7
5
5
  SHA512:
6
- metadata.gz: e00ac4165583c2647cf00c1704b8bdc3d0913008ec7f0d2edc2f904b553b8b613770373df37b4575cfb9aeddfae467ac8f032b76d855bb96f2134df1804089e5
7
- data.tar.gz: d45ed519f94552d0d84b76da994ef378021566065052e62f46932bc13223bb42b7c896938974c5fa95730b6a9f16fcf9ea570d4134e6226f4a5fd06ee8a900f0
6
+ metadata.gz: 6ab25c093315af58af4517eb5239765386cbbfff46822c1225c9a56467833a033d7de7f2f174cae0ca817af448292558ab80dcd35edfdad2df5d93829f463cb8
7
+ data.tar.gz: 6baedc91f8bfeb856f2ac54c1473ad8f6f0a936fbd8036d462b017ef201042d809ea83a4a86cac57be5180f8026e99582159cf18510b47d49d60650aa2fedc56
data/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  rvm:
2
- - 1.9.2
3
2
  - 1.9.3
4
3
  - 2.0.0
4
+ - 2.1.*
5
5
  gemfile:
6
6
  - Gemfile
7
7
  - Gemfile.fluentd.lt.0.10.43
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.3.3 (2014/04/12)
2
+
3
+ Enhancements:
4
+
5
+ * Add `add_tag_suffix` and `remove_tag_suffix` options
6
+ * Allow . in tag options to support compatibility with HandleTagNameMixin
7
+
1
8
  ## 0.3.2 (2014/02/04)
2
9
 
3
10
  Enhancement:
data/README.md CHANGED
@@ -12,7 +12,7 @@ Fluentd plugin to grep messages.
12
12
  regexp WARN
13
13
  exclude favicon
14
14
  add_tag_prefix greped
15
- </source>
15
+ </match>
16
16
 
17
17
  Assuming following inputs are coming:
18
18
 
@@ -36,7 +36,7 @@ Now, `regexpN` and `excludeN` options are available to specify grep conditions f
36
36
  regexp2 foo ^awesome$
37
37
  exclude1 message favicon
38
38
  add_tag_prefix greped
39
- </source>
39
+ </match>
40
40
 
41
41
  Assuming following inputs are coming:
42
42
 
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "fluent-plugin-grep"
6
- s.version = "0.3.2"
6
+ s.version = "0.3.3"
7
7
  s.authors = ["Naotoshi Seo"]
8
8
  s.email = ["sonots@gmail.com"]
9
9
  s.homepage = "https://github.com/sonots/fluent-plugin-grep"
@@ -9,6 +9,8 @@ class Fluent::GrepOutput < Fluent::Output
9
9
  config_param :tag, :string, :default => nil
10
10
  config_param :add_tag_prefix, :string, :default => nil
11
11
  config_param :remove_tag_prefix, :string, :default => nil
12
+ config_param :add_tag_suffix, :string, :default => nil
13
+ config_param :remove_tag_suffix, :string, :default => nil
12
14
  config_param :replace_invalid_sequence, :bool, :default => false
13
15
  (1..REGEXP_MAX_NUM).each {|i| config_param :"regexp#{i}", :string, :default => nil }
14
16
  (1..REGEXP_MAX_NUM).each {|i| config_param :"exclude#{i}", :string, :default => nil }
@@ -45,24 +47,10 @@ class Fluent::GrepOutput < Fluent::Output
45
47
  @excludes[key] = Regexp.compile(exclude)
46
48
  end
47
49
 
48
- if @tag.nil? and @add_tag_prefix.nil? and @remove_tag_prefix.nil?
50
+ if @tag.nil? and @add_tag_prefix.nil? and @remove_tag_prefix.nil? and @add_tag_suffix.nil? and @remove_tag_suffix.nil?
49
51
  @add_tag_prefix = 'greped' # not ConfigError to support lower version compatibility
50
52
  end
51
-
52
- @tag_prefix = "#{@add_tag_prefix}." if @add_tag_prefix
53
- @tag_prefix_match = "#{@remove_tag_prefix}." if @remove_tag_prefix
54
- @tag_proc =
55
- if @tag
56
- Proc.new {|tag| @tag }
57
- elsif @tag_prefix and @tag_prefix_match
58
- Proc.new {|tag| "#{@tag_prefix}#{lstrip(tag, @tag_prefix_match)}" }
59
- elsif @tag_prefix_match
60
- Proc.new {|tag| lstrip(tag, @tag_prefix_match) }
61
- elsif @tag_prefix
62
- Proc.new {|tag| "#{@tag_prefix}#{tag}" }
63
- else
64
- Proc.new {|tag| tag }
65
- end
53
+ @tag_proc = tag_proc
66
54
  end
67
55
 
68
56
  def emit(tag, es, chain)
@@ -88,8 +76,25 @@ class Fluent::GrepOutput < Fluent::Output
88
76
 
89
77
  private
90
78
 
91
- def lstrip(string, substring)
92
- string.index(substring) == 0 ? string[substring.size..-1] : string
79
+ def tag_proc
80
+ rstrip = Proc.new {|str, substr| str.chomp(substr) }
81
+ lstrip = Proc.new {|str, substr| str.start_with?(substr) ? str[substr.size..-1] : str }
82
+ tag_prefix = "#{rstrip.call(@add_tag_prefix, '.')}." if @add_tag_prefix
83
+ tag_suffix = ".#{lstrip.call(@add_tag_suffix, '.')}" if @add_tag_suffix
84
+ tag_prefix_match = "#{rstrip.call(@remove_tag_prefix, '.')}." if @remove_tag_prefix
85
+ tag_suffix_match = ".#{lstrip.call(@remove_tag_suffix, '.')}" if @remove_tag_suffix
86
+ tag_fixed = @tag if @tag
87
+ if tag_fixed
88
+ Proc.new {|tag| tag_fixed }
89
+ elsif tag_prefix_match and tag_suffix_match
90
+ Proc.new {|tag| "#{tag_prefix}#{rstrip.call(lstrip.call(tag, tag_prefix_match), tag_suffix_match)}#{tag_suffix}" }
91
+ elsif tag_prefix_match
92
+ Proc.new {|tag| "#{tag_prefix}#{lstrip.call(tag, tag_prefix_match)}#{tag_suffix}" }
93
+ elsif tag_suffix_match
94
+ Proc.new {|tag| "#{tag_prefix}#{rstrip.call(tag, tag_suffix_match)}#{tag_suffix}" }
95
+ else
96
+ Proc.new {|tag| "#{tag_prefix}#{tag}#{tag_suffix}" }
97
+ end
93
98
  end
94
99
 
95
100
  def match(regexp, string)
@@ -31,3 +31,6 @@ end
31
31
  # AFTER regexps, exludes (0.3.0)
32
32
  # user system total real
33
33
  # 2.700000 0.050000 2.750000 ( 3.340524)
34
+ # AFTER add_tag_suffix, remove_tag_suffix (0.3.3)
35
+ # user system total real
36
+ # 2.470000 0.020000 2.490000 ( 3.012241)
@@ -160,6 +160,7 @@ describe Fluent::GrepOutput do
160
160
  add_tag_prefix foo
161
161
  ]
162
162
  end
163
+ let(:tag) { 'syslog.host1' }
163
164
  before do
164
165
  Fluent::Engine.stub(:now).and_return(time)
165
166
  Fluent::Engine.should_receive(:emit).with("foo.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
@@ -174,6 +175,7 @@ describe Fluent::GrepOutput do
174
175
  remove_tag_prefix syslog
175
176
  ]
176
177
  end
178
+ let(:tag) { 'syslog.host1' }
177
179
  before do
178
180
  Fluent::Engine.stub(:now).and_return(time)
179
181
  Fluent::Engine.should_receive(:emit).with("host1", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
@@ -181,6 +183,114 @@ describe Fluent::GrepOutput do
181
183
  it { emit }
182
184
  end
183
185
 
186
+ context 'add_tag_suffix' do
187
+ let(:config) do
188
+ CONFIG + %[
189
+ regexp ping
190
+ add_tag_suffix foo
191
+ ]
192
+ end
193
+ let(:tag) { 'syslog.host1' }
194
+ before do
195
+ Fluent::Engine.stub(:now).and_return(time)
196
+ Fluent::Engine.should_receive(:emit).with("#{tag}.foo", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
197
+ end
198
+ it { emit }
199
+ end
200
+
201
+ context 'remove_tag_suffix' do
202
+ let(:config) do
203
+ CONFIG + %[
204
+ regexp ping
205
+ remove_tag_suffix host1
206
+ ]
207
+ end
208
+ let(:tag) { 'syslog.host1' }
209
+ before do
210
+ Fluent::Engine.stub(:now).and_return(time)
211
+ Fluent::Engine.should_receive(:emit).with("syslog", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
212
+ end
213
+ it { emit }
214
+ end
215
+
216
+ context 'all tag options' do
217
+ let(:config) do
218
+ CONFIG + %[
219
+ regexp ping
220
+ add_tag_prefix foo
221
+ remove_tag_prefix syslog
222
+ add_tag_suffix foo
223
+ remove_tag_suffix host1
224
+ ]
225
+ end
226
+ let(:tag) { 'syslog.foo.host1' }
227
+ before do
228
+ Fluent::Engine.stub(:now).and_return(time)
229
+ Fluent::Engine.should_receive(:emit).with("foo.foo.foo", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
230
+ end
231
+ it { emit }
232
+ end
233
+
234
+ context 'add_tag_prefix.' do
235
+ let(:config) do
236
+ CONFIG + %[
237
+ regexp ping
238
+ add_tag_prefix foo.
239
+ ]
240
+ end
241
+ let(:tag) { 'syslog.host1' }
242
+ before do
243
+ Fluent::Engine.stub(:now).and_return(time)
244
+ Fluent::Engine.should_receive(:emit).with("foo.#{tag}", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
245
+ end
246
+ it { emit }
247
+ end
248
+
249
+ context 'remove_tag_prefix.' do
250
+ let(:config) do
251
+ CONFIG + %[
252
+ regexp ping
253
+ remove_tag_prefix syslog.
254
+ ]
255
+ end
256
+ let(:tag) { 'syslog.host1' }
257
+ before do
258
+ Fluent::Engine.stub(:now).and_return(time)
259
+ Fluent::Engine.should_receive(:emit).with("host1", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
260
+ end
261
+ it { emit }
262
+ end
263
+
264
+ context '.add_tag_suffix' do
265
+ let(:config) do
266
+ CONFIG + %[
267
+ regexp ping
268
+ add_tag_suffix .foo
269
+ ]
270
+ end
271
+ let(:tag) { 'syslog.host1' }
272
+ before do
273
+ Fluent::Engine.stub(:now).and_return(time)
274
+ Fluent::Engine.should_receive(:emit).with("#{tag}.foo", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
275
+ end
276
+ it { emit }
277
+ end
278
+
279
+ context '.remove_tag_suffix' do
280
+ let(:config) do
281
+ CONFIG + %[
282
+ regexp ping
283
+ remove_tag_suffix .host1
284
+ ]
285
+ end
286
+ let(:tag) { 'syslog.host1' }
287
+ before do
288
+ Fluent::Engine.stub(:now).and_return(time)
289
+ Fluent::Engine.should_receive(:emit).with("syslog", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
290
+ end
291
+ it { emit }
292
+ end
293
+
184
294
  context 'replace_invalid_sequence' do
185
295
  let(:config) do
186
296
  CONFIG + %[
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-grep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-04 00:00:00.000000000 Z
11
+ date: 2014-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd