Skip to content

Commit

Permalink
- More work towards a config file format.
Browse files Browse the repository at this point in the history
  • Loading branch information
jordansissel committed Feb 20, 2011
1 parent 93ec55f commit a3ebbec
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 87 deletions.
19 changes: 8 additions & 11 deletions bin/logstash
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ $: << File.dirname($0) + "/../lib"
require "rubygems"
require "logstash/agent"
require "optparse"
require "yaml"
#require "yaml"

Settings = Struct.new(:config_file, :daemonize, :logfile, :verbose)

Expand Down Expand Up @@ -52,12 +52,12 @@ if !File.exist?(settings.config_file)
$stderr.puts "Config file '#{settings.config_file}' does not exist."
end

begin
config = YAML::load_file(settings.config_file)
rescue => e
$stderr.puts "Loading config file '#{settings.config_file}' failed: #{e}"
exit 1
end
#begin
#config = YAML::load_file(settings.config_file)
#rescue => e
#$stderr.puts "Loading config file '#{settings.config_file}' failed: #{e}"
##exit 1
#end

if settings.daemonize
if Process.fork == nil
Expand All @@ -78,8 +78,5 @@ elsif settings.daemonize
STDERR.reopen(devnull)
end

agent = LogStash::Agent.new(config)
#if settings.logfile
#agent.log_to(settings.logfile)
#end
agent = LogStash::Agent.new(settings)
agent.run
18 changes: 12 additions & 6 deletions lib/logstash/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require "logstash/multiqueue"
require "logstash/namespace"
require "logstash/outputs"
require "logstash/config/file"
require "java"
require "uri"

Expand All @@ -17,18 +18,14 @@ class LogStash::Agent
attr_reader :filters

public
def initialize(config)
def initialize(settings)
log_to(STDERR)

@config = config
@settings = settings
@threads = {}
@outputs = []
@inputs = []
@filters = []
# Config should have:
# - list of logs to monitor
# - log config
# - where to ship to

Thread::abort_on_exception = true
end # def initialize
Expand All @@ -40,6 +37,14 @@ def log_to(target)

public
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
raise "Must have both inputs and outputs configured."
end
Expand Down Expand Up @@ -171,6 +176,7 @@ def register_signal_handler
end

@sigchannel.subscribe do |msg|
# TODO(sissel): Make this a function.
case msg
when :USR1
counts = Hash.new { |h,k| h[k] = 0 }
Expand Down
15 changes: 11 additions & 4 deletions lib/logstash/config/grammar.rl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ require "logstash/namespace"
@config[name] += @components
}

ws = ([ \t\n])** ;
comment = "#" (any - "\n")* ;
ws = ([ \t\n] | comment)** ;
#ws = ([ \t\n])** ;

# TODO(sissel): Support floating point values?
numeric = ( ("+" | "-")? [0-9] :>> [0-9]** ) >mark %stack_numeric;
quoted_string = (
Expand All @@ -106,9 +109,13 @@ require "logstash/namespace"
# }

component_implementation = (
naked_string ws "{" ws
parameters
ws "}"
(
naked_string ws "{" ws
parameters
ws "}"
) | (
naked_string ws "{" ws "}"
)
) %component_implementation ;

component = (
Expand Down
1 change: 1 addition & 0 deletions lib/logstash/config/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def config(cfg=nil)
end # def config

def dsl_gen
# TODO(sissel): Deprecated.
puts "#{@dsl_parent.config_name} { #parent" if @dsl_parent
config = []
config << "#{@config_name} { #node"
Expand Down
65 changes: 0 additions & 65 deletions lib/logstash/config/parser.rb

This file was deleted.

1 change: 1 addition & 0 deletions lib/logstash/outputs/amqp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class LogStash::Outputs::Amqp < LogStash::Outputs::Base
MQTYPES = [ "fanout", "queue", "topic" ]

config_name "amqp"
config :host => :string
config :queue_type => :string
config :queue_name => :string
Expand Down
1 change: 0 additions & 1 deletion lib/logstash/outputs/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class LogStash::Outputs::Base
attr_accessor :logger

config_name "outputs"
dsl_parent nil

public
def initialize(url)
Expand Down

0 comments on commit a3ebbec

Please sign in to comment.