fluent-plugin-grepcounter 0.4.0 → 0.4.1

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: 16a2bb7af97b5bbe3d7436c7f9ac749a74a8b660
4
- data.tar.gz: 77e82589f64a366baf731899318c22c9cf076a37
3
+ metadata.gz: 86bdb8c2cc79fb721b52ca56d8c8e523cbdcc12f
4
+ data.tar.gz: b63dbf7c4a149a9fda4ef52c6c02a73092baae48
5
5
  SHA512:
6
- metadata.gz: 28c15035659a4ced1b00e033f8ab53e51cde287be5a62ef57af4834a75ba755eba6f929f4c3422534f368cb3842f83112fc70bb41a54eefc915b1534de7b284e
7
- data.tar.gz: b67364cf3cd70c42bdd6015238383100d04fc030a320804a6c41eaa792ddd15be5335bfe37d1f7faf41ae1a41b3f12f3bfdea4d4d366fdc6cb6afaadb6af6a85
6
+ metadata.gz: 34882d64a3c25e0740e9f80ecbadab394101391bd4ce121f713eee5640b336071477a137c20e25fbdfdbdbdf63d003dbbf1c7e4a4bea5e0453ff2cc62911c47a
7
+ data.tar.gz: 7990a6f34f89a4bd23c95824ebe58edbf85848c1c595ff02131b29fe676820d30125a49d6dddd2ca51d80a2eb98869c323b53aee1023f6b83288cceca6a01d1e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.4.1 (2013/11/30)
2
+
3
+ Features
4
+
5
+ - add `remove_tag_prefix` option
6
+
1
7
  ## 0.4.0 (2013/11/30)
2
8
 
3
9
  Changes
data/README.md CHANGED
@@ -112,6 +112,10 @@ Then, output bocomes as belows (indented). You can see the `message` field is jo
112
112
 
113
113
  Add tag prefix for output message
114
114
 
115
+ - remove\_tag\_prefix (from 0.4.1)
116
+
117
+ Remove tag prefix for output message
118
+
115
119
  - output\_with\_joined\_delimiter (obsolete from 0.4.0)
116
120
 
117
121
  Output matched messages after `join`ed with the specified delimiter.
@@ -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-grepcounter"
6
- s.version = "0.4.0"
6
+ s.version = "0.4.1"
7
7
  s.authors = ["Naotoshi SEO"]
8
8
  s.email = ["sonots@gmail.com"]
9
9
  s.homepage = "https://github.com/sonots/fluent-plugin-grepcounter"
@@ -20,6 +20,7 @@ class Fluent::GrepCounterOutput < Fluent::Output
20
20
  config_param :output_tag, :string, :default => nil # obsolete
21
21
  config_param :tag, :string, :default => nil
22
22
  config_param :add_tag_prefix, :string, :default => 'count'
23
+ config_param :remove_tag_prefix, :string, :default => nil
23
24
  config_param :output_with_joined_delimiter, :string, :default => nil # obsolete
24
25
  config_param :delimiter, :string, :default => nil
25
26
  config_param :aggregate, :string, :default => 'tag'
@@ -82,6 +83,21 @@ class Fluent::GrepCounterOutput < Fluent::Output
82
83
  end
83
84
  end
84
85
 
86
+ @tag_prefix = "#{@add_tag_prefix}."
87
+ @tag_prefix_match = "#{@remove_tag_prefix}." if @remove_tag_prefix
88
+ @tag_proc =
89
+ if @tag
90
+ Proc.new {|tag| @tag }
91
+ elsif @tag_prefix and @tag_prefix_match
92
+ Proc.new {|tag| "#{@tag_prefix}#{lstrip(tag, @tag_prefix_match)}" }
93
+ elsif @tag_prefix_match
94
+ Proc.new {|tag| lstrip(tag, @tag_prefix_match) }
95
+ elsif @tag_prefix
96
+ Proc.new {|tag| "#{@tag_prefix}#{tag}" }
97
+ else
98
+ Proc.new {|tag| tag }
99
+ end
100
+
85
101
  @matches = {}
86
102
  @counts = {}
87
103
  @mutex = Mutex.new
@@ -159,8 +175,10 @@ class Fluent::GrepCounterOutput < Fluent::Output
159
175
  count = flushed_counts[tag]
160
176
  matches = flushed_matches[tag]
161
177
  output = generate_output(count, matches, tag)
162
- tag = @tag ? @tag : "#{@add_tag_prefix}.#{tag}"
163
- Fluent::Engine.emit(tag, time, output) if output
178
+ if output
179
+ emit_tag = @tag_proc.call(tag)
180
+ Fluent::Engine.emit(emit_tag, time, output)
181
+ end
164
182
  end
165
183
  end
166
184
  end
@@ -182,17 +200,18 @@ class Fluent::GrepCounterOutput < Fluent::Output
182
200
  output
183
201
  end
184
202
 
203
+ def lstrip(string, substring)
204
+ string.index(substring) == 0 ? string[substring.size..-1] : string
205
+ end
206
+
185
207
  def match(string)
186
208
  begin
187
209
  return false if @regexp and !@regexp.match(string)
188
210
  return false if @exclude and @exclude.match(string)
189
211
  rescue ArgumentError => e
190
- unless e.message.index("invalid byte sequence in") == 0
191
- raise
192
- end
212
+ raise e unless e.message.index("invalid byte sequence in") == 0
193
213
  string = replace_invalid_byte(string)
194
- return false if @regexp and !@regexp.match(string)
195
- return false if @exclude and @exclude.match(string)
214
+ retry
196
215
  end
197
216
  return true
198
217
  end
@@ -281,6 +281,15 @@ describe Fluent::GrepCounterOutput do
281
281
  it { emit }
282
282
  end
283
283
 
284
+ context 'remove_tag_prefix' do
285
+ let(:config) { CONFIG + %[add_tag_prefix foo\nremove_tag_prefix syslog] }
286
+ before do
287
+ Fluent::Engine.stub(:now).and_return(time)
288
+ Fluent::Engine.should_receive(:emit).with("foo.host1", time, expected)
289
+ end
290
+ it { emit }
291
+ end
292
+
284
293
  context 'output_with_joined_delimiter (obsolete)' do
285
294
  # \\n shall be \n in config file
286
295
  let(:config) { CONFIG + %[output_with_joined_delimiter \\n] }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-grepcounter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi SEO