Class: Fluent::NotifierOutput::State

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/out_notifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(notification) ⇒ State

Returns a new instance of State.



448
449
450
451
452
453
454
455
456
457
458
# File 'lib/fluent/plugin/out_notifier.rb', line 448

def initialize(notification)
  @pattern = notification[:pattern]
  @target_tag = notification[:target_tag]
  @target_key = notification[:target_key]
  @level = notification['level']
  @stage = 0
  @counter = 1
  t = Fluent::Engine.now
  @first_notified = t
  @last_notified = t
end

Instance Attribute Details

#counterObject

level: :warn, :crit stage: 0(1st)/1(2nd)/2(3rd)



446
447
448
# File 'lib/fluent/plugin/out_notifier.rb', line 446

def counter
  @counter
end

#first_notifiedObject

level: :warn, :crit stage: 0(1st)/1(2nd)/2(3rd)



446
447
448
# File 'lib/fluent/plugin/out_notifier.rb', line 446

def first_notified
  @first_notified
end

#last_notifiedObject

level: :warn, :crit stage: 0(1st)/1(2nd)/2(3rd)



446
447
448
# File 'lib/fluent/plugin/out_notifier.rb', line 446

def last_notified
  @last_notified
end

#levelObject

level: :warn, :crit stage: 0(1st)/1(2nd)/2(3rd)



446
447
448
# File 'lib/fluent/plugin/out_notifier.rb', line 446

def level
  @level
end

#patternObject

level: :warn, :crit stage: 0(1st)/1(2nd)/2(3rd)



446
447
448
# File 'lib/fluent/plugin/out_notifier.rb', line 446

def pattern
  @pattern
end

#stageObject

level: :warn, :crit stage: 0(1st)/1(2nd)/2(3rd)



446
447
448
# File 'lib/fluent/plugin/out_notifier.rb', line 446

def stage
  @stage
end

#target_keyObject

level: :warn, :crit stage: 0(1st)/1(2nd)/2(3rd)



446
447
448
# File 'lib/fluent/plugin/out_notifier.rb', line 446

def target_key
  @target_key
end

#target_tagObject

level: :warn, :crit stage: 0(1st)/1(2nd)/2(3rd)



446
447
448
# File 'lib/fluent/plugin/out_notifier.rb', line 446

def target_tag
  @target_tag
end

Instance Method Details

#suppress?(definition, notification) ⇒ Boolean

Returns:

  • (Boolean)


460
461
462
463
464
465
466
# File 'lib/fluent/plugin/out_notifier.rb', line 460

def suppress?(definition, notification)
  if @level == notification['level']
    (Fluent::Engine.now - @last_notified) <= definition.intervals[@stage]
  else
    true
  end
end

#update_notified(definition, notification) ⇒ Object



468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
# File 'lib/fluent/plugin/out_notifier.rb', line 468

def update_notified(definition, notification)
  t = Fluent::Engine.now

  if @level == notification['level']
    rep = definition.repetitions[@stage]
    if rep and rep > 0
      @counter += 1
      if @counter > rep
        @stage += 1
        @counter = 0
      end
    end
  else
    @level = notification['level']
    @stage = 0
    @counter = 1
    @first_notified = t
  end
  @last_notified = t
end