Skip to content

Commit

Permalink
filter/mutate raise configError in register
Browse files Browse the repository at this point in the history
  • Loading branch information
wiibaa authored and Suyog Rao committed Aug 27, 2014
1 parent 2f12d38 commit 8351fbd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/logstash/filters/mutate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,18 @@ def register
# TODO(sissel): Validate conversion requests if provided.
@convert.nil? or @convert.each do |field, type|
if !valid_conversions.include?(type)
@logger.error("Invalid conversion type",
"type" => type, "expected one of" => valid_types)
# TODO(sissel): It's 2011, man, let's actually make like.. a proper
# 'configuration broken' exception
raise "Bad configuration, aborting."
raise LogStash::ConfigurationError, I18n.t("logstash.agent.configuration.invalid_plugin_register",
:plugin => "filter", :type => "mutate",
:error => "Invalid conversion type '#{type}', expected one of '#{valid_conversions.join(',')}'")
end
end # @convert.each

@gsub_parsed = []
@gsub.nil? or @gsub.each_slice(3) do |field, needle, replacement|
if [field, needle, replacement].any? {|n| n.nil?}
@logger.error("Invalid gsub configuration. gsub has to define 3 elements per config entry", :field => field, :needle => needle, :replacement => replacement)
raise "Bad configuration, aborting."
raise LogStash::ConfigurationError, I18n.t("logstash.agent.configuration.invalid_plugin_register",
:plugin => "filter", :type => "mutate",
:error => "Invalid gsub configuration #{[field, needle, replacement]}. gsub requires 3 non-nil elements per config entry")
end

@gsub_parsed << {
Expand Down
29 changes: 29 additions & 0 deletions spec/filters/mutate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,35 @@
describe LogStash::Filters::Mutate do
extend LogStash::RSpec

context "config validation" do
describe "invalid convert type should raise a configuration error" do
config <<-CONFIG
filter {
mutate {
convert => [ "message", "int"] //should be integer
}
}
CONFIG

sample "not_really_important" do
insist {subject}.raises LogStash::ConfigurationError
end
end
describe "invalid gsub triad should raise a configuration error" do
config <<-CONFIG
filter {
mutate {
gsub => [ "message", "toreplace"]
}
}
CONFIG

sample "not_really_important" do
insist {subject}.raises LogStash::ConfigurationError
end
end
end

describe "basics" do
config <<-CONFIG
filter {
Expand Down

0 comments on commit 8351fbd

Please sign in to comment.