mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
Merge branch 'master' of github.com:logstash/logstash
This commit is contained in:
commit
b9793f3600
5 changed files with 93 additions and 13 deletions
15
bin/logstash
15
bin/logstash
|
@ -68,8 +68,19 @@ if settings.daemonize
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
agent = LogStash::Agent.new(config)
|
|
||||||
if settings.logfile
|
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
|
end
|
||||||
|
|
||||||
|
agent = LogStash::Agent.new(config)
|
||||||
|
#if settings.logfile
|
||||||
|
#agent.log_to(settings.logfile)
|
||||||
|
#end
|
||||||
agent.run
|
agent.run
|
||||||
|
|
|
@ -7,12 +7,28 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
search: function(query) {
|
search: function(query) {
|
||||||
|
if (query == undefined || query == "") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var display_query = query.replace("<", "<").replace(">", ">")
|
||||||
|
$("#querystatus").html("Loading query '" + display_query + "'")
|
||||||
logstash.params.q = query;
|
logstash.params.q = query;
|
||||||
document.location.hash = escape(JSON.stringify(logstash.params));
|
document.location.hash = escape(JSON.stringify(logstash.params));
|
||||||
$("#results").load("/search/ajax", logstash.params);
|
$("#results").load("/search/ajax", logstash.params);
|
||||||
$("#query").val(logstash.params.q);
|
$("#query").val(logstash.params.q);
|
||||||
}, /* search */
|
}, /* 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) {
|
appendquery: function(query) {
|
||||||
var newquery = $("#query").val();
|
var newquery = $("#query").val();
|
||||||
newquery += " " + query;
|
newquery += " " + query;
|
||||||
|
@ -70,6 +86,13 @@
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
logstash.search(logstash.params.q);
|
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() {
|
$(window).hashchange(function() {
|
||||||
|
@ -83,12 +106,9 @@
|
||||||
|
|
||||||
$("a.pager").live("click", function() {
|
$("a.pager").live("click", function() {
|
||||||
var href = $(this).attr("href");
|
var href = $(this).attr("href");
|
||||||
var params = href.replace(/^[^?]*\?/, "").split("&")
|
var params = logstash.parse_params(location.href);
|
||||||
for (var p in params) {
|
for (var p in params) {
|
||||||
var a = params[p].split("=");
|
logstash.params[p] = params[p];
|
||||||
var key = a[0]
|
|
||||||
var value = a[1]
|
|
||||||
logstash.params[key] = unescape(value)
|
|
||||||
}
|
}
|
||||||
logstash.search(logstash.params.q)
|
logstash.search(logstash.params.q)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -32,17 +32,51 @@ class LogStash::Web::Server < Sinatra::Base
|
||||||
end # '/'
|
end # '/'
|
||||||
|
|
||||||
aget '/search' do
|
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] != ""
|
if params[:q] and params[:q] != ""
|
||||||
elasticsearch.search(params) do |@results|
|
elasticsearch.search(params) do |@results|
|
||||||
@hits = (@results["hits"]["hits"] rescue [])
|
@hits = (@results["hits"]["hits"] rescue [])
|
||||||
body haml :"search/results", :layout => !request.xhr?
|
begin
|
||||||
|
result_callback.call
|
||||||
|
rescue => e
|
||||||
|
puts e
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
#@error = "No query given."
|
||||||
@hits = []
|
@hits = []
|
||||||
body haml :"search/results", :layout => !request.xhr?
|
result_callback.call
|
||||||
end
|
end
|
||||||
end
|
end # aget '/search'
|
||||||
|
|
||||||
apost '/search/ajax' do
|
apost '/search/ajax' do
|
||||||
headers({"Content-Type" => "text/html" })
|
headers({"Content-Type" => "text/html" })
|
||||||
|
@ -133,6 +167,11 @@ if settings.logfile
|
||||||
logfile = File.open(settings.logfile, "w")
|
logfile = File.open(settings.logfile, "w")
|
||||||
STDOUT.reopen(logfile)
|
STDOUT.reopen(logfile)
|
||||||
STDERR.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
|
end
|
||||||
|
|
||||||
Rack::Handler::Thin.run(
|
Rack::Handler::Thin.run(
|
||||||
|
|
|
@ -31,9 +31,9 @@
|
||||||
last
|
last
|
||||||
- if @hits.length == 0
|
- if @hits.length == 0
|
||||||
- if !params[:q]
|
- 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
|
- else
|
||||||
No results for query '#{params[:q]}'
|
%h3#querystatus No results for query '#{params[:q]}'
|
||||||
- else
|
- else
|
||||||
%table.results
|
%table.results
|
||||||
%tr
|
%tr
|
||||||
|
|
10
lib/logstash/web/views/search/results.txt.erb
Normal file
10
lib/logstash/web/views/search/results.txt.erb
Normal 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
|
||||||
|
%>
|
Loading…
Add table
Add a link
Reference in a new issue