Sha256: 8b8c7db3884e3940e92d31fce857dae15708a2f5b7cfe1c4d545645d9abeb829
Contents?: true
Size: 1.45 KB
Versions: 4
Compression:
Stored size: 1.45 KB
Contents
module LitmusPaper class App < Sinatra::Base get "/" do output = "Services monitored:\n" output += LitmusPaper.services.keys.join("\n") text 200, output end post "/force/*" do path = *status_file_path(params[:splat]) statusfile = StatusFile.new(*path) statusfile.create(params[:reason]) text 201, "File created" end delete "/force/*" do path = *status_file_path(params[:splat]) statusfile = StatusFile.new(*path) if statusfile.exists? statusfile.delete text 200, "File deleted" else text 404, "NOT FOUND" end end get "/:service/status" do service = LitmusPaper.services[params[:service]] if service.nil? text 404, "NOT FOUND", { "X-Health" => "0" } else health = service.current_health response_code = health.ok? ? 200 : 503 body = "Health: #{health.value}\n" body << health.summary text response_code, body, { "X-Health" => health.value.to_s } end end get "/test/error" do raise "an error" end error do text 500, "Server Error" end def text(response_code, body, headers ={}) [response_code, { "Content-Type" => "text/plain" }.merge(headers), body] end def status_file_path(splat) path = splat.first.split("/") if path.size == 1 ["global_#{path.first}"] else path end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
litmus_paper-0.3.1 | lib/litmus_paper/app.rb |
litmus_paper-0.3.0 | lib/litmus_paper/app.rb |
litmus_paper-0.1.0 | lib/litmus_paper/app.rb |
litmus_paper-0.0.3 | lib/litmus_paper/app.rb |