mirror of
https://github.com/elastic/logstash.git
synced 2025-04-23 22:27:21 -04:00
- config now takes a name and an options hash (:validate and :required)
- support :ipaddr as validation
This commit is contained in:
parent
702a96fd28
commit
899ab7228a
18 changed files with 95 additions and 57 deletions
|
@ -61,15 +61,13 @@ module LogStash::Config::Mixin
|
|||
return @config_name
|
||||
end
|
||||
|
||||
# If config is given, add this config.
|
||||
# If no config given (nil), return the current config hash
|
||||
def config(cfg=nil)
|
||||
# cfg should be hash with one entry of { "key" => "val" }
|
||||
def config(name, opts={})
|
||||
@config ||= Hash.new
|
||||
key, value = cfg.to_a.first
|
||||
key = key.to_s if key.is_a?(Symbol)
|
||||
@config[key] = value
|
||||
return @config
|
||||
@required ||= Array.new
|
||||
|
||||
name = name.to_s if name.is_a?(Symbol)
|
||||
@config[name] = opts[:validate] # ok if this is nil
|
||||
@required << name if opts[:required] == true
|
||||
end # def config
|
||||
|
||||
# This is called whenever someone subclasses a class that has this mixin.
|
||||
|
@ -80,7 +78,6 @@ module LogStash::Config::Mixin
|
|||
subconfig = Hash.new
|
||||
if !@config.nil?
|
||||
@config.each do |key, val|
|
||||
puts "#{self}: Sharing config '#{key}' with subclass #{subclass}"
|
||||
subconfig[key] = val
|
||||
end
|
||||
end
|
||||
|
@ -93,6 +90,7 @@ module LogStash::Config::Mixin
|
|||
is_valid = true
|
||||
|
||||
is_valid &&= validate_check_invalid_parameter_names(params)
|
||||
is_valid &&= validate_check_required_parameter_names(params)
|
||||
is_valid &&= validate_check_parameter_values(params)
|
||||
|
||||
return is_valid
|
||||
|
@ -100,9 +98,9 @@ module LogStash::Config::Mixin
|
|||
|
||||
def validate_check_invalid_parameter_names(params)
|
||||
invalid_params = params.keys
|
||||
# Filter out parametrs that match regexp keys.
|
||||
# Filter out parameters that match regexp keys.
|
||||
# These are defined in plugins like this:
|
||||
# config /foo.*/ => ...
|
||||
# config /foo.*/ => ...
|
||||
@config.each_key do |config_key|
|
||||
if config_key.is_a?(Regexp)
|
||||
invalid_params.reject! { |k| k =~ config_key }
|
||||
|
@ -120,6 +118,24 @@ module LogStash::Config::Mixin
|
|||
return true
|
||||
end # def validate_check_invalid_parameter_names
|
||||
|
||||
def validate_check_required_parameter_names(params)
|
||||
@required ||= Array.new
|
||||
is_valid = true
|
||||
|
||||
@required.each do |config_key|
|
||||
if config_key.is_a?(Regexp)
|
||||
next if params.keys.select { |k| k =~ config_key }.length > 0
|
||||
elsif config_key.is_a?(String)
|
||||
next if params.keys.member?(config_key)
|
||||
end
|
||||
@logger.error("Missing required parameter '#{config_key}' for " \
|
||||
"#{@plugin_name}")
|
||||
is_valid = false
|
||||
end
|
||||
|
||||
return is_valid
|
||||
end
|
||||
|
||||
def validate_check_parameter_values(params)
|
||||
# Filter out parametrs that match regexp keys.
|
||||
# These are defined in plugins like this:
|
||||
|
@ -207,8 +223,23 @@ module LogStash::Config::Mixin
|
|||
if value.first !~ /^(true|false)$/
|
||||
return false, "Expected boolean 'true' or 'false', got #{value.inspect}"
|
||||
end
|
||||
|
||||
result = (value.first == "true")
|
||||
when :ipaddr
|
||||
if value.size > 1 # only one value wanted
|
||||
return false, "Expected IPaddr, got #{value.inspect}"
|
||||
end
|
||||
|
||||
octets = value.split(".")
|
||||
if octets.length != 4
|
||||
return false, "Expected IPaddr, got #{value.inspect}"
|
||||
end
|
||||
octest.each do |o|
|
||||
if o.to_i < 0 or o.to_i > 255
|
||||
return false, "Expected IPaddr, got #{value.inspect}"
|
||||
end
|
||||
end
|
||||
result = value.first
|
||||
|
||||
end # case validator
|
||||
else
|
||||
return false, "Unknown validator #{validator.class}"
|
||||
|
|
|
@ -8,9 +8,9 @@ class LogStash::Filters::Base
|
|||
attr_accessor :logger
|
||||
|
||||
config_name "filter"
|
||||
config :type => :string
|
||||
config :add_tag => nil
|
||||
config :add_field => :hash
|
||||
config :type, :validate => :string
|
||||
config :add_tag
|
||||
config :add_field, :validate => :hash
|
||||
|
||||
public
|
||||
def initialize(params)
|
||||
|
|
|
@ -10,7 +10,7 @@ class LogStash::Filters::Date < LogStash::Filters::Base
|
|||
# Config for date is:
|
||||
# fieldname: dateformat
|
||||
# Allow arbitrary keys for this config.
|
||||
config /[A-Za-z0-9_-]+/ => :string
|
||||
config /[A-Za-z0-9_-]+/, :validate => :string
|
||||
|
||||
# LOGSTASH-34
|
||||
DATEPATTERNS = %w{ y d H m s S Z }
|
||||
|
|
|
@ -7,9 +7,9 @@ require "grok" # rubygem 'jls-grok'
|
|||
class LogStash::Filters::Grok < LogStash::Filters::Base
|
||||
|
||||
config_name "grok"
|
||||
config :pattern => nil
|
||||
config :patterns_dir => nil
|
||||
config :drop_if_match => :boolean # googlecode/issue/26
|
||||
config :pattern
|
||||
config :patterns_dir
|
||||
config :drop_if_match, :validate => :boolean # googlecode/issue/26
|
||||
|
||||
@@grokpiles = Hash.new { |h, k| h[k] = [] }
|
||||
@@grokpiles_lock = Mutex.new
|
||||
|
|
|
@ -9,9 +9,9 @@ require "logstash/namespace"
|
|||
class LogStash::Filters::Multiline < LogStash::Filters::Base
|
||||
|
||||
config_name "multiline"
|
||||
config :pattern => :string
|
||||
config :negate => :boolean
|
||||
config :what => ["previous", "next"]
|
||||
config :pattern, :validate => :string
|
||||
config :negate, :validate => :boolean
|
||||
config :what, :validate => ["previous", "next"]
|
||||
|
||||
# The 'date' filter will take a value from your event and use it as the
|
||||
# event timestamp. This is useful for parsing logs generated on remote
|
||||
|
|
|
@ -7,14 +7,14 @@ class LogStash::Inputs::Amqp < LogStash::Inputs::Base
|
|||
|
||||
config_name "amqp"
|
||||
|
||||
config :host => :string
|
||||
config :user => :string
|
||||
config :pass => :string
|
||||
config :exchange_type => :string
|
||||
config :name => :string
|
||||
config :vhost => :string
|
||||
config :durable => :boolean
|
||||
config :debug => :boolean
|
||||
config :host, :validate => :string
|
||||
config :user, :validate => :string
|
||||
config :pass, :validate => :string
|
||||
config :exchange_type, :validate => :string
|
||||
config :name, :validate => :string
|
||||
config :vhost, :validate => :string
|
||||
config :durable, :validate => :boolean
|
||||
config :debug, :validate => :boolean
|
||||
|
||||
|
||||
public
|
||||
|
|
|
@ -8,9 +8,9 @@ class LogStash::Inputs::Base
|
|||
attr_accessor :logger
|
||||
|
||||
config_name "input"
|
||||
config :type => :string
|
||||
config :type, :validate => :string
|
||||
|
||||
config :tags => (lambda do |value|
|
||||
config :tags, :validate => (lambda do |value|
|
||||
re = /^[A-Za-z0-9_]+$/
|
||||
value.each do |v|
|
||||
if v !~ re
|
||||
|
|
|
@ -5,7 +5,7 @@ require "logstash/namespace"
|
|||
class LogStash::Inputs::Beanstalk < LogStash::Inputs::Base
|
||||
|
||||
config_name "beanstalk"
|
||||
config :tube => nil # TODO(sissel): needs validation?
|
||||
config :tube # TODO(sissel): needs validation?
|
||||
|
||||
public
|
||||
def initialize(params)
|
||||
|
|
|
@ -10,7 +10,7 @@ class LogStash::Inputs::File < LogStash::Inputs::Base
|
|||
@@filemanager_lock = Mutex.new
|
||||
|
||||
config_name "file"
|
||||
config :path => nil # no validation on path, it can be anything.
|
||||
config :path # no validation on path, it can be anything.
|
||||
|
||||
public
|
||||
def register
|
||||
|
|
|
@ -9,9 +9,16 @@ class LogStash::Inputs::Syslog < LogStash::Inputs::Base
|
|||
|
||||
config_name "syslog"
|
||||
|
||||
# The address to listen on
|
||||
config :address => nil # TODO(sissel): needs validation
|
||||
config :port => nil # TODO(sissel): needs validation
|
||||
# TCP listen configuration
|
||||
config :host, :validate => :ipaddr
|
||||
config :port, :validate => :number
|
||||
|
||||
public
|
||||
def initialize(params)
|
||||
super
|
||||
|
||||
@host ||= "0.0.0.0"
|
||||
end
|
||||
|
||||
public
|
||||
def register
|
||||
|
|
|
@ -7,9 +7,9 @@ class LogStash::Inputs::Tcp < LogStash::Inputs::Base
|
|||
|
||||
config_name "tcp"
|
||||
|
||||
config :host => :string
|
||||
config :port => :number
|
||||
config :data_timeout => :number
|
||||
config :host, :validate => :ipaddr
|
||||
config :port, :validate => :number, :required => true
|
||||
config :data_timeout, :validate => :number
|
||||
|
||||
public
|
||||
def initialize(params)
|
||||
|
|
|
@ -7,7 +7,7 @@ require "logstash/namespace"
|
|||
class LogStash::Inputs::Twitter < LogStash::Inputs::Base
|
||||
|
||||
config_name "twitter"
|
||||
config :query => nil # TODO(sissel): Validation?
|
||||
config :query # TODO(sissel): Validation?
|
||||
|
||||
public
|
||||
def register
|
||||
|
|
|
@ -6,14 +6,14 @@ class LogStash::Outputs::Amqp < LogStash::Outputs::Base
|
|||
MQTYPES = [ "fanout", "queue", "topic" ]
|
||||
|
||||
config_name "amqp"
|
||||
config :host => :string
|
||||
config :user => :string
|
||||
config :pass => :string
|
||||
config :exchange_type => :string
|
||||
config :name => :string
|
||||
config :vhost => :string
|
||||
config :durable => :boolean
|
||||
config :debug => :boolean
|
||||
config :host, :validate => :string
|
||||
config :user, :validate => :string
|
||||
config :pass, :validate => :string
|
||||
config :exchange_type, :validate => :string
|
||||
config :name, :validate => :string
|
||||
config :vhost, :validate => :string
|
||||
config :durable, :validate => :boolean
|
||||
config :debug, :validate => :boolean
|
||||
|
||||
public
|
||||
def initialize(params)
|
||||
|
|
|
@ -5,7 +5,7 @@ require "em-jack"
|
|||
class LogStash::Outputs::Beanstalk < LogStash::Outputs::Base
|
||||
|
||||
config_name "beanstalk"
|
||||
config :ttr => :number
|
||||
config :ttr, :validate => :number
|
||||
|
||||
public
|
||||
def initialize(params)
|
||||
|
|
|
@ -7,9 +7,9 @@ class LogStash::Outputs::Elasticsearch < LogStash::Outputs::Base
|
|||
|
||||
# http://host/index/type
|
||||
config_name "elasticsearch"
|
||||
config :host => :string
|
||||
config :index => :string
|
||||
config :type => :string
|
||||
config :host, :validate => :string
|
||||
config :index, :validate => :string
|
||||
config :type, :validate => :string
|
||||
# TODO(sissel): Config for river?
|
||||
|
||||
public
|
||||
|
|
|
@ -6,8 +6,8 @@ class LogStash::Outputs::Nagios < LogStash::Outputs::Base
|
|||
NAGIOS_WARN = 1
|
||||
|
||||
config_name "nagios"
|
||||
config :commandfile => :string
|
||||
|
||||
config :commandfile, :validate => :string
|
||||
|
||||
public
|
||||
def initialize(url, config={}, &block)
|
||||
super
|
||||
|
|
|
@ -5,7 +5,7 @@ require "logstash/namespace"
|
|||
class LogStash::Outputs::Stdout < LogStash::Outputs::Base
|
||||
|
||||
config_name "stdout"
|
||||
config :debug => :boolean
|
||||
config :debug, :validate => :boolean
|
||||
|
||||
public
|
||||
def initialize(params)
|
||||
|
|
|
@ -3,7 +3,7 @@ require "logstash/namespace"
|
|||
require "logstash/outputs/base"
|
||||
|
||||
class LogStash::Outputs::Websocket < LogStash::Outputs::Base
|
||||
config :address => :string
|
||||
config :address, :validate => :string
|
||||
|
||||
public
|
||||
def register
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue