fluent-plugin-notifier 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,8 +8,6 @@ Plugin to emit notifications for messages, with numbers over/under threshold, or
8
8
 
9
9
  ## Configuration
10
10
 
11
- ### NotifierOutput
12
-
13
11
  To notify apache logs with over 1000000 (microseconds) duration for CRITICAL , or status '500' by string pattern match:
14
12
 
15
13
  <match apache.log.**>
@@ -52,6 +50,77 @@ Default configurations:
52
50
 
53
51
  If you want to get every 5 minutes notifications (after 1 minutes notifications), specify '0' for 'repetitions\_2nd'.
54
52
 
53
+ ### Message Testing
54
+
55
+ To include specified messages into check target, or to exclude specified messages from check target, <test> directive is useful.
56
+
57
+ <match apache.log.**>
58
+ type notifier
59
+ <test>
60
+ check numeric
61
+ target_key duration # microseconds
62
+ lower_threshold 5000 # 5ms
63
+ upper_threshold 5000000 # 5s
64
+ </test>
65
+ <def>
66
+ pattern status_500
67
+ check string_find
68
+ warn_regexp 5\d\d
69
+ crit_regexp 500
70
+ target_key_pattern ^status.*$
71
+ </def>
72
+ </match>
73
+
74
+ With configuration above, fluent-plugin-notifier checks messages with specified duration value (d: 5000 <= d <= 5000000), and others are ignored.
75
+
76
+ Available 'check' types are: 'numeric', 'regexp' and 'tag'.
77
+
78
+ * numeric
79
+ * 'lower\_threshold', 'upper\_threshold' and both are available
80
+ * regexp, tag
81
+ * 'include\_pattern', 'exclude\_pattern' and both are available
82
+ * 'tag' checks tag strings after 'input\_tag\_remove\_prefix'
83
+
84
+ Multiple <test> directives means logical AND of each tests.
85
+
86
+ <match apache.log.**>
87
+ type notifier
88
+ input_tag_remove_prefix apache.log
89
+ <test>
90
+ check tag
91
+ include_pattern ^news[123]$ # for specified web server log
92
+ </test>
93
+ <test>
94
+ check numeric
95
+ target_key duration # microseconds
96
+ lower_threshold 5000 # 5ms
97
+ </test>
98
+ <test>
99
+ check regexp
100
+ target_key vhost
101
+ exclude_pattern ^image.news.example.com$ # ingore image delivery server log
102
+ </test>
103
+ <test>
104
+ check regexp
105
+ target_key path
106
+ include_pattern ^/path/to/contents/ # for specified content path only
107
+ exclude_pattern \.(gif|jpg|png|swf)$ # but image files are ignored
108
+ </test>
109
+ <def>
110
+ pattern status_500
111
+ check string_find
112
+ warn_regexp 5\d\d
113
+ crit_regexp 500
114
+ target_key_pattern ^status.*$
115
+ </def>
116
+ </match>
117
+
118
+ Notifier plugin configured like this will check messages:
119
+ * with tag 'apache.log.news1', 'apache.log.news2' or 'apache.log.news3'
120
+ * with duration bigger than 5ms (upper unlimited)
121
+ * without vhost image.news.example.com
122
+ * with request path '/path/to/contents/*' and without file suffix gif/jpg/png/swf.
123
+
55
124
  ## TODO
56
125
 
57
126
  * patches welcome!
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |gem|
3
3
  gem.name = "fluent-plugin-notifier"
4
- gem.version = "0.1.0"
4
+ gem.version = "0.2.0"
5
5
  gem.authors = ["TAGOMORI Satoshi"]
6
6
  gem.email = ["tagomoris@gmail.com"]
7
7
  gem.summary = %q{check matched messages and emit alert message}
@@ -16,7 +16,9 @@ class Fluent::NotifierOutput < Fluent::Output
16
16
  config_param :default_repetitions_2nd, :integer, :default => 5
17
17
  config_param :default_interval_3rd, :time, :default => 1800
18
18
 
19
- attr_accessor :defs, :states, :match_cache, :negative_cache
19
+ config_param :input_tag_remove_prefix, :string, :default => nil
20
+
21
+ attr_accessor :tests, :defs, :states, :match_cache, :negative_cache
20
22
 
21
23
  ### output
22
24
  # {
@@ -38,6 +40,18 @@ class Fluent::NotifierOutput < Fluent::Output
38
40
  # default_interval_2nd 5m
39
41
  # default_repetitions_2nd 5
40
42
  # default_interval_3rd 30m
43
+ # <test>
44
+ # check numeric
45
+ # target_key xxx
46
+ # lower_threshold xxx
47
+ # upper_threshold xxx
48
+ # </test>
49
+ # <test>
50
+ # check regexp
51
+ # target_key xxx
52
+ # include_pattern ^.$
53
+ # exclude_pattern ^.$
54
+ # </test>
41
55
  # <def>
42
56
  # pattern http_status_errors
43
57
  # check numeric_upward
@@ -65,9 +79,15 @@ class Fluent::NotifierOutput < Fluent::Output
65
79
 
66
80
  @match_cache = {} # cache which has map (fieldname => definition(s))
67
81
  @negative_cache = {}
82
+ @tests = []
68
83
  @defs = []
69
84
  @states = {} # key: tag+field ?
70
85
 
86
+ if @input_tag_remove_prefix
87
+ @input_tag_remove_prefix_string = @input_tag_remove_prefix + '.'
88
+ @input_tag_remove_prefix_length = @input_tag_remove_prefix_string.length
89
+ end
90
+
71
91
  defaults = {
72
92
  :tag => @default_tag, :tag_warn => @default_tag_warn, :tag_crit => @default_tag_crit,
73
93
  :interval_1st => @default_interval_1st, :repetitions_1st => @default_repetitions_1st,
@@ -76,10 +96,14 @@ class Fluent::NotifierOutput < Fluent::Output
76
96
  }
77
97
 
78
98
  conf.elements.each do |element|
79
- if element.name != 'def'
80
- raise Fluent::ConfigError, "invalid section name for out_notifier: #{d.name}"
99
+ case element.name
100
+ when 'test'
101
+ @tests.push(Test.new(element))
102
+ when 'def'
103
+ @defs.push(Definition.new(element, defaults))
104
+ else
105
+ raise Fluent::ConfigError, "invalid section name for out_notifier: #{element.name}"
81
106
  end
82
- defs.push(Definition.new(element, defaults))
83
107
  end
84
108
  end
85
109
 
@@ -120,12 +144,18 @@ class Fluent::NotifierOutput < Fluent::Output
120
144
  end
121
145
  end
122
146
 
123
- def emit(tag, es, chain)
147
+ def check(tag, es)
124
148
  notifications = []
125
149
 
150
+ tag = if @input_tag_remove_prefix and
151
+ tag.start_with?(@input_tag_remove_prefix_string) and tag.length > @input_tag_remove_prefix_length
152
+ tag[@input_tag_remove_prefix_length..-1]
153
+ else
154
+ tag
155
+ end
156
+
126
157
  es.each do |time,record|
127
158
  record.keys.each do |key|
128
-
129
159
  next if @negative_cache[key]
130
160
 
131
161
  defs = @match_cache[key]
@@ -134,12 +164,12 @@ class Fluent::NotifierOutput < Fluent::Output
134
164
  @defs.each do |d|
135
165
  defs.push(d) if d.match?(key)
136
166
  end
137
- if defs.size < 1
138
- @negative_cache[key] = true
139
- end
167
+ @negative_cache[key] = true if defs.size < 1
140
168
  end
141
169
 
142
170
  defs.each do |d|
171
+ next unless @tests.reduce(true){|r,t| r and t.test(tag, record)}
172
+
143
173
  alert = d.check(tag, time, record, key)
144
174
  if alert
145
175
  notifications.push(alert)
@@ -148,6 +178,12 @@ class Fluent::NotifierOutput < Fluent::Output
148
178
  end
149
179
  end
150
180
 
181
+ notifications
182
+ end
183
+
184
+ def emit(tag, es, chain)
185
+ notifications = check(tag, es)
186
+
151
187
  if notifications.size > 0
152
188
  @mutex.synchronize do
153
189
  suppressed_emit(notifications)
@@ -164,6 +200,73 @@ class Fluent::NotifierOutput < Fluent::Output
164
200
  chain.next
165
201
  end
166
202
 
203
+ class Test
204
+ attr_accessor :check, :target_key
205
+ attr_accessor :lower_threshold, :upper_threshold
206
+ attr_accessor :include_pattern, :exclude_pattern
207
+
208
+ def initialize(element)
209
+ element.keys.each do |k|
210
+ v = element[k]
211
+ case k
212
+ when 'check'
213
+ case v
214
+ when 'tag'
215
+ @check = :tag
216
+ @include_pattern = element['include_pattern'] ? Regexp.compile(element['include_pattern']) : nil
217
+ @exclude_pattern = element['exclude_pattern'] ? Regexp.compile(element['exclude_pattern']) : nil
218
+ if @include_pattern.nil? and @exclude_pattern.nil?
219
+ raise Fluent::ConfigError, "At least one of include_pattern or exclude_pattern must be specified for 'check tag'"
220
+ end
221
+ when 'numeric'
222
+ @check = :numeric
223
+ @lower_threshold = element['lower_threshold'] ? element['lower_threshold'].to_f : nil
224
+ @upper_threshold = element['upper_threshold'] ? element['upper_threshold'].to_f : nil
225
+ if @lower_threshold.nil? and @upper_threshold.nil?
226
+ raise Fluent::ConfigError, "At least one of lower_threshold or upper_threshold must be specified for 'check numeric'"
227
+ end
228
+ when 'regexp'
229
+ @check = :regexp
230
+ @include_pattern = element['include_pattern'] ? Regexp.compile(element['include_pattern']) : nil
231
+ @exclude_pattern = element['exclude_pattern'] ? Regexp.compile(element['exclude_pattern']) : nil
232
+ if @include_pattern.nil? and @exclude_pattern.nil?
233
+ raise Fluent::ConfigError, "At least one of include_pattern or exclude_pattern must be specified for 'check regexp'"
234
+ end
235
+ else
236
+ raise Fluent::ConfigError, "invalid check value of test [numeric/regexp]: '#{v}'"
237
+ end
238
+ when 'target_key'
239
+ @target_key = v
240
+ end
241
+ end
242
+ unless @check
243
+ raise Fluent::ConfigError, "'check' missing in <test> section"
244
+ end
245
+ if @target_key.nil? and @check != :tag
246
+ raise Fluent::ConfigError, "'target_key' missing in <test> section"
247
+ end
248
+ end
249
+
250
+ def test(tag, record)
251
+ v = case @check
252
+ when :numeric, :regexp
253
+ record[@target_key]
254
+ when :tag
255
+ tag
256
+ end
257
+ return false if v.nil?
258
+
259
+ case @check
260
+ when :numeric
261
+ v = v.to_f
262
+ (@lower_threshold.nil? or @lower_threshold <= v) and (@upper_threshold.nil? or v <= @upper_threshold)
263
+ when :tag, :regexp
264
+ v = v.to_s.force_encoding('ASCII-8BIT')
265
+ ((@include_pattern.nil? or @include_pattern.match(v)) and (@exclude_pattern.nil? or (not @exclude_pattern.match(v)))) or false
266
+ end
267
+ end
268
+ end
269
+
167
270
  class Definition
168
271
  attr_accessor :tag, :tag_warn, :tag_crit
169
272
  attr_accessor :intervals, :repetitions
@@ -180,14 +283,23 @@ class Fluent::NotifierOutput < Fluent::Output
180
283
  case element[k]
181
284
  when 'numeric_upward'
182
285
  @check = :upward
286
+ unless element.has_key?('crit_threshold') and element.has_key?('warn_threshold')
287
+ raise Fluent::ConfigError, "Both of crit_threshold and warn_threshold must be specified for 'check numeric_upward'"
288
+ end
183
289
  @crit_threshold = element['crit_threshold'].to_f
184
290
  @warn_threshold = element['warn_threshold'].to_f
185
291
  when 'numeric_downward'
186
292
  @check = :downward
293
+ unless element.has_key?('crit_threshold') and element.has_key?('warn_threshold')
294
+ raise Fluent::ConfigError, "Both of crit_threshold and warn_threshold must be specified for 'check_numeric_downward'"
295
+ end
187
296
  @crit_threshold = element['crit_threshold'].to_f
188
297
  @warn_threshold = element['warn_threshold'].to_f
189
298
  when 'string_find'
190
299
  @check = :find
300
+ unless element.has_key?('crit_regexp') and element.has_key?('warn_regexp')
301
+ raise Fluent::ConfigError, "Both of crit_regexp and warn_regexp must be specified for 'check string_find'"
302
+ end
191
303
  @crit_regexp = Regexp.compile(element['crit_regexp'].to_s)
192
304
  @warn_regexp = Regexp.compile(element['warn_regexp'].to_s)
193
305
  else
@@ -2,8 +2,110 @@ require 'helper'
2
2
 
3
3
  class NotifierOutputTest < Test::Unit::TestCase
4
4
  CONFIG = %[
5
+ type notifier
6
+ input_tag_remove_prefix test
7
+ <test>
8
+ check numeric
9
+ target_key numfield
10
+ lower_threshold 2.5
11
+ upper_threshold 5000
12
+ </test>
13
+ <test>
14
+ check regexp
15
+ target_key textfield
16
+ include_pattern Target.*
17
+ exclude_pattern TargetC
18
+ </test>
19
+ <def>
20
+ pattern pattern1
21
+ check numeric_upward
22
+ warn_threshold 25
23
+ crit_threshold 50
24
+ tag_warn alert.warn
25
+ tag_crit alert.crit
26
+ target_keys num1,num2,num3
27
+ </def>
28
+ <def>
29
+ pattern pattern2
30
+ check string_find
31
+ crit_regexp ERROR
32
+ warn_regexp WARNING
33
+ tag alert
34
+ target_key_pattern ^message.*$
35
+ </def>
5
36
  ]
37
+
6
38
  def create_driver(conf=CONFIG,tag='test')
7
39
  Fluent::Test::OutputTestDriver.new(Fluent::NotifierOutput, tag).configure(conf)
8
40
  end
41
+
42
+ def test_configure
43
+ d = create_driver
44
+ assert_nil nil # no one exception raised
45
+ end
46
+
47
+ def test_emit
48
+ d = create_driver
49
+ d.run do
50
+ d.emit({'num1' => 20, 'message' => 'INFO'})
51
+ end
52
+ assert_equal 0, d.emits.size
53
+
54
+ d = create_driver
55
+ d.run do
56
+ d.emit({'num1' => 30, 'message' => 'INFO'})
57
+ end
58
+ assert_equal 0, d.emits.size
59
+
60
+ d = create_driver(CONFIG, 'test.input')
61
+ d.run do
62
+ d.emit({'num1' => 30, 'message' => 'INFO', 'numfield' => '30', 'textfield' => 'TargetX'})
63
+ end
64
+ assert_equal 1, d.emits.size
65
+ assert_equal 'alert.warn', d.emits[0][0]
66
+ assert_equal 'pattern1', d.emits[0][2]['pattern']
67
+ assert_equal 'input', d.emits[0][2]['target_tag']
68
+ assert_equal 'numeric_upward', d.emits[0][2]['check_type']
69
+ assert_equal 'warn', d.emits[0][2]['level']
70
+ assert_equal 25.0, d.emits[0][2]['threshold']
71
+ assert_equal 30.0, d.emits[0][2]['value']
72
+
73
+ d = create_driver
74
+ d.run do
75
+ d.emit({'num1' => 60, 'message' => 'foo bar WARNING xxxxx', 'numfield' => '30', 'textfield' => 'TargetX'})
76
+ end
77
+ assert_equal 2, d.emits.size
78
+ assert_equal 'alert.crit', d.emits[0][0]
79
+ assert_equal 'pattern1', d.emits[0][2]['pattern']
80
+ assert_equal 'test', d.emits[0][2]['target_tag']
81
+ assert_equal 'numeric_upward', d.emits[0][2]['check_type']
82
+ assert_equal 'crit', d.emits[0][2]['level']
83
+ assert_equal 50.0, d.emits[0][2]['threshold']
84
+ assert_equal 60.0, d.emits[0][2]['value']
85
+ assert_equal 'alert', d.emits[1][0]
86
+ assert_equal 'pattern2', d.emits[1][2]['pattern']
87
+ assert_equal 'test', d.emits[1][2]['target_tag']
88
+ assert_equal 'string_find', d.emits[1][2]['check_type']
89
+ assert_equal 'warn', d.emits[1][2]['level']
90
+ assert_equal '/WARNING/', d.emits[1][2]['regexp']
91
+ assert_equal 'foo bar WARNING xxxxx', d.emits[1][2]['value']
92
+
93
+ d = create_driver
94
+ d.run do
95
+ d.emit({'num1' => 60, 'message' => 'foo bar WARNING xxxxx', 'numfield' => '2.4', 'textfield' => 'TargetX'})
96
+ end
97
+ assert_equal 0, d.emits.size
98
+
99
+ d = create_driver
100
+ d.run do
101
+ d.emit({'num1' => 60, 'message' => 'foo bar WARNING xxxxx', 'numfield' => '20', 'textfield' => 'TargetC'})
102
+ end
103
+ assert_equal 0, d.emits.size
104
+
105
+ d = create_driver
106
+ d.run do
107
+ d.emit({'num1' => 60, 'message' => 'foo bar WARNING xxxxx', 'numfield' => '20'})
108
+ end
109
+ assert_equal 0, d.emits.size
110
+ end
9
111
  end
@@ -0,0 +1,178 @@
1
+ require 'helper'
2
+
3
+ class NotifierOutputTestTest < Test::Unit::TestCase
4
+ TEST_CONF1 = {
5
+ 'check' => 'numeric', 'target_key' => 'field1',
6
+ 'lower_threshold' => '1', 'upper_threshold' => '2',
7
+ }
8
+ TEST_CONF2 = {
9
+ 'check' => 'numeric', 'target_key' => 'field1',
10
+ 'lower_threshold' => '1',
11
+ }
12
+ TEST_CONF3 = {
13
+ 'check' => 'numeric', 'target_key' => 'field1',
14
+ 'upper_threshold' => '2',
15
+ }
16
+ TEST_CONF4 = {
17
+ 'check' => 'regexp', 'target_key' => 'field2',
18
+ 'include_pattern' => 'hoge', 'exclude_pattern' => 'pos',
19
+ }
20
+ TEST_CONF5 = {
21
+ 'check' => 'regexp', 'target_key' => 'field2',
22
+ 'include_pattern' => 'hoge',
23
+ }
24
+ TEST_CONF6 = {
25
+ 'check' => 'regexp', 'target_key' => 'field2',
26
+ 'exclude_pattern' => 'pos',
27
+ }
28
+ TEST_CONF7 = {
29
+ 'check' => 'tag',
30
+ 'include_pattern' => 'hoge',
31
+ 'exclude_pattern' => 'pos',
32
+ }
33
+ TEST_CONF8 = {
34
+ 'check' => 'tag',
35
+ 'include_pattern' => 'hoge',
36
+ }
37
+ TEST_CONF9 = {
38
+ 'check' => 'tag',
39
+ 'exclude_pattern' => 'pos',
40
+ }
41
+
42
+ def test_init
43
+ t = Fluent::NotifierOutput::Test.new(TEST_CONF1)
44
+ assert_equal :numeric, t.check
45
+ assert_equal 'field1', t.target_key
46
+ assert_equal 1.0, t.lower_threshold
47
+ assert_equal 2.0, t.upper_threshold
48
+
49
+ t = Fluent::NotifierOutput::Test.new(TEST_CONF4)
50
+ assert_equal :regexp, t.check
51
+ assert_equal 'field2', t.target_key
52
+ assert_equal /hoge/, t.include_pattern
53
+ assert_equal /pos/, t.exclude_pattern
54
+
55
+ t = Fluent::NotifierOutput::Test.new(TEST_CONF7)
56
+ assert_equal :tag, t.check
57
+ assert_nil t.target_key
58
+ assert_equal /hoge/, t.include_pattern
59
+ assert_equal /pos/, t.exclude_pattern
60
+ end
61
+
62
+ def test_numeric
63
+ t = Fluent::NotifierOutput::Test.new(TEST_CONF1)
64
+ assert_equal :numeric, t.check
65
+ assert_equal 'field1', t.target_key
66
+ assert_equal 1.0, t.lower_threshold
67
+ assert_equal 2.0, t.upper_threshold
68
+
69
+ assert_equal false, t.test('test', {'field2' => '0.5'})
70
+ assert_equal false, t.test('test', {'field1' => '0.5'})
71
+ assert_equal true, t.test('test', {'field1' => 1})
72
+ assert_equal true, t.test('test', {'field1' => 1.999999999999999999999999999999})
73
+ assert_equal true, t.test('test', {'field1' => 2.0})
74
+ assert_equal false, t.test('test', {'field1' => '2.0000001'})
75
+
76
+ t = Fluent::NotifierOutput::Test.new(TEST_CONF2)
77
+ # TEST_CONF2 = {
78
+ # 'check' => 'numeric', 'target_key' => 'field1',
79
+ # 'lower_threshold' => '1',
80
+ # }
81
+ assert_equal false, t.test('test', {'field2' => '0.5'})
82
+ assert_equal false, t.test('test', {'field1' => '0.5'})
83
+ assert_equal true, t.test('test', {'field1' => 1})
84
+ assert_equal true, t.test('test', {'field1' => 1.999999999999999999999999999999})
85
+ assert_equal true, t.test('test', {'field1' => 2.0})
86
+ assert_equal true, t.test('test', {'field1' => '2.0000001'})
87
+ assert_equal true, t.test('test', {'field1' => 10000.32})
88
+
89
+
90
+ t = Fluent::NotifierOutput::Test.new(TEST_CONF3)
91
+ # TEST_CONF3 = {
92
+ # 'check' => 'numeric', 'target_key' => 'field1',
93
+ # 'upper_threshold' => '2',
94
+ # }
95
+ assert_equal false, t.test('test', {'field2' => '0.5'})
96
+ assert_equal true, t.test('test', {'field1' => '0.5'})
97
+ assert_equal true, t.test('test', {'field1' => 1})
98
+ assert_equal true, t.test('test', {'field1' => 1.999999999999999999999999999999})
99
+ assert_equal true, t.test('test', {'field1' => 2.0})
100
+ assert_equal false, t.test('test', {'field1' => '2.0000001'})
101
+ assert_equal false, t.test('test', {'field1' => 10000.32})
102
+
103
+ assert_equal true, t.test('test', {'field1' => 0.0})
104
+ assert_equal true, t.test('test', {'field1' => '-1'})
105
+ end
106
+
107
+ def test_regexp
108
+ t = Fluent::NotifierOutput::Test.new(TEST_CONF4)
109
+ assert_equal :regexp, t.check
110
+ assert_equal 'field2', t.target_key
111
+ assert_equal /hoge/, t.include_pattern
112
+ assert_equal /pos/, t.exclude_pattern
113
+
114
+ assert_equal false, t.test('test', {'field1' => 'hoge foo bar'})
115
+ assert_equal false, t.test('test', {'field2' => ''})
116
+ assert_equal true, t.test('test', {'field2' => 'hoge foo bar'})
117
+ assert_equal false, t.test('test', {'field2' => 'hoge pos foo bar'})
118
+ assert_equal false, t.test('test', {'field2' => 'pos foo bar'})
119
+ assert_equal false, t.test('test', {'field2' => 'pos hoge foo bar'})
120
+ assert_equal true, t.test('test', {'field2' => 'hoge foo bar hoge'})
121
+
122
+ t = Fluent::NotifierOutput::Test.new(TEST_CONF5)
123
+ # TEST_CONF5 = {
124
+ # 'check' => 'regexp', 'target_key' => 'field2',
125
+ # 'include_pattern' => 'hoge',
126
+ # }
127
+ assert_equal false, t.test('test', {'field1' => 'hoge foo bar'})
128
+ assert_equal false, t.test('test', {'field2' => ''})
129
+ assert_equal true, t.test('test', {'field2' => 'hoge foo bar'})
130
+ assert_equal true, t.test('test', {'field2' => 'hoge pos foo bar'})
131
+ assert_equal false, t.test('test', {'field2' => 'pos foo bar'})
132
+ assert_equal true, t.test('test', {'field2' => 'pos hoge foo bar'})
133
+ assert_equal true, t.test('test', {'field2' => 'hoge foo bar hoge'})
134
+
135
+ t = Fluent::NotifierOutput::Test.new(TEST_CONF6)
136
+ # TEST_CONF6 = {
137
+ # 'check' => 'regexp', 'target_key' => 'field2',
138
+ # 'exclude_pattern' => 'pos',
139
+ # }
140
+ assert_equal false, t.test('test', {'field1' => 'hoge foo bar'})
141
+ assert_equal true, t.test('test', {'field2' => ''})
142
+ assert_equal true, t.test('test', {'field2' => 'hoge foo bar'})
143
+ assert_equal false, t.test('test', {'field2' => 'hoge pos foo bar'})
144
+ assert_equal false, t.test('test', {'field2' => 'pos foo bar'})
145
+ assert_equal false, t.test('test', {'field2' => 'pos hoge foo bar'})
146
+ assert_equal true, t.test('test', {'field2' => 'hoge foo bar hoge'})
147
+ end
148
+
149
+ def test_tag
150
+ t = Fluent::NotifierOutput::Test.new(TEST_CONF7)
151
+ # TEST_CONF7 = {
152
+ # 'check' => 'tag',
153
+ # 'include_pattern' => 'hoge',
154
+ # 'exclude_pattern' => 'pos',
155
+ # }
156
+ assert_equal false, t.test('test', {'field1' => 'hoge foo bar'})
157
+ assert_equal true, t.test('test.hoge', {'field1' => 'hoge foo bar'})
158
+ assert_equal false, t.test('test.hoge.pos', {'field1' => 'hoge foo bar'})
159
+
160
+ t = Fluent::NotifierOutput::Test.new(TEST_CONF8)
161
+ # TEST_CONF8 = {
162
+ # 'check' => 'tag',
163
+ # 'include_pattern' => 'hoge',
164
+ # }
165
+ assert_equal false, t.test('test', {'field1' => 'hoge foo bar'})
166
+ assert_equal true, t.test('test.hoge', {'field1' => 'hoge foo bar'})
167
+ assert_equal true, t.test('test.hoge.pos', {'field1' => 'hoge foo bar'})
168
+
169
+ t = Fluent::NotifierOutput::Test.new(TEST_CONF9)
170
+ # TEST_CONF9 = {
171
+ # 'check' => 'tag',
172
+ # 'exclude_pattern' => 'pos',
173
+ # }
174
+ assert_equal true, t.test('test', {'field1' => 'hoge foo bar'})
175
+ assert_equal true, t.test('test.hoge', {'field1' => 'hoge foo bar'})
176
+ assert_equal false, t.test('test.hoge.pos', {'field1' => 'hoge foo bar'})
177
+ end
178
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-19 00:00:00.000000000 Z
12
+ date: 2012-08-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -77,6 +77,7 @@ files:
77
77
  - test/plugin/test_def.rb
78
78
  - test/plugin/test_out_notifier.rb
79
79
  - test/plugin/test_state.rb
80
+ - test/plugin/test_test.rb
80
81
  homepage: https://github.com/tagomoris/fluent-plugin-notifier
81
82
  licenses: []
82
83
  post_install_message:
@@ -106,3 +107,4 @@ test_files:
106
107
  - test/plugin/test_def.rb
107
108
  - test/plugin/test_out_notifier.rb
108
109
  - test/plugin/test_state.rb
110
+ - test/plugin/test_test.rb