mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
- Correctly set defaults for limit and offset
- Allow user to specify log_type - Fix next/prev urls - Escape form values when displaying them
This commit is contained in:
parent
dc4cc2088a
commit
40fbf7a670
3 changed files with 18 additions and 8 deletions
|
@ -36,16 +36,20 @@ class Search < Application
|
||||||
end
|
end
|
||||||
|
|
||||||
def query
|
def query
|
||||||
|
params[:offset] = (params[:offset] ? params[:offset].to_i : 0) rescue 0
|
||||||
|
params[:limit] = (params[:limit] ? params[:limit].to_i : 20) rescue 20
|
||||||
|
params[:log_type] = (params[:log_type] or "linux-syslog")
|
||||||
@searchclient = SearchClient.new(host="localhost", port=61613)
|
@searchclient = SearchClient.new(host="localhost", port=61613)
|
||||||
msg = LogStash::Net::Messages::SearchHitsRequest.new
|
msg = LogStash::Net::Messages::SearchHitsRequest.new
|
||||||
msg.log_type = (params[:log_type] or "linux-syslog")
|
msg.log_type = params[:log_type]
|
||||||
msg.query = params[:q]
|
msg.query = params[:q]
|
||||||
@searchclient.sendmsg("/queue/logstash", msg)
|
@searchclient.sendmsg("/queue/logstash", msg)
|
||||||
|
|
||||||
msg = LogStash::Net::Messages::SearchRequest.new
|
msg = LogStash::Net::Messages::SearchRequest.new
|
||||||
msg.log_type = (params[:log_type] or "linux-syslog")
|
msg.log_type = (params[:log_type] or "linux-syslog")
|
||||||
msg.query = params[:q]
|
msg.query = params[:q]
|
||||||
msg.limit = 20
|
msg.offset = params[:offset]
|
||||||
|
msg.limit = params[:limit]
|
||||||
@searchclient.sendmsg("/queue/logstash", msg)
|
@searchclient.sendmsg("/queue/logstash", msg)
|
||||||
|
|
||||||
Timeout.timeout(10) do
|
Timeout.timeout(10) do
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
<%= form :action => url(:controller => "search", :action => "query"),
|
<%= form :action => url(:controller => "search", :action => "query"),
|
||||||
:method => :getvn do %>
|
:method => :get do %>
|
||||||
<%= text_field :name => "q", :label => "Query" %>
|
<%= text_field :name => "q", :label => "Query", :value => escape_html(params[:q]), :size => 100 %>
|
||||||
|
<br/>
|
||||||
|
<%= text_field :name => "log_type", :label => "log type", :value => params[:log_type] %>
|
||||||
|
<br>
|
||||||
<%= submit "Search" %>
|
<%= submit "Search" %>
|
||||||
<% end =%>
|
<% end =%>
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
<%= form :action => url(:controller => "search", :action => "query"),
|
<%= form :action => url(:controller => "search", :action => "query"),
|
||||||
:method => :get do %>
|
:method => :get do %>
|
||||||
<%= text_field :name => "q", :label => "Query" %>
|
<%= text_field :name => "q", :label => "Query", :value => escape_html(params[:q]), :size => 100 %>
|
||||||
|
<br/>
|
||||||
|
<%= text_field :name => "log_type", :label => "log type", :value => escape_html(params[:log_type]) %>
|
||||||
|
<br>
|
||||||
<%= submit "Search" %>
|
<%= submit "Search" %>
|
||||||
<% end =%>
|
<% end =%>
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<h4>Results <%= params[:offset] %> - <%= params[:offset] + params[:limit] %> of <%= @searchclient.hits %> for <%= params[:q] %></h4>
|
<h4>Results <%= params[:offset] %> - <%= params[:offset] + params[:limit] %> of <%= @searchclient.hits %> for <%=h params[:q] %></h4>
|
||||||
<% if params[:offset] > 0 %>
|
<% if params[:offset] > 0 %>
|
||||||
<%= link_to "prev", url(:controller => "search", :action => "query", :q => params[:q], :offset => [0, params[:offset] - params[:limit]].max, :limit => params[:limit]) %>
|
<%= link_to "prev", url(:controller => "search", :action => "query", :q => params[:q], :offset => [0, params[:offset] - params[:limit]].max, :limit => params[:limit]), :log_type => params[:log_type] %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if params[:offset] + params[:limit] < @searchclient.hits %>
|
<% if params[:offset] + params[:limit] < @searchclient.hits %>
|
||||||
<%= link_to "next", url(:controller => "search", :action => "query", :q => params[:q], :offset => [@searchclient.hits - params[:limit], params[:offset] + params[:limit]].min, :limit => params[:limit]) %>
|
<%= link_to "next", url(:controller => "search", :action => "query", :q => params[:q], :offset => [@searchclient.hits - params[:limit], params[:offset] + params[:limit]].min, :limit => params[:limit], :log_type => params[:log_type]) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue