Skip to content
This repository has been archived by the owner on Jan 1, 2020. It is now read-only.

Fix client socket input client signature #1239

Merged
merged 4 commits into from Apr 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/sensu/client/socket.rb
Expand Up @@ -144,8 +144,16 @@ def publish_check_result(check)
:client => @settings[:client][:name],
:check => check.merge(:issued => Time.now.to_i)
}
payload[:signature] = @settings[:client][:signature] if @settings[:client][:signature]
@logger.info("publishing check result", :payload => payload)
@transport.publish(:direct, "results", Sensu::JSON.dump(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

# Process a check result. Set check result attribute defaults,
Expand Down
13 changes: 13 additions & 0 deletions spec/client/socket_spec.rb
Expand Up @@ -85,6 +85,19 @@
end
subject.publish_check_result(check_result[:check])
end

it "publishes check result with client signature" do
subject.settings[:client][:signature] = "foo"
check_result = result_template
check_result[:signature] = "foo"
expect(logger).to receive(:info).
with("publishing check result", {:payload => check_result})
expect(transport).to receive(:publish).
with(:direct, "results", kind_of(String)) do |_, _, json_string|
expect(Sensu::JSON.load(json_string)).to eq(check_result)
end
subject.publish_check_result(check_result[:check])
end
end

describe "#process_check_result" do
Expand Down