lib/sensu/server/process.rb
def check_history(client, check)
        history_key = "history:#{client[:name]}:#{check[:name]}"
        @redis.lrange(history_key, -21, -1) do |history|
          total_state_change = 0
          unless history.length < 21
            state_changes = 0
            change_weight = 0.8
            previous_status = history.first
            history.each do |status|
              unless status == previous_status
                state_changes += change_weight
              end
              change_weight += 0.02
              previous_status = status
            end
            total_state_change = (state_changes.fdiv(20) * 100).to_i
          end
          @redis.get("#{history_key}:last_ok") do |last_ok|
            last_ok = last_ok.to_i unless last_ok.nil?
            yield(history, total_state_change, last_ok)
          end
        end
      end
# Fetch the execution history for a client/check pair, the 21
# most recent check result statuses. This method also calculates
# the total state change percentage for the history, this value
# is use for check state flap detection, using a similar
# algorithm to Nagios:
# http://nagios.sourceforge.net/docs/3_0/flapping.html
#
# @param client [Hash]
# @param check [Hash]
# @yield [history, total_state_change] callback/block to call
#   with the check history and calculated total state change
#   value.
# @yieldparam history [Array] containing the last 21 check
#   result exit status codes.
# @yieldparam total_state_change [Float] percentage for the
#   check history (exit status codes).
# @yieldparam last_ok [Integer] execution timestamp of the last
#   OK check result.
Fetch the execution history for a client/check pair, the 21
most recent check result statuses.
Fetch the execution history for a client / check pair the 21 most recent check result statuses .
def check_history(client, check)
        history_key = "history:#{client[:name]}:#{check[:name]}"
        @redis.lrange(history_key, -21, -1) do |history|
          total_state_change = 0
          unless history.length < 21
            state_changes = 0
            change_weight = 0.8
            previous_status = history.first
            history.each do |status|
              unless status == previous_status
                state_changes += change_weight
              end
              change_weight += 0.02
              previous_status = status
            end
            total_state_change = (state_changes.fdiv(20) * 100).to_i
          end
          @redis.get("#{history_key}:last_ok") do |last_ok|
            last_ok = last_ok.to_i unless last_ok.nil?
            yield(history, total_state_change, last_ok)
          end
        end
      end
def check_history ( client , check ) history_key = "history:#{client[:name]}:#{check[:name]}" @redis . lrange ( history_key , - 21 , - 1 ) do | history | total_state_change = 0 unless history . length < 21 state_changes = 0 change_weight = 0.8 previous_status = history . first history . each do | status | unless status == previous_status state_changes += change_weight end change_weight += 0.02 previous_status = status end total_state_change = ( state_changes . fdiv ( 20 ) * 100 ) . to_i end @redis . get ( "#{history_key}:last_ok" ) do | last_ok | last_ok = last_ok . to_i unless last_ok . nil? yield ( history , total_state_change , last_ok ) end end end
Fetch the execution history for a client/check pair, the 21
most recent check result statuses.
Fetch the execution history for a client / check pair the 21 most recent check result statuses .
client
check
None
]
callback/block to call with the check history and calculated total state change value.
callback / block to call with the check history and calculated total state change value .
history
containing the last 21 check result exit status codes.
containing the last 21 check result exit status codes .
total_state_change
percentage for the check history (exit status codes).
percentage for the check history ( exit status codes ) .
last_ok
execution timestamp of the last OK check result.
execution timestamp of the last OK check result .