fluent-plugin-notifier 0.3.0 → 1.0.0
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/.travis.yml +5 -2
- data/Appraisals +3 -0
- data/README.md +13 -8
- data/fluent-plugin-notifier.gemspec +3 -3
- data/gemfiles/fluentd_v0.14.gemfile +7 -0
- data/lib/fluent/plugin/out_notifier.rb +222 -198
- data/test/helper.rb +2 -21
- data/test/plugin/test_def.rb +86 -79
- data/test/plugin/test_out_notifier.rb +65 -52
- data/test/plugin/test_state.rb +43 -35
- data/test/plugin/test_test.rb +103 -91
- metadata +18 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9dff806a4a4e3d1c5301c80cb450e129a3d2a772
|
4
|
+
data.tar.gz: c164675d4de2e69db7c28105439924c8a71b5a3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d1fbf77d6b32db55cf3d9a9712480794fc80ee52a1114b1e749b343c57411e6ed3d077eb7c156946d8181ba104d52b9265151e8ad007df4b7c714fa54bb4c73
|
7
|
+
data.tar.gz: e8ab3552f88d2fb5a870ec4b7d4087d642ea9741166b05a6df5cc029780cd41c55dd38d989fd645b4b99ffbcbca3efdd43fa98349139b194053292985ccc0827
|
data/.travis.yml
CHANGED
data/Appraisals
ADDED
data/README.md
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
# fluent-plugin-notifier
|
2
2
|
|
3
|
-
## Component
|
4
|
-
|
5
|
-
### NotifierOutput
|
6
|
-
|
7
3
|
[Fluentd](http://fluentd.org) plugin to emit notifications for messages, with numbers over/under threshold, or specified pattern strings.
|
8
4
|
|
9
5
|
## Configuration
|
@@ -11,7 +7,8 @@
|
|
11
7
|
To notify apache logs with over 1000000 (microseconds) duration for CRITICAL , or status '500' by string pattern match:
|
12
8
|
|
13
9
|
<match apache.log.**>
|
14
|
-
type notifier
|
10
|
+
@type notifier
|
11
|
+
@label @notification_events
|
15
12
|
<def>
|
16
13
|
pattern apache_duration
|
17
14
|
check numeric_upward
|
@@ -29,7 +26,7 @@ To notify apache logs with over 1000000 (microseconds) duration for CRITICAL , o
|
|
29
26
|
</def>
|
30
27
|
</match>
|
31
28
|
|
32
|
-
With this configuration, you will get notification
|
29
|
+
With this configuration, you will get notification messages in `<label @notification_events>` section, like this:
|
33
30
|
|
34
31
|
2012-05-15 19:44:29 +0900 notification: {"pattern":"apache_duration","target_tag":"apache.log.xxx","target_key":"duration","check_type":"numeric_upward","level":"crit","threshold":1000000,"value":"1057231","message_time":"2012-05-15 19:44:27 +0900"}
|
35
32
|
2012-05-15 19:44:29 +0900 notification: {"pattern":"status_500","target_tag":"apache.log.xxx","target_key":"status","check_type":"string_find","level":"crit","regexp":"/500/","value":"500","message_time":"2012-05-15 19:44:27 +0900"}
|
@@ -55,7 +52,8 @@ If you want to get every 5 minutes notifications (after 1 minutes notifications)
|
|
55
52
|
To include specified messages into check target, or to exclude specified messages from check target, <test> directive is useful.
|
56
53
|
|
57
54
|
<match apache.log.**>
|
58
|
-
type notifier
|
55
|
+
@type notifier
|
56
|
+
@label @notifications
|
59
57
|
<test>
|
60
58
|
check numeric
|
61
59
|
target_key duration # microseconds
|
@@ -70,6 +68,12 @@ To include specified messages into check target, or to exclude specified message
|
|
70
68
|
target_key_pattern ^status.*$
|
71
69
|
</def>
|
72
70
|
</match>
|
71
|
+
|
72
|
+
<label @notifications>
|
73
|
+
<match **>
|
74
|
+
# send notifications to Slack, email or ...
|
75
|
+
</match>
|
76
|
+
</label>
|
73
77
|
|
74
78
|
With configuration above, fluent-plugin-notifier checks messages with specified duration value (d: 5000 <= d <= 5000000), and others are ignored.
|
75
79
|
|
@@ -84,7 +88,8 @@ Available 'check' types are: 'numeric', 'regexp' and 'tag'.
|
|
84
88
|
Multiple <test> directives means logical AND of each tests.
|
85
89
|
|
86
90
|
<match apache.log.**>
|
87
|
-
type notifier
|
91
|
+
@type notifier
|
92
|
+
@label @notifications
|
88
93
|
input_tag_remove_prefix apache.log
|
89
94
|
<test>
|
90
95
|
check tag
|
@@ -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.
|
4
|
+
gem.version = "1.0.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}
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
|
17
|
-
gem.
|
17
|
+
gem.add_runtime_dependency "fluentd", [">= 0.14.0"]
|
18
|
+
gem.add_development_dependency "test-unit", "~> 3.0"
|
18
19
|
gem.add_development_dependency "rake"
|
19
|
-
gem.add_runtime_dependency "fluentd", "< 0.14.0"
|
20
20
|
end
|
@@ -1,89 +1,125 @@
|
|
1
|
-
|
1
|
+
require "fluent/plugin/output"
|
2
|
+
|
3
|
+
class Fluent::Plugin::NotifierOutput < Fluent::Plugin::Output
|
2
4
|
Fluent::Plugin.register_output('notifier', self)
|
3
5
|
|
6
|
+
helpers :event_emitter
|
7
|
+
|
4
8
|
NOTIFICATION_LEVELS = ['OK', 'WARN', 'CRIT', 'LOST'].freeze
|
5
9
|
|
6
10
|
STATES_CLEAN_INTERVAL = 3600 # 1hours
|
7
11
|
STATES_EXPIRE_SECONDS = 14400 # 4hours
|
8
12
|
|
9
|
-
config_param :default_tag, :string, :
|
10
|
-
config_param :default_tag_warn, :string, :
|
11
|
-
config_param :default_tag_crit, :string, :
|
13
|
+
config_param :default_tag, :string, default: 'notification'
|
14
|
+
config_param :default_tag_warn, :string, default: nil
|
15
|
+
config_param :default_tag_crit, :string, default: nil
|
12
16
|
|
13
|
-
config_param :
|
14
|
-
config_param :
|
15
|
-
config_param :default_interval_2nd, :time, :default => 300
|
16
|
-
config_param :default_repetitions_2nd, :integer, :default => 5
|
17
|
-
config_param :default_interval_3rd, :time, :default => 1800
|
17
|
+
config_param :default_intervals, :array, value_type: :time, default: [60, 300, 1800]
|
18
|
+
config_param :default_repetitions, :array, value_type: :integer, default: [5, 5]
|
18
19
|
|
19
|
-
config_param :
|
20
|
+
config_param :default_interval_1st, :time, default: nil
|
21
|
+
config_param :default_interval_2nd, :time, default: nil
|
22
|
+
config_param :default_interval_3rd, :time, default: nil
|
23
|
+
config_param :default_repetitions_1st, :integer, default: nil
|
24
|
+
config_param :default_repetitions_2nd, :integer, default: nil
|
20
25
|
|
21
|
-
|
26
|
+
config_param :input_tag_remove_prefix, :string, default: nil
|
22
27
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
# 'threshold' => 25, # or 'regexp' => ....,
|
31
|
-
# 'value' => 49, # or 'value' => 'matched some string...',
|
32
|
-
# 'message_time' => Time.instance
|
33
|
-
# }
|
34
|
-
|
35
|
-
# <match httpstatus.blog>
|
36
|
-
# type notifier
|
37
|
-
# default_tag notification
|
38
|
-
# default_interval_1st 1m
|
39
|
-
# default_repetitions_1st 5
|
40
|
-
# default_interval_2nd 5m
|
41
|
-
# default_repetitions_2nd 5
|
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>
|
55
|
-
# <def>
|
56
|
-
# pattern http_status_errors
|
57
|
-
# check numeric_upward
|
58
|
-
# warn_threshold 25
|
59
|
-
# crit_threshold 50
|
60
|
-
# tag alert
|
61
|
-
# # tag_warn alert.warn
|
62
|
-
# # tag_crit alert.crit
|
63
|
-
# # target_keys blog_5xx_percentage
|
64
|
-
# target_key_pattern ^.*_5xx_percentage$
|
65
|
-
# </def>
|
66
|
-
# <def>
|
67
|
-
# pattern log_checker
|
68
|
-
# check string_find
|
69
|
-
# crit_pattern 'ERROR'
|
70
|
-
# warn_pattern 'WARNING'
|
71
|
-
# tag alert
|
72
|
-
# # target_keys message
|
73
|
-
# target_key_pattern ^.*_message$
|
74
|
-
# </def>
|
75
|
-
# </match>
|
76
|
-
|
77
|
-
# Define `log` method for v0.10.42 or earlier
|
78
|
-
unless method_defined?(:log)
|
79
|
-
define_method("log") { $log }
|
28
|
+
config_section :test, multi: true, param_name: :test_configs do
|
29
|
+
config_param :check, :enum, list: [:tag, :numeric, :regexp]
|
30
|
+
config_param :target_key, :string, default: nil
|
31
|
+
config_param :lower_threshold, :float, default: nil
|
32
|
+
config_param :upper_threshold, :float, default: nil
|
33
|
+
config_param :include_pattern, :string, default: nil
|
34
|
+
config_param :exclude_pattern, :string, default: nil
|
80
35
|
end
|
81
36
|
|
82
|
-
|
83
|
-
|
84
|
-
|
37
|
+
config_section :def, multi: true, param_name: :def_configs do
|
38
|
+
config_param :pattern, :string
|
39
|
+
config_param :check, :enum, list: [:numeric_upward, :numeric_downward, :string_find]
|
40
|
+
|
41
|
+
config_param :target_keys, :array, value_type: :string, default: nil
|
42
|
+
config_param :target_key_pattern, :string, default: nil
|
43
|
+
config_param :exclude_key_pattern, :string, default: '^$'
|
44
|
+
|
45
|
+
config_param :tag, :string, default: nil
|
46
|
+
config_param :tag_warn, :string, default: nil
|
47
|
+
config_param :tag_crit, :string, default: nil
|
48
|
+
|
49
|
+
# numeric_upward/downward
|
50
|
+
config_param :crit_threshold, :float, default: nil
|
51
|
+
config_param :warn_threshold, :float, default: nil
|
52
|
+
|
53
|
+
# string_find
|
54
|
+
config_param :crit_regexp, :string, default: nil
|
55
|
+
config_param :warn_regexp, :string, default: nil
|
56
|
+
|
57
|
+
# repeat & interval
|
58
|
+
config_param :intervals, :array, value_type: :time, default: nil
|
59
|
+
config_param :interval_1st, :time, default: nil
|
60
|
+
config_param :interval_2nd, :time, default: nil
|
61
|
+
config_param :interval_3rd, :time, default: nil
|
62
|
+
config_param :repetitions, :array, value_type: :integer, default: nil
|
63
|
+
config_param :repetitions_1st, :integer, default: nil
|
64
|
+
config_param :repetitions_2nd, :integer, default: nil
|
85
65
|
end
|
86
66
|
|
67
|
+
attr_accessor :tests, :defs, :states, :match_cache, :negative_cache
|
68
|
+
|
69
|
+
### output
|
70
|
+
# {
|
71
|
+
# 'pattern' => 'http_status_errors',
|
72
|
+
# 'target_tag' => 'httpstatus.blog',
|
73
|
+
# 'target_key' => 'blog_5xx_percentage',
|
74
|
+
# 'check_type' => 'numeric_upward'
|
75
|
+
# 'level' => 'warn',
|
76
|
+
# 'threshold' => 25, # or 'regexp' => ....,
|
77
|
+
# 'value' => 49, # or 'value' => 'matched some string...',
|
78
|
+
# 'message_time' => Time.instance
|
79
|
+
# }
|
80
|
+
|
81
|
+
# <match httpstatus.blog>
|
82
|
+
# type notifier
|
83
|
+
# default_tag notification
|
84
|
+
# default_interval_1st 1m
|
85
|
+
# default_repetitions_1st 5
|
86
|
+
# default_interval_2nd 5m
|
87
|
+
# default_repetitions_2nd 5
|
88
|
+
# default_interval_3rd 30m
|
89
|
+
# <test>
|
90
|
+
# check numeric
|
91
|
+
# target_key xxx
|
92
|
+
# lower_threshold xxx
|
93
|
+
# upper_threshold xxx
|
94
|
+
# </test>
|
95
|
+
# <test>
|
96
|
+
# check regexp
|
97
|
+
# target_key xxx
|
98
|
+
# include_pattern ^.$
|
99
|
+
# exclude_pattern ^.$
|
100
|
+
# </test>
|
101
|
+
# <def>
|
102
|
+
# pattern http_status_errors
|
103
|
+
# check numeric_upward
|
104
|
+
# warn_threshold 25
|
105
|
+
# crit_threshold 50
|
106
|
+
# tag alert
|
107
|
+
# # tag_warn alert.warn
|
108
|
+
# # tag_crit alert.crit
|
109
|
+
# # target_keys blog_5xx_percentage
|
110
|
+
# target_key_pattern ^.*_5xx_percentage$
|
111
|
+
# </def>
|
112
|
+
# <def>
|
113
|
+
# pattern log_checker
|
114
|
+
# check string_find
|
115
|
+
# crit_pattern 'ERROR'
|
116
|
+
# warn_pattern 'WARNING'
|
117
|
+
# tag alert
|
118
|
+
# # target_keys message
|
119
|
+
# target_key_pattern ^.*_message$
|
120
|
+
# </def>
|
121
|
+
# </match>
|
122
|
+
|
87
123
|
def configure(conf)
|
88
124
|
super
|
89
125
|
|
@@ -98,35 +134,40 @@ class Fluent::NotifierOutput < Fluent::Output
|
|
98
134
|
@input_tag_remove_prefix_length = @input_tag_remove_prefix_string.length
|
99
135
|
end
|
100
136
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
@
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
137
|
+
if @default_interval_1st || @default_interval_2nd || @default_interval_3rd
|
138
|
+
@default_intervals = [
|
139
|
+
@default_interval_1st || @default_intervals[0],
|
140
|
+
@default_interval_2nd || @default_intervals[1],
|
141
|
+
@default_interval_3rd || @default_intervals[2],
|
142
|
+
]
|
143
|
+
end
|
144
|
+
if @default_repetitions_1st || @default_repetitions_2nd
|
145
|
+
@default_repetitions = [
|
146
|
+
@default_repetitions_1st || @default_repetitions[0],
|
147
|
+
@default_repetitions_2nd || @default_repetitions[1],
|
148
|
+
]
|
149
|
+
end
|
150
|
+
|
151
|
+
@test_configs.each do |test_config|
|
152
|
+
@tests << Test.new(test_config)
|
153
|
+
end
|
154
|
+
@def_configs.each do |def_config|
|
155
|
+
@defs << Definition.new(def_config, self)
|
117
156
|
end
|
118
157
|
end
|
119
158
|
|
159
|
+
def multi_workers_ready?
|
160
|
+
true
|
161
|
+
end
|
162
|
+
|
120
163
|
def start
|
121
164
|
super
|
122
165
|
@mutex = Mutex.new
|
123
166
|
@last_status_cleaned = Fluent::Engine.now
|
124
167
|
end
|
125
168
|
|
126
|
-
# def shutdown
|
127
|
-
# end
|
128
|
-
|
129
169
|
def suppressed_emit(notifications)
|
170
|
+
now = Fluent::Engine.now
|
130
171
|
notifications.each do |n|
|
131
172
|
hashkey = n.delete(:hashkey)
|
132
173
|
definition = n.delete(:match_def)
|
@@ -135,11 +176,11 @@ class Fluent::NotifierOutput < Fluent::Output
|
|
135
176
|
state = @states[hashkey]
|
136
177
|
if state
|
137
178
|
unless state.suppress?(definition, n)
|
138
|
-
router.emit(tag,
|
179
|
+
router.emit(tag, now, n)
|
139
180
|
state.update_notified(definition, n)
|
140
181
|
end
|
141
182
|
else
|
142
|
-
router.emit(tag,
|
183
|
+
router.emit(tag, now, n)
|
143
184
|
@states[hashkey] = State.new(n)
|
144
185
|
end
|
145
186
|
end
|
@@ -191,7 +232,7 @@ class Fluent::NotifierOutput < Fluent::Output
|
|
191
232
|
notifications
|
192
233
|
end
|
193
234
|
|
194
|
-
def
|
235
|
+
def process(tag, es)
|
195
236
|
notifications = check(tag, es)
|
196
237
|
|
197
238
|
if notifications.size > 0
|
@@ -206,8 +247,6 @@ class Fluent::NotifierOutput < Fluent::Output
|
|
206
247
|
@last_status_cleaned = Fluent::Engine.now
|
207
248
|
end
|
208
249
|
end
|
209
|
-
|
210
|
-
chain.next
|
211
250
|
end
|
212
251
|
|
213
252
|
class Test
|
@@ -215,45 +254,32 @@ class Fluent::NotifierOutput < Fluent::Output
|
|
215
254
|
attr_accessor :lower_threshold, :upper_threshold
|
216
255
|
attr_accessor :include_pattern, :exclude_pattern
|
217
256
|
|
218
|
-
def initialize(
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
@check = :tag
|
226
|
-
@include_pattern = element['include_pattern'] ? Regexp.compile(element['include_pattern']) : nil
|
227
|
-
@exclude_pattern = element['exclude_pattern'] ? Regexp.compile(element['exclude_pattern']) : nil
|
228
|
-
if @include_pattern.nil? and @exclude_pattern.nil?
|
229
|
-
raise Fluent::ConfigError, "At least one of include_pattern or exclude_pattern must be specified for 'check tag'"
|
230
|
-
end
|
231
|
-
when 'numeric'
|
232
|
-
@check = :numeric
|
233
|
-
@lower_threshold = element['lower_threshold'] ? element['lower_threshold'].to_f : nil
|
234
|
-
@upper_threshold = element['upper_threshold'] ? element['upper_threshold'].to_f : nil
|
235
|
-
if @lower_threshold.nil? and @upper_threshold.nil?
|
236
|
-
raise Fluent::ConfigError, "At least one of lower_threshold or upper_threshold must be specified for 'check numeric'"
|
237
|
-
end
|
238
|
-
when 'regexp'
|
239
|
-
@check = :regexp
|
240
|
-
@include_pattern = element['include_pattern'] ? Regexp.compile(element['include_pattern']) : nil
|
241
|
-
@exclude_pattern = element['exclude_pattern'] ? Regexp.compile(element['exclude_pattern']) : nil
|
242
|
-
if @include_pattern.nil? and @exclude_pattern.nil?
|
243
|
-
raise Fluent::ConfigError, "At least one of include_pattern or exclude_pattern must be specified for 'check regexp'"
|
244
|
-
end
|
245
|
-
else
|
246
|
-
raise Fluent::ConfigError, "invalid check value of test [numeric/regexp]: '#{v}'"
|
247
|
-
end
|
248
|
-
when 'target_key'
|
249
|
-
@target_key = v
|
257
|
+
def initialize(section)
|
258
|
+
@check = section.check
|
259
|
+
@target_key = section.target_key
|
260
|
+
case @check
|
261
|
+
when :tag
|
262
|
+
if !section.include_pattern && !section.exclude_pattern
|
263
|
+
raise Fluent::ConfigError, "At least one of include_pattern or exclude_pattern must be specified for 'check tag'"
|
250
264
|
end
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
265
|
+
@include_pattern = section.include_pattern ? Regexp.compile(section.include_pattern) : nil
|
266
|
+
@exclude_pattern = section.exclude_pattern ? Regexp.compile(section.exclude_pattern) : nil
|
267
|
+
when :numeric
|
268
|
+
if !section.lower_threshold && !section.upper_threshold
|
269
|
+
raise Fluent::ConfigError, "At least one of lower_threshold or upper_threshold must be specified for 'check numeric'"
|
270
|
+
end
|
271
|
+
raise Fluent::ConfigError, "'target_key' is needed for 'check numeric'" unless @target_key
|
272
|
+
@lower_threshold = section.lower_threshold
|
273
|
+
@upper_threshold = section.upper_threshold
|
274
|
+
when :regexp
|
275
|
+
if !section.include_pattern && !section.exclude_pattern
|
276
|
+
raise Fluent::ConfigError, "At least one of include_pattern or exclude_pattern must be specified for 'check regexp'"
|
277
|
+
end
|
278
|
+
raise Fluent::ConfigError, "'target_key' is needed for 'check regexp'" unless @target_key
|
279
|
+
@include_pattern = section.include_pattern ? Regexp.compile(section.include_pattern) : nil
|
280
|
+
@exclude_pattern = section.exclude_pattern ? Regexp.compile(section.exclude_pattern) : nil
|
281
|
+
else
|
282
|
+
raise "BUG: unknown check: #{@check}"
|
257
283
|
end
|
258
284
|
end
|
259
285
|
|
@@ -280,66 +306,64 @@ class Fluent::NotifierOutput < Fluent::Output
|
|
280
306
|
class Definition
|
281
307
|
attr_accessor :tag, :tag_warn, :tag_crit
|
282
308
|
attr_accessor :intervals, :repetitions
|
283
|
-
attr_accessor :pattern, :
|
309
|
+
attr_accessor :pattern, :target_keys, :target_key_pattern, :exclude_key_pattern
|
284
310
|
attr_accessor :crit_threshold, :warn_threshold # for 'numeric_upward', 'numeric_downward'
|
285
311
|
attr_accessor :crit_regexp, :warn_regexp # for 'string_find'
|
286
312
|
|
287
|
-
def initialize(
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
@crit_threshold = element['crit_threshold'].to_f
|
300
|
-
@warn_threshold = element['warn_threshold'].to_f
|
301
|
-
when 'numeric_downward'
|
302
|
-
@check = :downward
|
303
|
-
unless element.has_key?('crit_threshold') and element.has_key?('warn_threshold')
|
304
|
-
raise Fluent::ConfigError, "Both of crit_threshold and warn_threshold must be specified for 'check_numeric_downward'"
|
305
|
-
end
|
306
|
-
@crit_threshold = element['crit_threshold'].to_f
|
307
|
-
@warn_threshold = element['warn_threshold'].to_f
|
308
|
-
when 'string_find'
|
309
|
-
@check = :find
|
310
|
-
unless element.has_key?('crit_regexp') and element.has_key?('warn_regexp')
|
311
|
-
raise Fluent::ConfigError, "Both of crit_regexp and warn_regexp must be specified for 'check string_find'"
|
312
|
-
end
|
313
|
-
@crit_regexp = Regexp.compile(element['crit_regexp'].to_s)
|
314
|
-
@warn_regexp = Regexp.compile(element['warn_regexp'].to_s)
|
315
|
-
else
|
316
|
-
raise Fluent::ConfigError, "invalid check type: #{element[k]}"
|
317
|
-
end
|
318
|
-
when 'target_keys'
|
319
|
-
@target_keys = element['target_keys'].split(',')
|
320
|
-
when 'target_key_pattern'
|
321
|
-
@target_key_pattern = Regexp.compile(element['target_key_pattern'])
|
322
|
-
@exclude_key_pattern = Regexp.compile(element['exclude_key_pattern'] || '^$')
|
323
|
-
end
|
324
|
-
end
|
325
|
-
if @pattern.nil? or @pattern.length < 1
|
326
|
-
raise Fluent::ConfigError, "pattern must be set"
|
313
|
+
def initialize(section, plugin)
|
314
|
+
@pattern = section.pattern
|
315
|
+
|
316
|
+
@tag = section.tag || plugin.default_tag
|
317
|
+
@tag_warn = section.tag_warn || plugin.default_tag_warn
|
318
|
+
@tag_crit = section.tag_crit || plugin.default_tag_crit
|
319
|
+
|
320
|
+
@target_keys = section.target_keys
|
321
|
+
@target_key_pattern = section.target_key_pattern ? Regexp.compile(section.target_key_pattern) : nil
|
322
|
+
@exclude_key_pattern = section.exclude_key_pattern ? Regexp.compile(section.exclude_key_pattern) : nil
|
323
|
+
if !@target_keys and !@target_key_pattern
|
324
|
+
raise Fluent::ConfigError, "out_notifier needs one of target_keys or target_key_pattern in <def>"
|
327
325
|
end
|
328
|
-
|
329
|
-
|
326
|
+
|
327
|
+
case section.check
|
328
|
+
when :numeric_upward
|
329
|
+
@check = :upward
|
330
|
+
if !section.crit_threshold || !section.warn_threshold
|
331
|
+
raise Fluent::ConfigError, "Both of crit_threshold and warn_threshold must be specified for 'check numeric_upward'"
|
332
|
+
end
|
333
|
+
@crit_threshold = section.crit_threshold
|
334
|
+
@warn_threshold = section.warn_threshold
|
335
|
+
when :numeric_downward
|
336
|
+
@check = :downward
|
337
|
+
if !section.crit_threshold || !section.warn_threshold
|
338
|
+
raise Fluent::ConfigError, "Both of crit_threshold and warn_threshold must be specified for 'check numeric_downward'"
|
339
|
+
end
|
340
|
+
@crit_threshold = section.crit_threshold
|
341
|
+
@warn_threshold = section.warn_threshold
|
342
|
+
when :string_find
|
343
|
+
@check = :find
|
344
|
+
if !section.crit_regexp || !section.warn_regexp
|
345
|
+
raise Fluent::ConfigError, "Both of crit_regexp and warn_regexp must be specified for 'check string_find'"
|
346
|
+
end
|
347
|
+
@crit_regexp = Regexp.compile(section.crit_regexp)
|
348
|
+
@warn_regexp = Regexp.compile(section.warn_regexp)
|
349
|
+
else
|
350
|
+
raise "BUG: unknown check: #{section.check}"
|
330
351
|
end
|
331
|
-
|
332
|
-
@
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
@repetitions =
|
340
|
-
|
341
|
-
|
342
|
-
|
352
|
+
|
353
|
+
@intervals = if section.intervals
|
354
|
+
section.intervals
|
355
|
+
elsif section.interval_1st || section.interval_2nd || section.interval_3rd
|
356
|
+
[section.interval_1st || plugin.default_intervals[0], section.interval_2nd || plugin.default_intervals[1], section.interval_3rd || plugin.default_intervals[2]]
|
357
|
+
else
|
358
|
+
plugin.default_intervals
|
359
|
+
end
|
360
|
+
@repetitions = if section.repetitions
|
361
|
+
section.repetitions
|
362
|
+
elsif section.repetitions_1st || section.repetitions_2nd
|
363
|
+
[section.repetitions_1st || plugin.default_repetitions[0], section.repetitions_2nd || plugin.default_repetitions[1]]
|
364
|
+
else
|
365
|
+
plugin.default_repetitions
|
366
|
+
end
|
343
367
|
end
|
344
368
|
|
345
369
|
def match?(key)
|
@@ -350,16 +374,16 @@ class Fluent::NotifierOutput < Fluent::Output
|
|
350
374
|
end
|
351
375
|
end
|
352
376
|
|
353
|
-
# {
|
354
|
-
# 'pattern' => 'http_status_errors',
|
355
|
-
# 'target_tag' => 'httpstatus.blog',
|
356
|
-
# 'target_key' => 'blog_5xx_percentage',
|
357
|
-
# 'check_type' => 'numeric_upward'
|
358
|
-
# 'level' => 'warn', # 'regexp' => '[WARN] .* MUST BE CHECKED!$'
|
359
|
-
# 'threshold' => 25,
|
360
|
-
# 'value' => 49, # 'value' => '2012/05/15 18:01:59 [WARN] wooooops, MUST BE CHECKED!'
|
361
|
-
# 'message_time' => Time.instance
|
362
|
-
# }
|
377
|
+
# {
|
378
|
+
# 'pattern' => 'http_status_errors',
|
379
|
+
# 'target_tag' => 'httpstatus.blog',
|
380
|
+
# 'target_key' => 'blog_5xx_percentage',
|
381
|
+
# 'check_type' => 'numeric_upward'
|
382
|
+
# 'level' => 'warn', # 'regexp' => '[WARN] .* MUST BE CHECKED!$'
|
383
|
+
# 'threshold' => 25,
|
384
|
+
# 'value' => 49, # 'value' => '2012/05/15 18:01:59 [WARN] wooooops, MUST BE CHECKED!'
|
385
|
+
# 'message_time' => Time.instance
|
386
|
+
# }
|
363
387
|
def check(tag, time, record, key)
|
364
388
|
case @check
|
365
389
|
when :upward
|