fluent-plugin-grepcounter 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +4 -0
- data/fluent-plugin-grepcounter.gemspec +1 -1
- data/lib/fluent/plugin/out_grepcounter.rb +26 -7
- data/spec/out_grepcounter_spec.rb +9 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86bdb8c2cc79fb721b52ca56d8c8e523cbdcc12f
|
4
|
+
data.tar.gz: b63dbf7c4a149a9fda4ef52c6c02a73092baae48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34882d64a3c25e0740e9f80ecbadab394101391bd4ce121f713eee5640b336071477a137c20e25fbdfdbdbdf63d003dbbf1c7e4a4bea5e0453ff2cc62911c47a
|
7
|
+
data.tar.gz: 7990a6f34f89a4bd23c95824ebe58edbf85848c1c595ff02131b29fe676820d30125a49d6dddd2ca51d80a2eb98869c323b53aee1023f6b83288cceca6a01d1e
|
data/CHANGELOG.md
CHANGED
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.
|
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
|
-
|
163
|
-
|
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
|
-
|
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] }
|