Class: Fluent::Plugin::NotifierOutput::Test
- Inherits:
-
Object
- Object
- Fluent::Plugin::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(section) ⇒ Test
constructor
A new instance of Test.
- #test(tag, record) ⇒ Object
Constructor Details
#initialize(section) ⇒ Test
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/fluent/plugin/out_notifier.rb', line 257 def initialize(section) @check = section.check @target_key = section.target_key case @check when :tag if !section.include_pattern && !section.exclude_pattern raise Fluent::ConfigError, "At least one of include_pattern or exclude_pattern must be specified for 'check tag'" end @include_pattern = section.include_pattern ? Regexp.compile(section.include_pattern) : nil @exclude_pattern = section.exclude_pattern ? Regexp.compile(section.exclude_pattern) : nil when :numeric if !section.lower_threshold && !section.upper_threshold raise Fluent::ConfigError, "At least one of lower_threshold or upper_threshold must be specified for 'check numeric'" end raise Fluent::ConfigError, "'target_key' is needed for 'check numeric'" unless @target_key @lower_threshold = section.lower_threshold @upper_threshold = section.upper_threshold when :regexp if !section.include_pattern && !section.exclude_pattern raise Fluent::ConfigError, "At least one of include_pattern or exclude_pattern must be specified for 'check regexp'" end raise Fluent::ConfigError, "'target_key' is needed for 'check regexp'" unless @target_key @include_pattern = section.include_pattern ? Regexp.compile(section.include_pattern) : nil @exclude_pattern = section.exclude_pattern ? Regexp.compile(section.exclude_pattern) : nil else raise "BUG: unknown check: #{@check}" end end |
Instance Attribute Details
#check ⇒ Object
Returns the value of attribute check.
253 254 255 |
# File 'lib/fluent/plugin/out_notifier.rb', line 253 def check @check end |
#exclude_pattern ⇒ Object
Returns the value of attribute exclude_pattern.
255 256 257 |
# File 'lib/fluent/plugin/out_notifier.rb', line 255 def exclude_pattern @exclude_pattern end |
#include_pattern ⇒ Object
Returns the value of attribute include_pattern.
255 256 257 |
# File 'lib/fluent/plugin/out_notifier.rb', line 255 def include_pattern @include_pattern end |
#lower_threshold ⇒ Object
Returns the value of attribute lower_threshold.
254 255 256 |
# File 'lib/fluent/plugin/out_notifier.rb', line 254 def lower_threshold @lower_threshold end |
#target_key ⇒ Object
Returns the value of attribute target_key.
253 254 255 |
# File 'lib/fluent/plugin/out_notifier.rb', line 253 def target_key @target_key end |
#upper_threshold ⇒ Object
Returns the value of attribute upper_threshold.
254 255 256 |
# File 'lib/fluent/plugin/out_notifier.rb', line 254 def upper_threshold @upper_threshold end |
Instance Method Details
#test(tag, record) ⇒ Object
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/fluent/plugin/out_notifier.rb', line 286 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 |