Skip to content

Commit

Permalink
Further validate date filter within register method
Browse files Browse the repository at this point in the history
  • Loading branch information
wiibaa committed Oct 11, 2013
1 parent cbf2a9a commit 07964a5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/logstash/filters/date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ def parseLocale(localeString)
public
def register
require "java"
if @match.length < 2
raise LogStash::ConfigurationError, I18n.t("logstash.agent.configuration.invalid_plugin_register",
:plugin => "filter", :type => "date",
:error => "The match setting should contains first a field name and at least one date format, current value is #{@match}")
end
# TODO(sissel): Need a way of capturing regexp configs better.
locale = parseLocale(@config["locale"][0]) if @config["locale"] != nil and @config["locale"][0] != nil
setupMatcher(@config["match"].shift, locale, @config["match"] )
Expand Down
4 changes: 4 additions & 0 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ en:
}
invalid_plugin_settings: >-
Something is wrong with your configuration.
invalid_plugin_register: >-
Cannot register %{plugin} %{type} plugin.
The error reported is:
%{error}
plugin_path_missing: >-
You specified a plugin path that does not exist: %{path}
no_plugins_found: |-
Expand Down
15 changes: 15 additions & 0 deletions spec/filters/date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
RUBY_ENGINE == "jruby" and describe LogStash::Filters::Date do
extend LogStash::RSpec

describe "giving an invalid match config, raise a configuration error" do
config <<-CONFIG
filter {
date {
match => [ "mydate"]
}
}
CONFIG

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

end

describe "parsing with ISO8601" do
config <<-CONFIG
filter {
Expand Down

0 comments on commit 07964a5

Please sign in to comment.