- add missing files

This commit is contained in:
Jordan Sissel 2011-02-19 20:50:48 -08:00
parent a3ebbec089
commit affed158a0
2 changed files with 94 additions and 0 deletions

View file

@ -0,0 +1,82 @@
require "logstash/namespace"
require "logstash/config/grammar"
require "logstash/config/registry"
require "logstash/agent"
class LogStash::Config::File
public
def initialize(file)
@file = file
end
public
def parse
grammar = LogStash::Config::Grammar.new
grammar.parse(File.new(@file).read)
@config = grammar.config
registry = LogStash::Config::Registry::registry
self.each do |o|
# Load the base class for the type given (like inputs/base, or filters/base)
# TODO(sissel): Error handling
tryload o[:type], :base
type = registry[o[:type]]
# Load the plugin itself (inputs/file, outputs/amqp, etc)
# TODO(sissel): Error handling
tryload o[:type], o[:plugin]
plugin = registry[o[:plugin]]
if type.nil?
puts "Unknown config #{o[:type]}/#{o[:plugin]}"
end
yield :type => type, :plugin => plugin, :parameters => o[:parameters]
end
end # def parse
public
def tryload(parent, child)
child = child.downcase if child.is_a? String
begin
p "Trying to load logstash/#{parent}s/#{child}" => \
(require "logstash/#{parent}s/#{child}")
rescue => e
if child == :base
$stderr.puts "Failure loading base class '#{parent}': #{e.inspect}"
else
$stderr.puts "Failure loading plugin #{parent}s/#{child}: #{e.inspect}"
end
raise e
end
end # def tryload
public
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.config(cfg)

View file

@ -0,0 +1,12 @@
require "logstash/namespace"
# Global config registry.
module LogStash::Config::Registry
@registry = Hash.new
class << self
attr_accessor :registry
# TODO(sissel): Add some helper methods here.
end
end # module LogStash::Config::Registry