mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
Merge remote branch 'origin/issue/17' into experimental/petef-jruby
This commit is contained in:
commit
ea0a978281
15 changed files with 54 additions and 88 deletions
19
bin/logstash
19
bin/logstash
|
@ -5,7 +5,7 @@ $: << File.dirname($0) + "/../lib"
|
||||||
require "rubygems"
|
require "rubygems"
|
||||||
require "logstash/agent"
|
require "logstash/agent"
|
||||||
require "optparse"
|
require "optparse"
|
||||||
require "yaml"
|
#require "yaml"
|
||||||
|
|
||||||
Settings = Struct.new(:config_file, :daemonize, :logfile, :verbose)
|
Settings = Struct.new(:config_file, :daemonize, :logfile, :verbose)
|
||||||
|
|
||||||
|
@ -52,12 +52,12 @@ if !File.exist?(settings.config_file)
|
||||||
$stderr.puts "Config file '#{settings.config_file}' does not exist."
|
$stderr.puts "Config file '#{settings.config_file}' does not exist."
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
#begin
|
||||||
config = YAML::load_file(settings.config_file)
|
#config = YAML::load_file(settings.config_file)
|
||||||
rescue => e
|
#rescue => e
|
||||||
$stderr.puts "Loading config file '#{settings.config_file}' failed: #{e}"
|
#$stderr.puts "Loading config file '#{settings.config_file}' failed: #{e}"
|
||||||
exit 1
|
##exit 1
|
||||||
end
|
#end
|
||||||
|
|
||||||
if settings.daemonize
|
if settings.daemonize
|
||||||
if Process.fork == nil
|
if Process.fork == nil
|
||||||
|
@ -78,8 +78,5 @@ elsif settings.daemonize
|
||||||
STDERR.reopen(devnull)
|
STDERR.reopen(devnull)
|
||||||
end
|
end
|
||||||
|
|
||||||
agent = LogStash::Agent.new(config)
|
agent = LogStash::Agent.new(settings)
|
||||||
#if settings.logfile
|
|
||||||
#agent.log_to(settings.logfile)
|
|
||||||
#end
|
|
||||||
agent.run
|
agent.run
|
||||||
|
|
|
@ -4,6 +4,7 @@ require "logstash/logging"
|
||||||
require "logstash/multiqueue"
|
require "logstash/multiqueue"
|
||||||
require "logstash/namespace"
|
require "logstash/namespace"
|
||||||
require "logstash/outputs"
|
require "logstash/outputs"
|
||||||
|
require "logstash/config/file"
|
||||||
require "java"
|
require "java"
|
||||||
require "uri"
|
require "uri"
|
||||||
|
|
||||||
|
@ -17,18 +18,14 @@ class LogStash::Agent
|
||||||
attr_reader :filters
|
attr_reader :filters
|
||||||
|
|
||||||
public
|
public
|
||||||
def initialize(config)
|
def initialize(settings)
|
||||||
log_to(STDERR)
|
log_to(STDERR)
|
||||||
|
|
||||||
@config = config
|
@settings = settings
|
||||||
@threads = {}
|
@threads = {}
|
||||||
@outputs = []
|
@outputs = []
|
||||||
@inputs = []
|
@inputs = []
|
||||||
@filters = []
|
@filters = []
|
||||||
# Config should have:
|
|
||||||
# - list of logs to monitor
|
|
||||||
# - log config
|
|
||||||
# - where to ship to
|
|
||||||
|
|
||||||
Thread::abort_on_exception = true
|
Thread::abort_on_exception = true
|
||||||
end # def initialize
|
end # def initialize
|
||||||
|
@ -40,6 +37,14 @@ class LogStash::Agent
|
||||||
|
|
||||||
public
|
public
|
||||||
def run
|
def run
|
||||||
|
# Load the config file
|
||||||
|
p @settings.config_file
|
||||||
|
config = LogStash::Config::File.new(@settings.config_file)
|
||||||
|
config.parse do |plugin|
|
||||||
|
ap plugin
|
||||||
|
end
|
||||||
|
exit
|
||||||
|
|
||||||
if @config["inputs"].length == 0 or @config["outputs"].length == 0
|
if @config["inputs"].length == 0 or @config["outputs"].length == 0
|
||||||
raise "Must have both inputs and outputs configured."
|
raise "Must have both inputs and outputs configured."
|
||||||
end
|
end
|
||||||
|
@ -170,6 +175,7 @@ class LogStash::Agent
|
||||||
end
|
end
|
||||||
|
|
||||||
@sigchannel.subscribe do |msg|
|
@sigchannel.subscribe do |msg|
|
||||||
|
# TODO(sissel): Make this a function.
|
||||||
case msg
|
case msg
|
||||||
when :USR1
|
when :USR1
|
||||||
counts = Hash.new { |h,k| h[k] = 0 }
|
counts = Hash.new { |h,k| h[k] = 0 }
|
||||||
|
|
|
@ -81,7 +81,10 @@ require "logstash/namespace"
|
||||||
@config[name] += @components
|
@config[name] += @components
|
||||||
}
|
}
|
||||||
|
|
||||||
ws = ([ \t\n])** ;
|
comment = "#" (any - "\n")* ;
|
||||||
|
ws = ([ \t\n] | comment)** ;
|
||||||
|
#ws = ([ \t\n])** ;
|
||||||
|
|
||||||
# TODO(sissel): Support floating point values?
|
# TODO(sissel): Support floating point values?
|
||||||
numeric = ( ("+" | "-")? [0-9] :>> [0-9]** ) >mark %stack_numeric;
|
numeric = ( ("+" | "-")? [0-9] :>> [0-9]** ) >mark %stack_numeric;
|
||||||
quoted_string = (
|
quoted_string = (
|
||||||
|
@ -106,9 +109,13 @@ require "logstash/namespace"
|
||||||
# }
|
# }
|
||||||
|
|
||||||
component_implementation = (
|
component_implementation = (
|
||||||
|
(
|
||||||
naked_string ws "{" ws
|
naked_string ws "{" ws
|
||||||
parameters
|
parameters
|
||||||
ws "}"
|
ws "}"
|
||||||
|
) | (
|
||||||
|
naked_string ws "{" ws "}"
|
||||||
|
)
|
||||||
) %component_implementation ;
|
) %component_implementation ;
|
||||||
|
|
||||||
component = (
|
component = (
|
||||||
|
|
|
@ -49,6 +49,7 @@ module LogStash::Config::Mixin
|
||||||
end # def config
|
end # def config
|
||||||
|
|
||||||
def dsl_gen
|
def dsl_gen
|
||||||
|
# TODO(sissel): Deprecated.
|
||||||
puts "#{@dsl_parent.config_name} { #parent" if @dsl_parent
|
puts "#{@dsl_parent.config_name} { #parent" if @dsl_parent
|
||||||
config = []
|
config = []
|
||||||
config << "#{@config_name} { #node"
|
config << "#{@config_name} { #node"
|
||||||
|
|
|
@ -1,65 +0,0 @@
|
||||||
require "logstash/namespace"
|
|
||||||
require "logstash/config/grammar"
|
|
||||||
require "logstash/config/registry"
|
|
||||||
require "logstash/agent"
|
|
||||||
|
|
||||||
class LogStash::Config::File
|
|
||||||
def initialize(file)
|
|
||||||
@file = file
|
|
||||||
end
|
|
||||||
|
|
||||||
def parse
|
|
||||||
grammar = LogStash::Config::Grammar.new
|
|
||||||
grammar.parse(File.new(@file).read)
|
|
||||||
@config = grammar.config
|
|
||||||
end
|
|
||||||
|
|
||||||
def each(&block)
|
|
||||||
#ap @config
|
|
||||||
|
|
||||||
# First level is the components
|
|
||||||
# Like:
|
|
||||||
# inputs {
|
|
||||||
# ...
|
|
||||||
# }
|
|
||||||
@config.each do |type, plugin_config_array|
|
|
||||||
# plugin_config_array has arrays of each component config:
|
|
||||||
# inputs {
|
|
||||||
# amqp { ... }
|
|
||||||
# file { ... }
|
|
||||||
# file { ... }
|
|
||||||
# }
|
|
||||||
plugin_config_array.each do |plugin_config|
|
|
||||||
yield({
|
|
||||||
:type => type,
|
|
||||||
:plugin => plugin_config.keys.first,
|
|
||||||
:parameters => plugin_config.values.first
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end # @config.each
|
|
||||||
end # def each
|
|
||||||
end # class LogStash::Config::Parser
|
|
||||||
|
|
||||||
#agent = LogStash::Agent.new({})
|
|
||||||
cfg = LogStash::Config::File.new(ARGV[0])
|
|
||||||
cfg.parse
|
|
||||||
registry = LogStash::Config::Registry::registry
|
|
||||||
cfg.each do |o|
|
|
||||||
ap ["Config", o]
|
|
||||||
|
|
||||||
# Load the base class for the type given (like inputs/base, or filters/base)
|
|
||||||
# TODO(sissel): Error handling
|
|
||||||
require "logstash/#{o[:type]}s/base"
|
|
||||||
type = registry[o[:type]]
|
|
||||||
|
|
||||||
# Load the plugin itself (inputs/file, outputs/amqp, etc)
|
|
||||||
# TODO(sissel): Error handling
|
|
||||||
require "logstash/#{o[:type]}s/#{o[:plugin].downcase}"
|
|
||||||
config_class = registry[o[:plugin]]
|
|
||||||
if type
|
|
||||||
ap :got => [type, config_class]
|
|
||||||
else
|
|
||||||
puts "Unknown config #{o.awesome_inspect}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
#agent.config(cfg)
|
|
|
@ -3,6 +3,9 @@ require "logstash/inputs/base"
|
||||||
require "logstash/namespace"
|
require "logstash/namespace"
|
||||||
|
|
||||||
class LogStash::Inputs::Beanstalk < LogStash::Inputs::Base
|
class LogStash::Inputs::Beanstalk < LogStash::Inputs::Base
|
||||||
|
|
||||||
|
config_name "beanstalk"
|
||||||
|
|
||||||
public
|
public
|
||||||
def initialize(url, type, config={}, &block)
|
def initialize(url, type, config={}, &block)
|
||||||
super
|
super
|
||||||
|
|
|
@ -6,7 +6,7 @@ require "socket" # for Socket.gethostname
|
||||||
class LogStash::Inputs::File < LogStash::Inputs::Base
|
class LogStash::Inputs::File < LogStash::Inputs::Base
|
||||||
|
|
||||||
config_name "file"
|
config_name "file"
|
||||||
#dsl_parent LogStash::Inputs::Base
|
config :path => :string
|
||||||
|
|
||||||
public
|
public
|
||||||
def initialize(configs, output_queue)
|
def initialize(configs, output_queue)
|
||||||
|
|
|
@ -6,6 +6,8 @@ require "socket" # for Socket.gethostname
|
||||||
class LogStash::Inputs::Internal < LogStash::Inputs::Base
|
class LogStash::Inputs::Internal < LogStash::Inputs::Base
|
||||||
attr_reader :channel
|
attr_reader :channel
|
||||||
|
|
||||||
|
config_name "internal"
|
||||||
|
|
||||||
public
|
public
|
||||||
def initialize(url, type, config={}, &block)
|
def initialize(url, type, config={}, &block)
|
||||||
super
|
super
|
||||||
|
|
|
@ -4,6 +4,9 @@ require "logstash/namespace"
|
||||||
require "socket" # for Socket.gethostname
|
require "socket" # for Socket.gethostname
|
||||||
|
|
||||||
class LogStash::Inputs::Stdin < LogStash::Inputs::Base
|
class LogStash::Inputs::Stdin < LogStash::Inputs::Base
|
||||||
|
|
||||||
|
config_name "stdin"
|
||||||
|
|
||||||
public
|
public
|
||||||
def register
|
def register
|
||||||
EventMachine::attach($stdin, InputHandler, self)
|
EventMachine::attach($stdin, InputHandler, self)
|
||||||
|
|
|
@ -3,6 +3,9 @@ require "logstash/namespace"
|
||||||
require "logstash/stomp/handler"
|
require "logstash/stomp/handler"
|
||||||
|
|
||||||
class LogStash::Inputs::Stomp < LogStash::Inputs::Base
|
class LogStash::Inputs::Stomp < LogStash::Inputs::Base
|
||||||
|
|
||||||
|
config_name "stomp"
|
||||||
|
|
||||||
public
|
public
|
||||||
def initialize(url, config={}, &block)
|
def initialize(url, config={}, &block)
|
||||||
super
|
super
|
||||||
|
|
|
@ -6,6 +6,9 @@ require "logstash/time" # should really use the filters/date.rb bits
|
||||||
require "socket" # for Socket.gethostname
|
require "socket" # for Socket.gethostname
|
||||||
|
|
||||||
class LogStash::Inputs::Syslog < LogStash::Inputs::Base
|
class LogStash::Inputs::Syslog < LogStash::Inputs::Base
|
||||||
|
|
||||||
|
config_name "syslog"
|
||||||
|
|
||||||
public
|
public
|
||||||
def register
|
def register
|
||||||
if !@url.host or !@url.port
|
if !@url.host or !@url.port
|
||||||
|
|
|
@ -4,6 +4,9 @@ require "logstash/namespace"
|
||||||
require "socket" # for Socket.gethostname
|
require "socket" # for Socket.gethostname
|
||||||
|
|
||||||
class LogStash::Inputs::Tcp < LogStash::Inputs::Base
|
class LogStash::Inputs::Tcp < LogStash::Inputs::Base
|
||||||
|
|
||||||
|
config_name "tcp"
|
||||||
|
|
||||||
public
|
public
|
||||||
def initialize(url, type, config={}, &block)
|
def initialize(url, type, config={}, &block)
|
||||||
super
|
super
|
||||||
|
|
|
@ -5,6 +5,9 @@ require "logstash/namespace"
|
||||||
|
|
||||||
# TODO(sissel): This could use some refactoring.
|
# TODO(sissel): This could use some refactoring.
|
||||||
class LogStash::Inputs::Twitter < LogStash::Inputs::Base
|
class LogStash::Inputs::Twitter < LogStash::Inputs::Base
|
||||||
|
|
||||||
|
config_name "twitter"
|
||||||
|
|
||||||
public
|
public
|
||||||
def register
|
def register
|
||||||
api_url = "https://stream.twitter.com/1/statuses/filter.json"
|
api_url = "https://stream.twitter.com/1/statuses/filter.json"
|
||||||
|
|
|
@ -7,6 +7,7 @@ require "cgi"
|
||||||
class LogStash::Outputs::Amqp < LogStash::Outputs::Base
|
class LogStash::Outputs::Amqp < LogStash::Outputs::Base
|
||||||
MQTYPES = [ "fanout", "queue", "topic" ]
|
MQTYPES = [ "fanout", "queue", "topic" ]
|
||||||
|
|
||||||
|
config_name "amqp"
|
||||||
config :host => :string
|
config :host => :string
|
||||||
config :queue_type => :string
|
config :queue_type => :string
|
||||||
config :queue_name => :string
|
config :queue_name => :string
|
||||||
|
|
|
@ -11,7 +11,6 @@ class LogStash::Outputs::Base
|
||||||
attr_accessor :logger
|
attr_accessor :logger
|
||||||
|
|
||||||
config_name "outputs"
|
config_name "outputs"
|
||||||
dsl_parent nil
|
|
||||||
|
|
||||||
public
|
public
|
||||||
def initialize(url)
|
def initialize(url)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue