mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
- support querying what log types are available
This commit is contained in:
parent
344e1a4aef
commit
6c4c36cdd7
4 changed files with 64 additions and 15 deletions
44
bin/list_log_types.rb
Executable file
44
bin/list_log_types.rb
Executable file
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/ruby
|
||||
#
|
||||
require 'rubygems'
|
||||
require "socket"
|
||||
require "lib/net/message"
|
||||
require "lib/net/client"
|
||||
require "lib/net/messages/logtypes"
|
||||
|
||||
Thread::abort_on_exception = true
|
||||
|
||||
class LogTypesClient < LogStash::Net::MessageClient
|
||||
attr_reader :types
|
||||
|
||||
def initialize(opts)
|
||||
@types = []
|
||||
super(opts)
|
||||
start
|
||||
end
|
||||
|
||||
def start
|
||||
msg = LogStash::Net::Messages::LogTypesRequest.new
|
||||
sendmsg("logstash-index", msg)
|
||||
run
|
||||
end
|
||||
|
||||
def LogTypesResponseHandler(msg)
|
||||
@types = msg.types
|
||||
close
|
||||
end
|
||||
end
|
||||
|
||||
def main(args)
|
||||
client = LogTypesClient.new(:host => "localhost")
|
||||
|
||||
# Collate & print results.
|
||||
puts "Log types:"
|
||||
client.types.each { |t| puts " - #{t}" }
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
if $0 == __FILE__
|
||||
exit main(ARGV)
|
||||
end
|
|
@ -23,5 +23,9 @@ module LogStash
|
|||
def [](log_type)
|
||||
return @logs[log_type]
|
||||
end
|
||||
|
||||
def types
|
||||
return @logs.keys
|
||||
end
|
||||
end # class Logs
|
||||
end # module LogStash
|
||||
|
|
|
@ -1,22 +1,16 @@
|
|||
require "lib/net/message"
|
||||
|
||||
module LogStash; module Net; module Messages
|
||||
class SearchRequest < RequestMessage
|
||||
class LogTypesRequest < RequestMessage
|
||||
register
|
||||
|
||||
# No message attributes
|
||||
end # class LogTypesRequest
|
||||
|
||||
class LogTypesResponse < ResponseMessage
|
||||
register
|
||||
|
||||
# Message attributes
|
||||
hashbind :query, "/args/query"
|
||||
hashbind :log_type, "/args/log_type"
|
||||
hashbind :offset, "/args/offset"
|
||||
hashbind :limit, "/args/limit"
|
||||
|
||||
end # class SearchRequest
|
||||
|
||||
class SearchResponse < ResponseMessage
|
||||
register
|
||||
|
||||
# Message attributes
|
||||
hashbind :results, "/args/results"
|
||||
hashbind :finished, "/args/finished"
|
||||
end # class SearchResponse
|
||||
hashbind :types, "/args/types"
|
||||
end # class LogTypesResponse
|
||||
end; end; end # module LogStash::Net::Messages
|
||||
|
|
|
@ -5,6 +5,7 @@ require 'lib/net/message'
|
|||
require 'lib/net/messages/broadcast'
|
||||
require 'lib/net/messages/directory'
|
||||
require 'lib/net/messages/indexevent'
|
||||
require 'lib/net/messages/logtypes'
|
||||
require 'lib/net/messages/search'
|
||||
require 'lib/net/messages/searchhits'
|
||||
require 'lib/net/messages/quit'
|
||||
|
@ -63,6 +64,12 @@ module LogStash; module Net; module Servers
|
|||
yield response
|
||||
end
|
||||
|
||||
def LogTypesRequestHandler(request)
|
||||
response = LogStash::Net::Messages::LogTypesResponse.new
|
||||
response.types = @config.logs.types
|
||||
yield response
|
||||
end
|
||||
|
||||
def SearchRequestHandler(request)
|
||||
puts "Search for #{request.query.inspect} in #{request.log_type}"
|
||||
response = LogStash::Net::Messages::SearchResponse.new
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue