Skip to content

Commit 66839e2

Browse files
committed
Merge pull request elastic#716 from wiibaa/jira-1149
Further validate date filter within register method Thanks for making Logstash awesome! :)
2 parents a1b804a + 07964a5 commit 66839e2

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

lib/logstash/filters/date.rb

+5
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ def parseLocale(localeString)
126126
public
127127
def register
128128
require "java"
129+
if @match.length < 2
130+
raise LogStash::ConfigurationError, I18n.t("logstash.agent.configuration.invalid_plugin_register",
131+
:plugin => "filter", :type => "date",
132+
:error => "The match setting should contains first a field name and at least one date format, current value is #{@match}")
133+
end
129134
# TODO(sissel): Need a way of capturing regexp configs better.
130135
locale = parseLocale(@config["locale"][0]) if @config["locale"] != nil and @config["locale"][0] != nil
131136
setupMatcher(@config["match"].shift, locale, @config["match"] )

locales/en.yml

+4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ en:
9797
}
9898
invalid_plugin_settings: >-
9999
Something is wrong with your configuration.
100+
invalid_plugin_register: >-
101+
Cannot register %{plugin} %{type} plugin.
102+
The error reported is:
103+
%{error}
100104
plugin_path_missing: >-
101105
You specified a plugin path that does not exist: %{path}
102106
no_plugins_found: |-

spec/filters/date.rb

+15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@
55
RUBY_ENGINE == "jruby" and describe LogStash::Filters::Date do
66
extend LogStash::RSpec
77

8+
describe "giving an invalid match config, raise a configuration error" do
9+
config <<-CONFIG
10+
filter {
11+
date {
12+
match => [ "mydate"]
13+
}
14+
}
15+
CONFIG
16+
17+
sample "not_really_important" do
18+
insist {subject}.raises LogStash::ConfigurationError
19+
end
20+
21+
end
22+
823
describe "parsing with ISO8601" do
924
config <<-CONFIG
1025
filter {

0 commit comments

Comments
 (0)