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

Commit

Permalink
[api_results] avoid altering check "schema"
Browse files Browse the repository at this point in the history
  • Loading branch information
amdprophet committed May 20, 2015
1 parent 7f019bc commit 2059828
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
10 changes: 7 additions & 3 deletions lib/sensu/api/process.rb
Expand Up @@ -736,7 +736,8 @@ def resolve_event(event_json)
checks.each_with_index do |check_name, check_index|
result_key = "result:#{client_name}:#{check_name}"
settings.redis.get(result_key) do |result_json|
response << MultiJson.load(result_json)
check_result = MultiJson.load(result_json)
response << {:client => client_name, :check => check_result}
if client_index == clients.size - 1 && check_index == checks.size - 1
body MultiJson.dump(response)
end
Expand All @@ -760,7 +761,8 @@ def resolve_event(event_json)
checks.each_with_index do |check_name, check_index|
result_key = "result:#{client_name}:#{check_name}"
settings.redis.get(result_key) do |result_json|
response << MultiJson.load(result_json)
check_result = MultiJson.load(result_json)
response << {:client => client_name, :check => check_result}
if check_index == checks.size - 1
body MultiJson.dump(response)
end
Expand All @@ -776,7 +778,9 @@ def resolve_event(event_json)
result_key = "result:#{client_name}:#{check_name}"
settings.redis.get(result_key) do |result_json|
unless result_json.nil?
body result_json
check_result = MultiJson.load(result_json)
response = {:client => client_name, :check => check_result}
body MultiJson.dump(response)
else
not_found!
end
Expand Down
1 change: 0 additions & 1 deletion lib/sensu/server/process.rb
Expand Up @@ -217,7 +217,6 @@ def store_check_result(client, check, &callback)
@redis.sadd("result:#{client[:name]}", check[:name])
result_key = "#{client[:name]}:#{check[:name]}"
check_truncated = check.merge(:output => check[:output][0..256])
check_truncated[:client] = client[:name]
@redis.set("result:#{result_key}", MultiJson.dump(check_truncated)) do
history_key = "history:#{result_key}"
@redis.rpush(history_key, check[:status]) do
Expand Down
6 changes: 3 additions & 3 deletions spec/api/process_spec.rb
Expand Up @@ -840,7 +840,7 @@
expect(http.response_header.status).to eq(200)
expect(body).to be_kind_of(Array)
test_result = Proc.new do |result|
@check
result_template(@check)
end
expect(body).to contain(test_result)
async_done
Expand All @@ -854,7 +854,7 @@
expect(http.response_header.status).to eq(200)
expect(body).to be_kind_of(Array)
test_result = Proc.new do |result|
@check
result_template(@check)
end
expect(body).to contain(test_result)
async_done
Expand All @@ -867,7 +867,7 @@
api_request("/results/i-424242/test") do |http, body|
expect(http.response_header.status).to eq(200)
expect(body).to be_kind_of(Hash)
expect(body).to eq(@check)
expect(body).to eq(result_template(@check))
async_done
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/helpers.rb
Expand Up @@ -112,10 +112,10 @@ def check_template
}
end

def result_template
def result_template(check_result = nil)
{
:client => "i-424242",
:check => check_template
:check => check_result || check_template
}
end

Expand Down

0 comments on commit 2059828

Please sign in to comment.