class Fluent::Plugin::NotifierOutput::Test
Attributes
check[RW]
exclude_pattern[RW]
include_pattern[RW]
lower_threshold[RW]
target_key[RW]
upper_threshold[RW]
Public Class Methods
new(section)
click to toggle source
# 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
Public Instance Methods
test(tag, record)
click to toggle source
# 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