Permalink
Browse files

Support both html and json output for statuses

  • Loading branch information...
1 parent 2252889 commit b88078d8481cabab9d989be8497a9dc6ae9446a6 @sosedoff sosedoff committed Oct 24, 2012
Showing with 27 additions and 3 deletions.
  1. +17 −3 app/controllers/status_controller.rb
  2. +9 −0 app/models/ping.rb
  3. +1 −0 config/routes.rb
View
20 app/controllers/status_controller.rb
@@ -1,15 +1,29 @@
class StatusController < ApplicationController
+ before_filter :load_services
+
def show
- @pings = Ping.all.sort_by { |x| x.service }
+ respond_to do |f|
+ f.html { render }
+ f.json { render :json => json_status }
+ end
+ end
- crit = @pings.any? { |x| x.down? and x.critical? }
+ private
+
+ def load_services
+ @pings = Ping.all.sort_by { |x| x.service }
+ critical = @pings.any? { |x| x.down? and x.critical? }
if @pings.empty?
@status = "unknown"
- elsif crit
+ elsif critical
@status = "down"
else
@status = @pings.any? { |x| x.down? } ? "partial" : "up"
end
end
+
+ def json_status
+ {:status => @status, :services => @pings}
+ end
end
View
9 app/models/ping.rb
@@ -19,4 +19,13 @@ def state
return "unknown" if unknown?
status
end
+
+ def as_json(options={})
+ {
+ :name => service,
+ :description => description,
+ :status => status,
+ :last_update => last_seen
+ }
+ end
end
View
1 config/routes.rb
@@ -1,3 +1,4 @@
RubygemsStatus::Application.routes.draw do
root :to => 'status#show'
+ get 'status' => 'status#show'
end

0 comments on commit b88078d

Please sign in to comment.