Merge branch 'master' of github.com:logstash/logstash

This commit is contained in:
Jordan Sissel 2010-12-23 01:57:49 -08:00
commit b9793f3600
5 changed files with 93 additions and 13 deletions

View file

@ -68,8 +68,19 @@ if settings.daemonize
end
end
agent = LogStash::Agent.new(config)
if settings.logfile
agent.log_to(settings.logfile)
logfile = File.open(settings.logfile, "w")
STDOUT.reopen(logfile)
STDERR.reopen(logfile)
elsif settings.daemonize
# Write to /dev/null if
devnull = File.open("/dev/null", "w")
STDOUT.reopen(devnull)
STDERR.reopen(devnull)
end
agent = LogStash::Agent.new(config)
#if settings.logfile
#agent.log_to(settings.logfile)
#end
agent.run

View file

@ -7,12 +7,28 @@
},
search: function(query) {
if (query == undefined || query == "") {
return;
}
var display_query = query.replace("<", "&lt;").replace(">", "&gt;")
$("#querystatus").html("Loading query '" + display_query + "'")
logstash.params.q = query;
document.location.hash = escape(JSON.stringify(logstash.params));
$("#results").load("/search/ajax", logstash.params);
$("#query").val(logstash.params.q);
}, /* search */
parse_params: function(href) {
var params = href.replace(/^[^?]*\?/, "").split("&")
for (var p in params) {
var a = params[p].split("=");
var key = a[0]
var value = a[1]
logstash.params[key] = unescape(value)
}
return params;
},
appendquery: function(query) {
var newquery = $("#query").val();
newquery += " " + query;
@ -70,6 +86,13 @@
// Do nothing
}
logstash.search(logstash.params.q);
} else {
/* No hash. See if there's a query param. */
var params = logstash.parse_params(location.href);
for (var p in params) {
logstash.params[p] = params[p];
}
logstash.search(logstash.params.q)
}
$(window).hashchange(function() {
@ -83,12 +106,9 @@
$("a.pager").live("click", function() {
var href = $(this).attr("href");
var params = href.replace(/^[^?]*\?/, "").split("&")
var params = logstash.parse_params(location.href);
for (var p in params) {
var a = params[p].split("=");
var key = a[0]
var value = a[1]
logstash.params[key] = unescape(value)
logstash.params[p] = params[p];
}
logstash.search(logstash.params.q)
return false;

View file

@ -32,17 +32,51 @@ class LogStash::Web::Server < Sinatra::Base
end # '/'
aget '/search' do
headers({"Content-Type" => "text/html" })
result_callback = proc do
status 500 if @error
params[:format] ||= "html"
case params[:format]
when "html"
headers({"Content-Type" => "text/html" })
body haml :"search/results", :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" })
hits = @hits.collect { |h| h["_source"] }
response = {
"hits" => hits,
"facets" => (@results["facets"] rescue nil),
}
response["error"] = @error if @error
body response.to_json
end # case params[:format]
end # proc result_callback
# We'll still do a search query here even though most users
# have javascript enabled, we need to show the results in
# case a user doesn't have javascript.
if params[:q] and params[:q] != ""
elasticsearch.search(params) do |@results|
@hits = (@results["hits"]["hits"] rescue [])
body haml :"search/results", :layout => !request.xhr?
begin
result_callback.call
rescue => e
puts e
end
end
else
#@error = "No query given."
@hits = []
body haml :"search/results", :layout => !request.xhr?
result_callback.call
end
end
end # aget '/search'
apost '/search/ajax' do
headers({"Content-Type" => "text/html" })
@ -133,6 +167,11 @@ if settings.logfile
logfile = File.open(settings.logfile, "w")
STDOUT.reopen(logfile)
STDERR.reopen(logfile)
elsif settings.daemonize
# Write to /dev/null if
devnull = File.open("/dev/null", "w")
STDOUT.reopen(devnull)
STDERR.reopen(devnull)
end
Rack::Handler::Thin.run(

View file

@ -31,9 +31,9 @@
last
- if @hits.length == 0
- if !params[:q]
No query given. How about <a href="?q=*" class="querychanger">this?</a>
%h3#querystatus No query given. How about <a href="?q=*" class="querychanger">this?</a>
- else
No results for query '#{params[:q]}'
%h3#querystatus No results for query '#{params[:q]}'
- else
%table.results
%tr

View file

@ -0,0 +1,10 @@
<%
# Sinatra currently doesn't do ERB with newline trimming, so we
# have to write this funky mishmosh that is hard to read.
if @error %>Error: <%= @error %><% else
@hits.each do |hit|
event = LogStash::Event.new(hit["_source"])
%><%= event.message || event.to_hash.to_json %>
<% end
end
%>