Skip to content

Commit

Permalink
- Config parsing works again; bug was causing '\' in a string to
Browse files Browse the repository at this point in the history
  terminate parsing of the config file. Oops! Was using 'return' from a
  code block.
- Update all the plugins to specify 'config_name'
- Start working more on agent integration
  • Loading branch information
jordansissel committed Feb 20, 2011
1 parent affed15 commit 33d6619
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 19 deletions.
8 changes: 5 additions & 3 deletions lib/logstash/agent.rb
Expand Up @@ -38,12 +38,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
# 'plugin' is a has containing:
# :type => the base class of the plugin (LogStash::Inputs::Base, etc)
# :plugin => the class of the plugin (LogStash::Inputs::File, etc)
# :parameters => hash of key-value parameters from the config.
p plugin[:plugin].name
end
exit

if @config["inputs"].length == 0 or @config["outputs"].length == 0
raise "Must have both inputs and outputs configured."
Expand Down
6 changes: 4 additions & 2 deletions lib/logstash/config/file.rb
Expand Up @@ -39,8 +39,10 @@ def parse
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}")
loaded = (require "logstash/#{parent}s/#{child}")
#if loaded
#puts "Loading logstash/#{parent}s/#{child}"
#end
rescue => e
if child == :base
$stderr.puts "Failure loading base class '#{parent}': #{e.inspect}"
Expand Down
33 changes: 21 additions & 12 deletions lib/logstash/config/grammar.rl
Expand Up @@ -33,7 +33,7 @@ require "logstash/namespace"
token = string[startpos + 1 ... endpos - 1] # Skip quotations

# Parse escapes.
token.gsub(/\\./) { |m| return m[1,1] }
token.gsub(/\\./) { |m| m[1,1] }
#puts "quotedstring: #{token}"
@stack << token
}
Expand Down Expand Up @@ -63,71 +63,76 @@ require "logstash/namespace"
@parameters[name] << value
}

action component_implementation {
action plugin {
@components ||= []
name = @stack.pop
#@components << { :name => name, :parameters => @parameters }
@components << { name => @parameters }
@parameters = {}
}

action component_init {
#puts "current component: " + @stack.last
puts "current component: " + @stack.last
@components = []
}

action component {
name = @stack.pop
@config ||= Hash.new { |h,k| h[k] = [] }
@config[name] += @components
puts "Config component: #{name}"
}

comment = "#" (any - "\n")* ;
comment = "#" (any - [\n])* >mark %{ e = @tokenstack.pop; puts "Comment: #{string[e ... p]}" };
ws = ([ \t\n] | comment)** ;
#ws = ([ \t\n])** ;

# TODO(sissel): Support floating point values?
numeric = ( ("+" | "-")? [0-9] :>> [0-9]** ) >mark %stack_numeric;
quoted_string = (
( "\"" ( ( (any - [\\"\n]) | "\\" any )* ) "\"" ) |
( "'" ( ( (any - [\\'\n]) | "\\" any )* ) "'" )
( "\"" ( ( (any - [\\"\n]) | "\\" any )* ) "\"" )
| ( "'" ( ( (any - [\\'\n]) | "\\" any )* ) "'" )
) >mark %stack_quoted_string ;
naked_string = ( [A-Za-z_] :>> [A-Za-z0-9_]* ) >mark %stack_string ;
string = ( quoted_string | naked_string ) ;

# TODO(sissel): allow use of this.
regexp_literal = ( "/" ( ( (any - [\\'\n]) | "\\" any )* ) "/" ) ;

array = ( "[" ws string ws ("," ws string ws)* "]" ) >array_init %array_push;
parameter_value = ( numeric | string | array );
parameter = ( string ws "=>" ws parameter_value ) %parameter ;
parameters = ( parameter ( ws parameter )** ) >parameter_init ;

# Statement:
# component {
# component_implementation_name {
# plugin_name {
# bar => ...
# baz => ...
# }
# ...
# }

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

component = (
naked_string ws "{"
>component_init
( ws component_implementation )**
( ws plugin )**
ws "}"
) %component ;

config = (ws component)** ;
config = (ws component? )** ;

main := config
main := config %{ puts "END" }
$err {
# Compute line and column of the cursor (p)
puts "Error at line #{self.line(string, p)}, column #{self.column(string, p)}: #{string[p .. -1].inspect}"
Expand Down Expand Up @@ -167,6 +172,10 @@ class LogStash::Config::Grammar
raise e
end

if cs < self.logstash_config_first_final
$stderr.puts "Error at line #{self.line(string, p)}, column #{self.column(string, p)}: #{string[p .. -1].inspect}"
raise "Invalid Configuration. Check syntax of config file."
end
return cs
end # def parse

Expand Down
2 changes: 1 addition & 1 deletion lib/logstash/config/mixin.rb
Expand Up @@ -23,7 +23,7 @@
module LogStash::Config::Mixin
# This method is called when someone does 'include LogStash::Config'
def self.included(base)
puts "Configurable class #{base.name}"
#puts "Configurable class #{base.name}"
#
# Add the DSL methods to the 'base' given.
base.extend(LogStash::Config::Mixin::DSL)
Expand Down
2 changes: 2 additions & 0 deletions lib/logstash/filters/date.rb
Expand Up @@ -4,6 +4,8 @@

class LogStash::Filters::Date < LogStash::Filters::Base

config_name "filter"

# Config for date is:
# fieldname: dateformat
# Allow arbitrary keys for this config.
Expand Down
4 changes: 4 additions & 0 deletions lib/logstash/filters/field.rb
Expand Up @@ -3,6 +3,10 @@
require "ostruct"

class LogStash::Filters::Field < LogStash::Filters::Base

# TODO(sissel): Finish this.
config_name "field"

class EvalSpace < OpenStruct
def get_binding
return binding
Expand Down
3 changes: 3 additions & 0 deletions lib/logstash/filters/grep.rb
Expand Up @@ -24,6 +24,9 @@
# - tag2
#
class LogStash::Filters::Grep < LogStash::Filters::Base

config_name "grep"

public
def initialize(config = {})
super
Expand Down
1 change: 1 addition & 0 deletions lib/logstash/filters/grok.rb
Expand Up @@ -6,6 +6,7 @@

class LogStash::Filters::Grok < LogStash::Filters::Base

config_name "grok"
config :pattern => :string
config :patterns_dir => :path
config :drop_if_match => :boolean # googlecode/issue/26
Expand Down
3 changes: 3 additions & 0 deletions lib/logstash/filters/grokdiscovery.rb
Expand Up @@ -4,6 +4,9 @@
require "grok" # rubygem 'jls-grok'

class LogStash::Filters::Grokdiscovery < LogStash::Filters::Base

config_name "grokdiscovery"

public
def initialize(config = {})
super
Expand Down
1 change: 1 addition & 0 deletions lib/logstash/filters/multiline.rb
Expand Up @@ -8,6 +8,7 @@

class LogStash::Filters::Multiline < LogStash::Filters::Base

config_name "multiline"
config :pattern => :string
config :negate => :boolean
config :what => ["previous", "next"]
Expand Down
2 changes: 1 addition & 1 deletion lib/logstash/outputs/base.rb
Expand Up @@ -10,7 +10,7 @@ class LogStash::Outputs::Base

attr_accessor :logger

config_name "outputs"
config_name "output"

public
def initialize(url)
Expand Down
3 changes: 3 additions & 0 deletions lib/logstash/outputs/beanstalk.rb
Expand Up @@ -3,6 +3,9 @@
require "em-jack"

class LogStash::Outputs::Beanstalk < LogStash::Outputs::Base

config_name "beanstalk"

public
def initialize(url, config={}, &block)
super
Expand Down
1 change: 1 addition & 0 deletions lib/logstash/outputs/elasticsearch.rb
Expand Up @@ -6,6 +6,7 @@
class LogStash::Outputs::Elasticsearch < LogStash::Outputs::Base

# http://host/index/type
config_name "elasticsearch"
config :host => :string
config :index => :string
config :type => :string
Expand Down
3 changes: 3 additions & 0 deletions lib/logstash/outputs/gelf.rb
Expand Up @@ -9,6 +9,9 @@
require "logstash/outputs/base"

class LogStash::Outputs::Gelf < LogStash::Outputs::Base

config_name "gelf"

public
def register
# nothing to do
Expand Down
3 changes: 3 additions & 0 deletions lib/logstash/outputs/internal.rb
Expand Up @@ -2,6 +2,9 @@
require "logstash/outputs/base"

class LogStash::Outputs::Internal < LogStash::Outputs::Base

config_name "internal"

public
def initialize(url, config={}, &block)
super
Expand Down
3 changes: 3 additions & 0 deletions lib/logstash/outputs/mongodb.rb
Expand Up @@ -3,6 +3,9 @@
require "em-mongo"

class LogStash::Outputs::Mongodb < LogStash::Outputs::Base

config_name "mongodb"

public
def register
# TODO(sissel): Port?
Expand Down
1 change: 1 addition & 0 deletions lib/logstash/outputs/nagios.rb
Expand Up @@ -5,6 +5,7 @@ class LogStash::Outputs::Nagios < LogStash::Outputs::Base
NAGIOS_CRITICAL = 2
NAGIOS_WARN = 1

config_name "nagios"
config :commandfile => :string

public
Expand Down
1 change: 1 addition & 0 deletions lib/logstash/outputs/stdout.rb
Expand Up @@ -3,6 +3,7 @@

class LogStash::Outputs::Stdout < LogStash::Outputs::Base

config_name "stdout"
config :debug => :boolean

public
Expand Down
2 changes: 2 additions & 0 deletions lib/logstash/outputs/stomp.rb
Expand Up @@ -5,6 +5,8 @@
class LogStash::Outputs::Stomp < LogStash::Outputs::Base
attr_reader :url

config_name "stomp"

public
def initialize(url, config={}, &block)
super
Expand Down

0 comments on commit 33d6619

Please sign in to comment.