diff --git a/lib/logstash/config.rb b/lib/logstash/config.rb index 3a9c72bbf..9a1cdc2ed 100644 --- a/lib/logstash/config.rb +++ b/lib/logstash/config.rb @@ -23,20 +23,59 @@ module LogStash::Config # This method is called when someone does 'include LogStash::Config' def self.included(base) # Add ClassMethods module methods to the 'base' given. - base.extend(ClassMethods) + base.extend(LogStash::Config::DSL) end - module ClassMethods - def section(name) - @section = name - end # def self.section + module DSL + attr_accessor :dsl_name + attr_accessor :dsl_parent - def config(cfg) + # Set the parent config for this class. + def dsl_parent(*args) + @dsl_parent = args[0] if args.length > 0 + return @dsl_parent + end + + # Set the config name for this class. + def dsl_name(*args) + @dsl_name = args[0] if args.length > 0 + return @dsl_name + end + + def dsl_config(cfg) # cfg should be hash with one entry of { "key" => "val" } + @dsl_config ||= Hash.new key, value = cfg.to_a.first - puts "#{@section} {" - puts " #{key} => #{value}" - puts "}" - end # def self.config - end # module ClassMethods + @dsl_config[key] = value + end # def config + + def dsl_gen + puts "#{@dsl_parent.dsl_name} { #parent" if @dsl_parent + config = [] + config << "#{@dsl_name} { #node" + config << " \"somename\":" + attrs = [] + (@dsl_config || Hash.new).each do |key, value| + attrs << " #{key} => #{value}," + end + config += attrs + config << "} #node" + config = config.collect { |p| "#{@dsl_parent.nil? ? "" : " "}#{p}" } + puts config.join("\n") + puts "} #parent" if @dsl_parent + end + + def inherited(subclass) + # Copy our parent's config to a subclass. + # This method is invoked whenever someone subclasses us, like: + # class Foo < Bar ... + config = Hash.new + @dsl_config.each do |key, val| + #puts "#{self}: Sharing config '#{key}' with subclass #{subclass}" + config[key] = val + end + subclass.instance_variable_set("@dsl_config", config) + subclass.dsl_parent = self + end # def inherited + end # module LogStash::Config::DSL end # module LogStash::Config diff --git a/lib/logstash/inputs/amqp.rb b/lib/logstash/inputs/amqp.rb index 7e0e4c3a0..b1f69545a 100644 --- a/lib/logstash/inputs/amqp.rb +++ b/lib/logstash/inputs/amqp.rb @@ -8,6 +8,9 @@ require "cgi" class LogStash::Inputs::Amqp < LogStash::Inputs::Base MQTYPES = [ "fanout", "queue", "topic" ] + dsl_name "amqp" + dsl_config "pantscon" => :string #LogStash::Config::Path + public def initialize(url, type, config={}, &block) super diff --git a/lib/logstash/inputs/base.rb b/lib/logstash/inputs/base.rb index a455d5758..bce42ad33 100644 --- a/lib/logstash/inputs/base.rb +++ b/lib/logstash/inputs/base.rb @@ -8,9 +8,11 @@ class LogStash::Inputs::Base include LogStash::Config attr_accessor :logger + dsl_name "input" + dsl_parent nil # Define the basic config - config "path" => :string #LogStash::Config::Path - config "tag" => :string #LogStash::Config::Array + dsl_config "path" => :string #LogStash::Config::Path + dsl_config "tag" => :string #LogStash::Config::Array public def initialize(configs, output_queue) diff --git a/lib/logstash/inputs/file.rb b/lib/logstash/inputs/file.rb index bca23a733..6cf02f549 100644 --- a/lib/logstash/inputs/file.rb +++ b/lib/logstash/inputs/file.rb @@ -4,6 +4,10 @@ require "logstash/namespace" require "socket" # for Socket.gethostname class LogStash::Inputs::File < LogStash::Inputs::Base + + dsl_name "file" + #dsl_parent LogStash::Inputs::Base + public def initialize(configs, output_queue) super