fluent-plugin-notifier 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,28 +1,9 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
1
+ require 'bundler/setup'
10
2
  require 'test/unit'
11
3
 
12
4
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
14
6
  require 'fluent/test'
15
- unless ENV.has_key?('VERBOSE')
16
- nulllogger = Object.new
17
- nulllogger.instance_eval {|obj|
18
- def method_missing(method, *args)
19
- # pass
20
- end
21
- }
22
- $log = nulllogger
23
- end
7
+ require 'fluent/test/driver/output'
24
8
 
25
9
  require 'fluent/plugin/out_notifier'
26
-
27
- class Test::Unit::TestCase
28
- end
@@ -1,12 +1,19 @@
1
1
  require 'helper'
2
+ require 'fluent/test/helpers'
2
3
 
3
4
  class NotifierOutputDefinitionTest < Test::Unit::TestCase
4
- TEST_DEFAULTS = {
5
- :tag => 'n', :tag_warn => nil, :tag_crit => nil,
6
- :interval_1st => 60, :repetitions_1st => 5,
7
- :interval_2nd => 300, :repetitions_2nd => 5,
8
- :interval_3rd => 1800
9
- }
5
+ include Fluent::Test::Helpers
6
+
7
+ def setup
8
+ Fluent::Test.setup
9
+ @i = Fluent::Plugin::NotifierOutput.new
10
+ @i.configure(config_element())
11
+ end
12
+
13
+ def gen_conf(hash)
14
+ root = @i.configured_section_create(nil, config_element('root', '', {}, [config_element('def', '', hash)]))
15
+ root.def_configs.first
16
+ end
10
17
 
11
18
  TEST_CONF1 = {
12
19
  'tag' => 'notify',
@@ -24,41 +31,41 @@ class NotifierOutputDefinitionTest < Test::Unit::TestCase
24
31
  }
25
32
 
26
33
  def test_init
27
- d = Fluent::NotifierOutput::Definition.new(TEST_CONF1, TEST_DEFAULTS)
28
- assert_equal 'name1', d.pattern
29
- assert_equal ['field1','field2'], d.target_keys
30
- assert_equal :upward, d.instance_eval{ @check }
31
- assert_equal 2.0, d.crit_threshold
32
- assert_equal 1.0, d.warn_threshold
33
- assert_equal 'notify', d.tag
34
+ d = Fluent::Plugin::NotifierOutput::Definition.new(gen_conf(TEST_CONF1), @i)
35
+ assert_equal('name1', d.pattern)
36
+ assert_equal(['field1','field2'], d.target_keys)
37
+ assert_equal(:upward, d.instance_eval{ @check })
38
+ assert_equal(2.0, d.crit_threshold)
39
+ assert_equal(1.0, d.warn_threshold)
40
+ assert_equal('notify', d.tag)
34
41
  assert_nil d.tag_warn
35
42
  assert_nil d.tag_crit
36
- assert_equal [60, 300, 1800], d.intervals
37
- assert_equal [5, 5], d.repetitions
38
-
39
- d = Fluent::NotifierOutput::Definition.new(TEST_CONF2, TEST_DEFAULTS)
40
- assert_equal 'name2', d.pattern
41
- assert_equal /^field\d$/, d.target_key_pattern
42
- assert_equal /^$/, d.exclude_key_pattern
43
- assert_equal :find, d.instance_eval{ @check }
44
- assert_equal /WARN/, d.warn_regexp
45
- assert_equal /CRIT/, d.crit_regexp
46
- assert_equal 'n', d.tag
47
- assert_equal 'warn', d.tag_warn
48
- assert_equal 'crit', d.tag_crit
49
- assert_equal [5, 6, 7], d.intervals
50
- assert_equal [1, 2], d.repetitions
43
+ assert_equal([60, 300, 1800], d.intervals)
44
+ assert_equal([5, 5], d.repetitions)
45
+
46
+ d = Fluent::Plugin::NotifierOutput::Definition.new(gen_conf(TEST_CONF2), @i)
47
+ assert_equal('name2', d.pattern)
48
+ assert_equal(/^field\d$/, d.target_key_pattern)
49
+ assert_equal(/^$/, d.exclude_key_pattern)
50
+ assert_equal(:find, d.instance_eval{ @check })
51
+ assert_equal(/WARN/, d.warn_regexp)
52
+ assert_equal(/CRIT/, d.crit_regexp)
53
+ assert_equal('notification', d.tag)
54
+ assert_equal('warn', d.tag_warn)
55
+ assert_equal('crit', d.tag_crit)
56
+ assert_equal([5, 6, 7], d.intervals)
57
+ assert_equal([1, 2], d.repetitions)
51
58
  end
52
59
 
53
60
  def test_match
54
- d = Fluent::NotifierOutput::Definition.new(TEST_CONF1, TEST_DEFAULTS)
55
- assert_equal true, d.match?('field1')
56
- assert_equal true, d.match?('field2')
61
+ d = Fluent::Plugin::NotifierOutput::Definition.new(gen_conf(TEST_CONF1), @i)
62
+ assert_equal(true, d.match?('field1'))
63
+ assert_equal(true, d.match?('field2'))
57
64
  assert ! d.match?('field0')
58
65
  assert ! d.match?('field')
59
66
  assert ! d.match?('')
60
67
 
61
- d = Fluent::NotifierOutput::Definition.new(TEST_CONF2, TEST_DEFAULTS)
68
+ d = Fluent::Plugin::NotifierOutput::Definition.new(gen_conf(TEST_CONF2), @i)
62
69
  assert_equal true, d.match?('field0')
63
70
  assert_equal true, d.match?('field1')
64
71
  assert_equal true, d.match?('field9')
@@ -67,7 +74,7 @@ class NotifierOutputDefinitionTest < Test::Unit::TestCase
67
74
  assert ! d.match?(' field0')
68
75
  assert ! d.match?('field0 ')
69
76
 
70
- d = Fluent::NotifierOutput::Definition.new(TEST_CONF2.merge({'exclude_key_pattern' => '^field[7-9]$'}), TEST_DEFAULTS)
77
+ d = Fluent::Plugin::NotifierOutput::Definition.new(gen_conf(TEST_CONF2.merge({'exclude_key_pattern' => '^field[7-9]$'})), @i)
71
78
  assert_equal true, d.match?('field0')
72
79
  assert_equal true, d.match?('field1')
73
80
  assert ! d.match?('field7')
@@ -77,67 +84,67 @@ class NotifierOutputDefinitionTest < Test::Unit::TestCase
77
84
 
78
85
  def test_check_numeric
79
86
  t = Time.strptime('2012-07-19 14:40:30', '%Y-%m-%d %T')
80
- d = Fluent::NotifierOutput::Definition.new(TEST_CONF1, TEST_DEFAULTS)
87
+ d = Fluent::Plugin::NotifierOutput::Definition.new(gen_conf(TEST_CONF1), @i)
81
88
  r = d.check('test.tag', t.to_i, {'field1' => '0.8', 'field2' => '1.5'}, 'field1')
82
89
  assert_nil r
83
90
 
84
91
  r = d.check('test.tag', t.to_i, {'field1' => '0.8', 'field2' => '1.5'}, 'field2')
85
- assert_equal "name1\ttest.tag\tfield2", r[:hashkey]
86
- assert_equal d, r[:match_def]
87
- assert_equal 'notify', r[:emit_tag]
88
- assert_equal 'name1', r['pattern']
89
- assert_equal 'test.tag', r['target_tag']
90
- assert_equal 'field2', r['target_key']
91
- assert_equal 'numeric_upward', r['check_type']
92
- assert_equal 'warn', r['level']
93
- assert_equal 1.0, r['threshold']
94
- assert_equal 1.5, r['value']
95
- assert_equal t.to_s, r['message_time']
92
+ assert_equal("name1\ttest.tag\tfield2", r[:hashkey])
93
+ assert_equal(d, r[:match_def])
94
+ assert_equal('notify', r[:emit_tag])
95
+ assert_equal('name1', r['pattern'])
96
+ assert_equal('test.tag', r['target_tag'])
97
+ assert_equal('field2', r['target_key'])
98
+ assert_equal('numeric_upward', r['check_type'])
99
+ assert_equal('warn', r['level'])
100
+ assert_equal(1.0, r['threshold'])
101
+ assert_equal(1.5, r['value'])
102
+ assert_equal(t.to_s, r['message_time'])
96
103
 
97
104
  r = d.check('test.tag', t.to_i, {'field1' => '200', 'field2' => '1.5'}, 'field1')
98
- assert_equal "name1\ttest.tag\tfield1", r[:hashkey]
99
- assert_equal d, r[:match_def]
100
- assert_equal 'notify', r[:emit_tag]
101
- assert_equal 'name1', r['pattern']
102
- assert_equal 'test.tag', r['target_tag']
103
- assert_equal 'field1', r['target_key']
104
- assert_equal 'numeric_upward', r['check_type']
105
- assert_equal 'crit', r['level']
106
- assert_equal 2.0, r['threshold']
107
- assert_equal 200.0, r['value']
108
- assert_equal t.to_s, r['message_time']
105
+ assert_equal("name1\ttest.tag\tfield1", r[:hashkey])
106
+ assert_equal(d, r[:match_def])
107
+ assert_equal('notify', r[:emit_tag])
108
+ assert_equal('name1', r['pattern'])
109
+ assert_equal('test.tag', r['target_tag'])
110
+ assert_equal('field1', r['target_key'])
111
+ assert_equal('numeric_upward', r['check_type'])
112
+ assert_equal('crit', r['level'])
113
+ assert_equal(2.0, r['threshold'])
114
+ assert_equal(200.0, r['value'])
115
+ assert_equal(t.to_s, r['message_time'])
109
116
  end
110
117
 
111
118
  def test_check_string
112
119
  t = Time.strptime('2012-07-19 14:40:30', '%Y-%m-%d %T')
113
- d = Fluent::NotifierOutput::Definition.new(TEST_CONF2, TEST_DEFAULTS)
120
+ d = Fluent::Plugin::NotifierOutput::Definition.new(gen_conf(TEST_CONF2), @i)
114
121
  r = d.check('test.tag', t.to_i, {'field0' => 'hoge pos', 'field1' => 'CRIT fooooooo baaaaarrrrrrr'}, 'field0')
115
122
  assert_nil r
116
123
 
117
124
  r = d.check('test.tag', t.to_i, {'field0' => 'hoge pos', 'field1' => 'CRIT fooooooo baaaaarrrrrrr'}, 'field1')
118
- assert_equal "name2\ttest.tag\tfield1", r[:hashkey]
119
- assert_equal d, r[:match_def]
120
- assert_equal 'crit', r[:emit_tag]
121
- assert_equal 'name2', r['pattern']
122
- assert_equal 'test.tag', r['target_tag']
123
- assert_equal 'field1', r['target_key']
124
- assert_equal 'string_find', r['check_type']
125
- assert_equal 'crit', r['level']
126
- assert_equal '/CRIT/', r['regexp']
127
- assert_equal 'CRIT fooooooo baaaaarrrrrrr', r['value']
128
- assert_equal t.to_s, r['message_time']
125
+ assert_equal("name2\ttest.tag\tfield1", r[:hashkey])
126
+ assert_equal(d, r[:match_def])
127
+ assert_equal('crit', r[:emit_tag])
128
+ assert_equal('name2', r['pattern'])
129
+ assert_equal('test.tag', r['target_tag'])
130
+ assert_equal('field1', r['target_key'])
131
+ assert_equal('string_find', r['check_type'])
132
+ assert_equal('crit', r['level'])
133
+ assert_equal('/CRIT/', r['regexp'])
134
+ assert_equal('CRIT fooooooo baaaaarrrrrrr', r['value'])
135
+ assert_equal(t.to_s, r['message_time'])
129
136
 
130
137
  r = d.check('test.tag', t.to_i, {'field0' => 'hoge pos (WARN) check!', 'field1' => 'CRIT fooooooo baaaaarrrrrrr'}, 'field0')
131
- assert_equal "name2\ttest.tag\tfield0", r[:hashkey]
132
- assert_equal d, r[:match_def]
133
- assert_equal 'warn', r[:emit_tag]
134
- assert_equal 'name2', r['pattern']
135
- assert_equal 'test.tag', r['target_tag']
136
- assert_equal 'field0', r['target_key']
137
- assert_equal 'string_find', r['check_type']
138
- assert_equal 'warn', r['level']
139
- assert_equal '/WARN/', r['regexp']
140
- assert_equal 'hoge pos (WARN) check!', r['value']
141
- assert_equal t.to_s, r['message_time']
138
+ assert_equal("name2\ttest.tag\tfield0", r[:hashkey])
139
+ assert_equal(d, r[:match_def])
140
+ assert_equal('warn', r[:emit_tag])
141
+ assert_equal('name2', r['pattern'])
142
+ assert_equal('test.tag', r['target_tag'])
143
+ assert_equal('field0', r['target_key'])
144
+ assert_equal('string_find', r['check_type'])
145
+ assert_equal('warn', r['level'])
146
+ assert_equal('/WARN/', r['regexp'])
147
+ assert_equal('hoge pos (WARN) check!', r['value'])
148
+ assert_equal(t.to_s, r['message_time'])
142
149
  end
143
150
  end
@@ -39,87 +39,100 @@ class NotifierOutputTest < Test::Unit::TestCase
39
39
  </def>
40
40
  ]
41
41
 
42
- def create_driver(conf=CONFIG,tag='test')
43
- Fluent::Test::OutputTestDriver.new(Fluent::NotifierOutput, tag).configure(conf)
42
+ def create_driver(conf = CONFIG)
43
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::NotifierOutput).configure(conf)
44
44
  end
45
45
 
46
46
  def test_configure
47
- d = create_driver
48
- assert_nil nil # no one exception raised
47
+ assert_nothing_raised do
48
+ create_driver
49
+ end
49
50
  end
50
51
 
51
- def test_emit
52
+ test "notify 0 events when num1 < warn_threshold and no test conditions" do
52
53
  d = create_driver
53
- d.run do
54
- d.emit({'num1' => 20, 'message' => 'INFO'})
54
+ d.run(default_tag: "test") do
55
+ d.feed({'num1' => 20, 'message' => 'INFO'})
55
56
  end
56
- assert_equal 0, d.emits.size
57
+ assert_equal(0, d.events.size)
58
+ end
57
59
 
60
+ test "notify 0 events when num1 > warn_threshold but no test conditions are satisfied" do
58
61
  d = create_driver
59
- d.run do
60
- d.emit({'num1' => 30, 'message' => 'INFO'})
62
+ d.run(default_tag: "test") do
63
+ d.feed({'num1' => 30, 'message' => 'INFO'})
61
64
  end
62
- assert_equal 0, d.emits.size
65
+ assert_equal(0, d.events.size)
66
+ end
63
67
 
64
- d = create_driver(CONFIG, 'test.input')
65
- d.run do
66
- d.emit({'num1' => 30, 'message' => 'INFO', 'numfield' => '30', 'textfield' => 'TargetX'})
68
+ test "notify 1 event when num1 > warn_threshold and satisfy test conditions" do
69
+ d = create_driver
70
+ d.run(default_tag: "test.input") do
71
+ d.feed({'num1' => 30, 'message' => 'INFO', 'numfield' => '30', 'textfield' => 'TargetX'})
67
72
  end
68
- assert_equal 1, d.emits.size
69
- assert_equal 'alert.warn', d.emits[0][0]
70
- assert_equal 'pattern1', d.emits[0][2]['pattern']
71
- assert_equal 'input', d.emits[0][2]['target_tag']
72
- assert_equal 'numeric_upward', d.emits[0][2]['check_type']
73
- assert_equal 'warn', d.emits[0][2]['level']
74
- assert_equal 25.0, d.emits[0][2]['threshold']
75
- assert_equal 30.0, d.emits[0][2]['value']
73
+ assert_equal(1, d.events.size)
74
+ assert_equal('alert.warn', d.events[0][0])
75
+ assert_equal('pattern1', d.events[0][2]['pattern'])
76
+ assert_equal('input', d.events[0][2]['target_tag'])
77
+ assert_equal('numeric_upward', d.events[0][2]['check_type'])
78
+ assert_equal('warn', d.events[0][2]['level'])
79
+ assert_equal(25.0, d.events[0][2]['threshold'])
80
+ assert_equal(30.0, d.events[0][2]['value'])
81
+ end
76
82
 
83
+ test "notify 2 events when num1 > crit_threshold and message match warn_regexp" do
77
84
  d = create_driver
78
- d.run do
79
- d.emit({'num1' => 60, 'message' => 'foo bar WARNING xxxxx', 'numfield' => '30', 'textfield' => 'TargetX'})
85
+ d.run(default_tag: "test") do
86
+ d.feed({'num1' => 60, 'message' => 'foo bar WARNING xxxxx', 'numfield' => '30', 'textfield' => 'TargetX'})
80
87
  end
81
- assert_equal 2, d.emits.size
82
- assert_equal 'alert.crit', d.emits[0][0]
83
- assert_equal 'pattern1', d.emits[0][2]['pattern']
84
- assert_equal 'test', d.emits[0][2]['target_tag']
85
- assert_equal 'numeric_upward', d.emits[0][2]['check_type']
86
- assert_equal 'crit', d.emits[0][2]['level']
87
- assert_equal 50.0, d.emits[0][2]['threshold']
88
- assert_equal 60.0, d.emits[0][2]['value']
89
- assert_equal 'alert', d.emits[1][0]
90
- assert_equal 'pattern2', d.emits[1][2]['pattern']
91
- assert_equal 'test', d.emits[1][2]['target_tag']
92
- assert_equal 'string_find', d.emits[1][2]['check_type']
93
- assert_equal 'warn', d.emits[1][2]['level']
94
- assert_equal '/WARNING/', d.emits[1][2]['regexp']
95
- assert_equal 'foo bar WARNING xxxxx', d.emits[1][2]['value']
88
+ assert_equal(2, d.events.size)
89
+ assert_equal('alert.crit', d.events[0][0])
90
+ assert_equal('pattern1', d.events[0][2]['pattern'])
91
+ assert_equal('test', d.events[0][2]['target_tag'])
92
+ assert_equal('numeric_upward', d.events[0][2]['check_type'])
93
+ assert_equal('crit', d.events[0][2]['level'])
94
+ assert_equal(50.0, d.events[0][2]['threshold'])
95
+ assert_equal(60.0, d.events[0][2]['value'])
96
+ assert_equal('alert', d.events[1][0])
97
+ assert_equal('pattern2', d.events[1][2]['pattern'])
98
+ assert_equal('test', d.events[1][2]['target_tag'])
99
+ assert_equal('string_find', d.events[1][2]['check_type'])
100
+ assert_equal('warn', d.events[1][2]['level'])
101
+ assert_equal('/WARNING/', d.events[1][2]['regexp'])
102
+ assert_equal('foo bar WARNING xxxxx', d.events[1][2]['value'])
103
+ end
96
104
 
105
+ test "notify 0 events when test conditions are not satisfied numfield < lower_threshold" do
97
106
  d = create_driver
98
- d.run do
99
- d.emit({'num1' => 60, 'message' => 'foo bar WARNING xxxxx', 'numfield' => '2.4', 'textfield' => 'TargetX'})
107
+ d.run(default_tag: "test") do
108
+ d.feed({'num1' => 60, 'message' => 'foo bar WARNING xxxxx', 'numfield' => '2.4', 'textfield' => 'TargetX'})
100
109
  end
101
- assert_equal 0, d.emits.size
110
+ assert_equal(0, d.events.size)
111
+ end
102
112
 
113
+ test "notify 0 events when test conditions are not satisfied textfield matches exclude_pattern" do
103
114
  d = create_driver
104
- d.run do
105
- d.emit({'num1' => 60, 'message' => 'foo bar WARNING xxxxx', 'numfield' => '20', 'textfield' => 'TargetC'})
115
+ d.run(default_tag: "test") do
116
+ d.feed({'num1' => 60, 'message' => 'foo bar WARNING xxxxx', 'numfield' => '20', 'textfield' => 'TargetC'})
106
117
  end
107
- assert_equal 0, d.emits.size
118
+ assert_equal(0, d.events.size)
119
+ end
108
120
 
121
+ test "notify 0 events when test conditions are not satisfied textfield is missing" do
109
122
  d = create_driver
110
- d.run do
111
- d.emit({'num1' => 60, 'message' => 'foo bar WARNING xxxxx', 'numfield' => '20'})
123
+ d.run(default_tag: "test") do
124
+ d.feed({'num1' => 60, 'message' => 'foo bar WARNING xxxxx', 'numfield' => '20'})
112
125
  end
113
- assert_equal 0, d.emits.size
126
+ assert_equal(0, d.events.size)
114
127
  end
115
128
 
116
129
  def test_emit_invalid_byte
117
130
  invalid_utf8 = "\xff".force_encoding('UTF-8')
118
131
  d = create_driver
119
- assert_nothing_raised {
120
- d.run do
121
- d.emit({'num1' => 60, 'message' => "foo bar WARNING #{invalid_utf8}", 'numfield' => '30', 'textfield' => 'TargetX'})
132
+ assert_nothing_raised do
133
+ d.run(default_tag: "test") do
134
+ d.feed({'num1' => 60, 'message' => "foo bar WARNING #{invalid_utf8}", 'numfield' => '30', 'textfield' => 'TargetX'})
122
135
  end
123
- }
136
+ end
124
137
  end
125
138
  end
@@ -1,12 +1,20 @@
1
1
  require 'helper'
2
+ require 'fluent/test/helpers'
2
3
 
3
4
  class NotifierOutputStateTest < Test::Unit::TestCase
4
- TEST_DEF_DEFAULTS = {
5
- :tag => 'n', :tag_warn => nil, :tag_crit => nil,
6
- :interval_1st => 60, :repetitions_1st => 5,
7
- :interval_2nd => 300, :repetitions_2nd => 5,
8
- :interval_3rd => 1800
9
- }
5
+ include Fluent::Test::Helpers
6
+
7
+ def setup
8
+ Fluent::Test.setup
9
+ @i = Fluent::Plugin::NotifierOutput.new
10
+ @i.configure(config_element())
11
+ end
12
+
13
+ def gen_conf(hash)
14
+ root = @i.configured_section_create(nil, config_element('root', '', {}, [config_element('def', '', hash)]))
15
+ root.def_configs.first
16
+ end
17
+
10
18
  TEST_DEF_CONF1 = {
11
19
  'tag' => 'notify',
12
20
  'pattern' => 'name1', 'target_keys' => 'field1,field2',
@@ -22,55 +30,55 @@ class NotifierOutputStateTest < Test::Unit::TestCase
22
30
  }
23
31
 
24
32
  def test_init
25
- s = Fluent::NotifierOutput::State.new({
33
+ s = Fluent::Plugin::NotifierOutput::State.new({
26
34
  :pattern => 'name1', :target_tag => 'test.tag', :target_key => 'field1', 'level' => 'warn'
27
35
  })
28
- assert_equal 'name1', s.pattern
29
- assert_equal 'test.tag', s.target_tag
30
- assert_equal 'field1', s.target_key
31
- assert_equal 'warn', s.level
32
- assert_equal 0, s.stage
33
- assert_equal 1, s.counter
34
- assert (s.first_notified <= Fluent::Engine.now)
35
- assert (s.last_notified <= Fluent::Engine.now)
36
+ assert_equal('name1', s.pattern)
37
+ assert_equal('test.tag', s.target_tag)
38
+ assert_equal('field1', s.target_key)
39
+ assert_equal('warn', s.level)
40
+ assert_equal(0, s.stage)
41
+ assert_equal(1, s.counter)
42
+ assert { s.first_notified <= Fluent::Engine.now }
43
+ assert { s.last_notified <= Fluent::Engine.now }
36
44
  end
37
45
 
38
46
  def test_suppress?
39
- s = Fluent::NotifierOutput::State.new({
47
+ s = Fluent::Plugin::NotifierOutput::State.new({
40
48
  :pattern => 'name1', :target_tag => 'test.tag', :target_key => 'field1', 'level' => 'warn'
41
49
  })
42
- d = Fluent::NotifierOutput::Definition.new(TEST_DEF_CONF1, TEST_DEF_DEFAULTS)
43
- s.last_notified = Fluent::Engine.now - TEST_DEF_DEFAULTS[:interval_1st] + 5
44
- assert_equal true, s.suppress?(d, {:pattern => 'name1', :target_tag => 'test.tag', :target_key => 'field1', 'level' => 'warn'})
45
- s.last_notified = Fluent::Engine.now - TEST_DEF_DEFAULTS[:interval_1st] - 5
46
- assert_equal false, s.suppress?(d, {:pattern => 'name1', :target_tag => 'test.tag', :target_key => 'field1', 'level' => 'warn'})
50
+ d = Fluent::Plugin::NotifierOutput::Definition.new(gen_conf(TEST_DEF_CONF1), @i)
51
+ s.last_notified = Fluent::Engine.now - @i.default_intervals[0] + 5
52
+ assert_equal(true, s.suppress?(d, {:pattern => 'name1', :target_tag => 'test.tag', :target_key => 'field1', 'level' => 'warn'}))
53
+ s.last_notified = Fluent::Engine.now - @i.default_intervals[0] - 5
54
+ assert_equal(false, s.suppress?(d, {:pattern => 'name1', :target_tag => 'test.tag', :target_key => 'field1', 'level' => 'warn'}))
47
55
 
48
- s = Fluent::NotifierOutput::State.new({
56
+ s = Fluent::Plugin::NotifierOutput::State.new({
49
57
  :pattern => 'name1', :target_tag => 'test.tag', :target_key => 'field1', 'level' => 'warn'
50
58
  })
51
- d = Fluent::NotifierOutput::Definition.new(TEST_DEF_CONF1, TEST_DEF_DEFAULTS)
52
- assert_equal true, s.suppress?(d, {:pattern => 'name1', :target_tag => 'test.tag', :target_key => 'field1', 'level' => 'crit'})
59
+ d = Fluent::Plugin::NotifierOutput::Definition.new(gen_conf(TEST_DEF_CONF1), @i)
60
+ assert_equal(true, s.suppress?(d, {:pattern => 'name1', :target_tag => 'test.tag', :target_key => 'field1', 'level' => 'crit'}))
53
61
  end
54
62
 
55
63
  def test_update_notified
56
- s = Fluent::NotifierOutput::State.new({
64
+ s = Fluent::Plugin::NotifierOutput::State.new({
57
65
  :pattern => 'name2', :target_tag => 'test.tag', :target_key => 'field1', 'level' => 'warn'
58
66
  })
59
- d = Fluent::NotifierOutput::Definition.new(TEST_DEF_CONF2, TEST_DEF_DEFAULTS)
67
+ d = Fluent::Plugin::NotifierOutput::Definition.new(gen_conf(TEST_DEF_CONF2), @i)
60
68
 
61
- assert_equal 0, s.stage
62
- assert_equal 1, s.counter
69
+ assert_equal(0, s.stage)
70
+ assert_equal(1, s.counter)
63
71
 
64
72
  s.update_notified(d, {:pattern => 'name2', :target_tag => 'test.tag', :target_key => 'field1', 'level' => 'warn'})
65
- assert_equal 1, s.stage
66
- assert_equal 0, s.counter
67
-
73
+ assert_equal(1, s.stage)
74
+ assert_equal(0, s.counter)
75
+
68
76
  s.update_notified(d, {:pattern => 'name2', :target_tag => 'test.tag', :target_key => 'field1', 'level' => 'warn'})
69
- assert_equal 1, s.stage
70
- assert_equal 1, s.counter
77
+ assert_equal(1, s.stage)
78
+ assert_equal(1, s.counter)
71
79
 
72
80
  s.update_notified(d, {:pattern => 'name2', :target_tag => 'test.tag', :target_key => 'field1', 'level' => 'crit'})
73
- assert_equal 0, s.stage
74
- assert_equal 1, s.counter
81
+ assert_equal(0, s.stage)
82
+ assert_equal(1, s.counter)
75
83
  end
76
84
  end