Sha256: 6f1b88149c7badaa5c4690218d9e0b1641f4f7647286b73af9e97cbff61a7b79

Contents?: true

Size: 1.65 KB

Versions: 26

Compression:

Stored size: 1.65 KB

Contents

class Server
	
	def call(env)
		
		parms = Rack::Request.new(env).params.merge(env["rack.routing_args"]).inject({}){|acc,(k,v)| acc[k.to_sym] = v; acc}
		server = parms[:server]
		
		output = CityWatch.header << '<h1>' << server << "</h1>"
		Watchmen.each do |watchman|
			flags = watchman.get_flags(server)
			alerts = watchman.get_alerts(server,2)
			if (flags && flags.count > 0) || (alerts && alerts.count > 0)
				output << "<h3>" << watchman.name.to_s << "</h3><ul>"
				if flags && flags.count > 0
					output << "<li class=\"alert\"><strong>Flags:</strong> <pre><code>" << Yajl::Encoder.encode(flags,:pretty => true, :indent => "   ") << "</code></pre></li>"
				end
				if alerts && alerts.count > 0
					output << "<li class=\"alert\"><strong>Alerts:</strong></li>"
					alerts.each do |alert|
						output << "<li><pre><code>" << Yajl::Encoder.encode(Yajl::Parser.parse(alert),:pretty => true, :indent => "   ") << "</code></pre></li>"
					end
				end
				output << "</ul>"
			end
		end
		output << "<ol>"
		CityWatch.redis.zrevrange("#{CityWatch.config[:prefix]}::#{server}::raw_stats",0,10).each do |update|
			dat = Yajl::Parser.new(:symbolize_keys => true).parse(update)
			output << "<li><h4>" << dat[:received_at] << "</h4><ul>"
			dat[:watchmen].each do |name,datr|
				output << "<li><strong>" << name.to_s << ":</strong> <pre><code>" << Yajl::Encoder.encode(datr,:pretty => true, :indent => "   ") << "</code></pre></li>"
			end
			output << "</ul></li>"
		end
		output << "</ol></body></html>"
		
		[200,{"Content-Type" => "text/html"},[output]]
	end
	
	Routes.add_route new, { :request_method => 'GET', :path_info => %r{^/(?<server>[\w\.]+)$} }, {}, :server
	
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
city-watch-0.7.9 lib/city_watch/commander/server.rb
city-watch-0.7.8 lib/city_watch/commander/server.rb
city-watch-0.7.7 lib/city_watch/commander/server.rb
city-watch-0.7.6 lib/city_watch/commander/server.rb
city-watch-0.7.5 lib/city_watch/commander/server.rb
city-watch-0.7.4 lib/city_watch/commander/server.rb
city-watch-0.7.3 lib/city_watch/commander/server.rb
city-watch-0.7.2 lib/city_watch/commander/server.rb
city-watch-0.7.1 lib/city_watch/commander/server.rb
city-watch-0.7.0 lib/city_watch/commander/server.rb
city-watch-0.6.9 lib/city_watch/commander/server.rb
city-watch-0.6.8 lib/city_watch/commander/server.rb
city-watch-0.6.7 lib/city_watch/commander/server.rb
city-watch-0.6.6 lib/city_watch/commander/server.rb
city-watch-0.6.5 lib/city_watch/commander/server.rb
city-watch-0.6.4 lib/city_watch/commander/server.rb
city-watch-0.6.3 lib/city_watch/commander/server.rb
city-watch-0.6.2 lib/city_watch/commander/server.rb
city-watch-0.6.1 lib/city_watch/commander/server.rb
city-watch-0.6.0 lib/city_watch/commander/server.rb