class LogStash::Web::Server
Public Class Methods
new(settings={})
click to toggle source
use Rack::ShowExceptions
Calls superclass method
# File lib/logstash/web/server.rb, line 35 def initialize(settings={}) super # TODO(sissel): Support alternate backends backend_url = URI.parse(settings.backend_url) case backend_url.scheme when "elasticsearch" @backend = LogStash::Search::ElasticSearch.new( :host => backend_url.host, :port => backend_url.port ) when "twitter" require "logstash/search/twitter" @backend = LogStash::Search::Twitter.new( :host => backend_url.host, :port => backend_url.port ) end # backend_url.scheme end
Public Instance Methods
api_search()
click to toggle source
# File lib/logstash/web/server.rb, line 130 def api_search headers({"Content-Type" => "text/html" }) count = params["count"] = (params["count"] or 50).to_i offset = params["offset"] = (params["offset"] or 0).to_i format = (params[:format] or "json") query = LogStash::Search::Query.new( :query_string => params[:q], :offset => offset, :count => count ) @backend.search(query) do |results| @results = results if @results.error? status 500 case format when "html" headers({"Content-Type" => "text/html" }) body haml :"search/error", :layout => !request.xhr? when "text" headers({"Content-Type" => "text/plain" }) body erb :"search/error.txt", :layout => false when "txt" headers({"Content-Type" => "text/plain" }) body erb :"search/error.txt", :layout => false when "json" headers({"Content-Type" => "text/plain" }) # TODO(sissel): issue/30 - needs refactoring here. if @results.error? body({ "error" => @results.error_message }.to_json) else body @results.to_json end end # case params[:format] next end @events = @results.events @total = (@results.total rescue 0) count = @results.events.size if count and offset if @total > (count + offset) @result_end = (count + offset) else @result_end = @total end @result_start = offset end if count + offset < @total next_params = params.clone next_params["offset"] = [offset + count, @total - count].min @next_href = "?" + next_params.collect { |k,v| [URI.escape(k.to_s), URI.escape(v.to_s)].join("=") }.join("&") last_params = next_params.clone last_params["offset"] = @total - count @last_href = "?" + last_params.collect { |k,v| [URI.escape(k.to_s), URI.escape(v.to_s)].join("=") }.join("&") end if offset > 0 prev_params = params.clone prev_params["offset"] = [offset - count, 0].max @prev_href = "?" + prev_params.collect { |k,v| [URI.escape(k.to_s), URI.escape(v.to_s)].join("=") }.join("&") #if prev_params["offset"] > 0 first_params = prev_params.clone first_params["offset"] = 0 @first_href = "?" + first_params.collect { |k,v| [URI.escape(k.to_s), URI.escape(v.to_s)].join("=") }.join("&") #end end # TODO(sissel): make a helper function taht goes hash -> cgi querystring @refresh_href = "?" + params.collect { |k,v| [URI.escape(k.to_s), URI.escape(v.to_s)].join("=") }.join("&") case format when "html" headers({"Content-Type" => "text/html" }) body haml :"search/ajax", :layout => !request.xhr? when "text" headers({"Content-Type" => "text/plain" }) body erb :"search/results.txt", :layout => false when "txt" headers({"Content-Type" => "text/plain" }) body erb :"search/results.txt", :layout => false when "json" headers({"Content-Type" => "text/plain" }) # TODO(sissel): issue/30 - needs refactoring here. response = @results body response.to_json end # case params[:format] end # @backend.search end