Class: Fluent::NotifierOutput::Test
- Inherits:
-
Object
- Object
- Fluent::NotifierOutput::Test
- Defined in:
- lib/fluent/plugin/out_notifier.rb
Instance Attribute Summary collapse
-
#check ⇒ Object
Returns the value of attribute check.
-
#exclude_pattern ⇒ Object
Returns the value of attribute exclude_pattern.
-
#include_pattern ⇒ Object
Returns the value of attribute include_pattern.
-
#lower_threshold ⇒ Object
Returns the value of attribute lower_threshold.
-
#target_key ⇒ Object
Returns the value of attribute target_key.
-
#upper_threshold ⇒ Object
Returns the value of attribute upper_threshold.
Instance Method Summary collapse
-
#initialize(element) ⇒ Test
constructor
A new instance of Test.
- #test(tag, record) ⇒ Object
Constructor Details
#initialize(element) ⇒ Test
Returns a new instance of Test.
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/fluent/plugin/out_notifier.rb', line 218 def initialize(element) element.keys.each do |k| v = element[k] case k when 'check' case v when 'tag' @check = :tag @include_pattern = element['include_pattern'] ? Regexp.compile(element['include_pattern']) : nil @exclude_pattern = element['exclude_pattern'] ? Regexp.compile(element['exclude_pattern']) : nil if @include_pattern.nil? and @exclude_pattern.nil? raise Fluent::ConfigError, "At least one of include_pattern or exclude_pattern must be specified for 'check tag'" end when 'numeric' @check = :numeric @lower_threshold = element['lower_threshold'] ? element['lower_threshold'].to_f : nil @upper_threshold = element['upper_threshold'] ? element['upper_threshold'].to_f : nil if @lower_threshold.nil? and @upper_threshold.nil? raise Fluent::ConfigError, "At least one of lower_threshold or upper_threshold must be specified for 'check numeric'" end when 'regexp' @check = :regexp @include_pattern = element['include_pattern'] ? Regexp.compile(element['include_pattern']) : nil @exclude_pattern = element['exclude_pattern'] ? Regexp.compile(element['exclude_pattern']) : nil if @include_pattern.nil? and @exclude_pattern.nil? raise Fluent::ConfigError, "At least one of include_pattern or exclude_pattern must be specified for 'check regexp'" end else raise Fluent::ConfigError, "invalid check value of test [numeric/regexp]: '#{v}'" end when 'target_key' @target_key = v end end unless @check raise Fluent::ConfigError, "'check' missing in <test> section" end if @target_key.nil? and @check != :tag raise Fluent::ConfigError, "'target_key' missing in <test> section" end end |
Instance Attribute Details
#check ⇒ Object
Returns the value of attribute check.
214 215 216 |
# File 'lib/fluent/plugin/out_notifier.rb', line 214 def check @check end |
#exclude_pattern ⇒ Object
Returns the value of attribute exclude_pattern.
216 217 218 |
# File 'lib/fluent/plugin/out_notifier.rb', line 216 def exclude_pattern @exclude_pattern end |
#include_pattern ⇒ Object
Returns the value of attribute include_pattern.
216 217 218 |
# File 'lib/fluent/plugin/out_notifier.rb', line 216 def include_pattern @include_pattern end |
#lower_threshold ⇒ Object
Returns the value of attribute lower_threshold.
215 216 217 |
# File 'lib/fluent/plugin/out_notifier.rb', line 215 def lower_threshold @lower_threshold end |
#target_key ⇒ Object
Returns the value of attribute target_key.
214 215 216 |
# File 'lib/fluent/plugin/out_notifier.rb', line 214 def target_key @target_key end |
#upper_threshold ⇒ Object
Returns the value of attribute upper_threshold.
215 216 217 |
# File 'lib/fluent/plugin/out_notifier.rb', line 215 def upper_threshold @upper_threshold end |
Instance Method Details
#test(tag, record) ⇒ Object
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/fluent/plugin/out_notifier.rb', line 260 def test(tag, record) v = case @check when :numeric, :regexp record[@target_key] when :tag tag end return false if v.nil? case @check when :numeric v = v.to_f (@lower_threshold.nil? or @lower_threshold <= v) and (@upper_threshold.nil? or v <= @upper_threshold) when :tag, :regexp v = v.to_s.force_encoding('ASCII-8BIT') ((@include_pattern.nil? or @include_pattern.match(v)) and (@exclude_pattern.nil? or (not @exclude_pattern.match(v)))) or false end end |