Module: Sensu::API::Routes::Results
- Includes:
- Utilities::PublishCheckResult
- Included in:
- Sensu::API::Routes
- Defined in:
- lib/sensu/api/routes/results.rb
Constant Summary collapse
- RESULTS_URI =
/^\/results$/- RESULTS_CLIENT_URI =
/^\/results\/([\w\.-]+)$/- RESULT_URI =
/^\/results\/([\w\.-]+)\/([\w\.-]+)$/
Instance Method Summary collapse
-
#delete_result ⇒ Object
DELETE /results/:client_name/:check_name.
-
#get_result ⇒ Object
GET /results/:client_name/:check_name.
-
#get_results ⇒ Object
GET /results.
-
#get_results_client ⇒ Object
GET /results/:client_name.
-
#post_results ⇒ Object
POST /results.
Instance Method Details
#delete_result ⇒ Object
DELETE /results/:client_name/:check_name
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/sensu/api/routes/results.rb', line 99 def delete_result client_name, check_name = parse_uri(RESULT_URI) result_key = "result:#{client_name}:#{check_name}" @redis.exists(result_key) do |result_exists| if result_exists @redis.srem("result:#{client_name}", check_name) do @redis.del(result_key) do no_content! end end else not_found! end end end |
#get_result ⇒ Object
GET /results/:client_name/:check_name
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/sensu/api/routes/results.rb', line 84 def get_result client_name, check_name = parse_uri(RESULT_URI) result_key = "result:#{client_name}:#{check_name}" @redis.get(result_key) do |result_json| unless result_json.nil? check = Sensu::JSON.load(result_json) @response_content = {:client => client_name, :check => check} respond else not_found! end end end |
#get_results ⇒ Object
GET /results
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/sensu/api/routes/results.rb', line 29 def get_results @response_content = [] @redis.smembers("clients") do |clients| unless clients.empty? clients.each_with_index do |client_name, client_index| @redis.smembers("result:#{client_name}") do |checks| if !checks.empty? checks.each_with_index do |check_name, check_index| result_key = "result:#{client_name}:#{check_name}" @redis.get(result_key) do |result_json| unless result_json.nil? check = Sensu::JSON.load(result_json) @response_content << {:client => client_name, :check => check} end if client_index == clients.length - 1 && check_index == checks.length - 1 respond end end end elsif client_index == clients.length - 1 respond end end end else respond end end end |
#get_results_client ⇒ Object
GET /results/:client_name
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/sensu/api/routes/results.rb', line 60 def get_results_client client_name = parse_uri(RESULTS_CLIENT_URI).first @response_content = [] @redis.smembers("result:#{client_name}") do |checks| unless checks.empty? checks.each_with_index do |check_name, check_index| result_key = "result:#{client_name}:#{check_name}" @redis.get(result_key) do |result_json| unless result_json.nil? check = Sensu::JSON.load(result_json) @response_content << {:client => client_name, :check => check} end if check_index == checks.length - 1 respond end end end else respond end end end |
#post_results ⇒ Object
POST /results
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sensu/api/routes/results.rb', line 14 def post_results rules = { :name => {:type => String, :nil_ok => false, :regex => /\A[\w\.-]+\z/}, :output => {:type => String, :nil_ok => false}, :status => {:type => Integer, :nil_ok => true}, :source => {:type => String, :nil_ok => true, :regex => /\A[\w\.-]+\z/} } read_data(rules) do |data| publish_check_result("sensu-api", data) @response_content = {:issued => Time.now.to_i} accepted! end end |