Module: Sensu::API::Utilities::PublishCheckResult

Included in:
ResolveEvent
Defined in:
lib/sensu/api/utilities/publish_check_result.rb

Instance Method Summary collapse

Instance Method Details

#publish_check_result(client_name, check) ⇒ Object

Publish a check result to the Transport for processing. A check result is composed of a client name and a check definition, containing check ‘:output` and `:status`. A client signature is added to the check result payload if one is registered for the client. JSON serialization is used when publishing the check result payload to the Transport pipe. Transport errors are logged.

Parameters:

  • client_name (String)
  • check (Hash)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sensu/api/utilities/publish_check_result.rb', line 15

def publish_check_result(client_name, check)
  check[:issued] = Time.now.to_i
  check[:executed] = Time.now.to_i
  check[:status] ||= 0
  payload = {
    :client => client_name,
    :check => check
  }
  @redis.get("client:#{client_name}:signature") do |signature|
    payload[:signature] = signature unless signature.nil?
    @logger.info("publishing check result", :payload => payload)
    @transport.publish(:direct, "results", Sensu::JSON.dump(payload)) do |info|
      if info[:error]
        @logger.error("failed to publish check result", {
          :payload => payload,
          :error => info[:error].to_s
        })
      end
    end
  end
end