lib/sensu/server/process.rb
# Create an event, using the provided client and check result
# data. Existing event data for the client/check pair is fetched
# from the event registry to be used in the composition of the
# new event. The silenced registry is used to determine if the
# event has been silenced.
#
# @param client [Hash]
# @param check [Hash]
# @yield callback [event] callback/block called with the
#   resulting event.
# @yieldparam event [Hash]
Create an event, using the provided client and check result
data. Existing event data for the client/check pair is fetched
from the event registry to be used in the composition of the
new event. The silenced registry is used to determine if the
event has been silenced.
Create an event using the provided client and check result data . Existing event data for the client / check pair is fetched from the event registry to be used in the composition of the new event . The silenced registry is used to determine if the event has been silenced .
def create_event(client, check)
        check_history(client, check) do |history, total_state_change, last_ok|
          check[:history] = history
          check[:total_state_change] = total_state_change
          @redis.hget("events:#{client[:name]}", check[:name]) do |event_json|
            stored_event = event_json ? Sensu::JSON.load(event_json) : nil
            flapping = check_flapping?(stored_event, check)
            event = {
              :id => random_uuid,
              :client => client,
              :check => check,
              :occurrences => 1,
              :occurrences_watermark => 1,
              :last_ok => last_ok,
              :action => (flapping ? :flapping : :create),
              :timestamp => Time.now.to_i
            }
            if stored_event
              event[:id] = stored_event[:id]
              event[:last_state_change] = stored_event[:last_state_change]
              event[:occurrences] = stored_event[:occurrences]
              event[:occurrences_watermark] = stored_event[:occurrences_watermark] || event[:occurrences]
            end
            if check[:status] != 0 || flapping
              if history[-1] == history[-2]
                event[:occurrences] += 1
                if event[:occurrences] > event[:occurrences_watermark]
                  event[:occurrences_watermark] = event[:occurrences]
                end
              else
                event[:occurrences] = 1
                event[:last_state_change] = event[:timestamp]
              end
            elsif stored_event
              event[:last_state_change] = event[:timestamp]
              event[:action] = :resolve
            end
            event_silenced?(event) do |event|
              yield(event)
            end
          end
        end
      end
def create_event ( client , check ) check_history ( client , check ) do | history , total_state_change , last_ok | check [ :history ] = history check [ :total_state_change ] = total_state_change @redis . hget ( "events:#{client[:name]}" , check [ :name ] ) do | event_json | stored_event = event_json ? Sensu :: JSON . load ( event_json ) : nil flapping = check_flapping? ( stored_event , check ) event = { :id => random_uuid , :client => client , :check => check , :occurrences => 1 , :occurrences_watermark => 1 , :last_ok => last_ok , :action => ( flapping ? :flapping : :create ) , :timestamp => Time . now . to_i } if stored_event event [ :id ] = stored_event [ :id ] event [ :last_state_change ] = stored_event [ :last_state_change ] event [ :occurrences ] = stored_event [ :occurrences ] event [ :occurrences_watermark ] = stored_event [ :occurrences_watermark ] || event [ :occurrences ] end if check [ :status ] != 0 || flapping if history [ - 1 ] == history [ - 2 ] event [ :occurrences ] += 1 if event [ :occurrences ] > event [ :occurrences_watermark ] event [ :occurrences_watermark ] = event [ :occurrences ] end else event [ :occurrences ] = 1 event [ :last_state_change ] = event [ :timestamp ] end elsif stored_event event [ :last_state_change ] = event [ :timestamp ] event [ :action ] = :resolve end event_silenced? ( event ) do | event | yield ( event ) end end end end
Create an event, using the provided client and check result
data.
Create an event using the provided client and check result data .
client
check
None
]
callback  callback/block called with the resulting event.
callback callback / block called with the resulting event .