I've run into an unexpected behaviour of the -t test option and if statements. If I use the following invalid config,
input { stdin {} }
filter {
if somefield == "somevalue" { drop {}}
}
output { stdout {} }
and run /opt/logstash/bin/logstash -t testfile.conf I get a configuration ok message. However if I run it as the config file for logstash it errors (as expected) with the following error.
fetched an invalid config {:config=>"input { stdin {} }\nfilter {\nif somefield == "somevalue" { drop {}}\n}\noutput { stdout {} }\n\n", :reason=>"Expected one of #, ( at line 3, column 14 (byte 42) after filter {\nif somefield ", :level=>:error}
I'm pretty sure this is a bug but the github page said to post here first.
I'm running 2.3.2. Whats weird is if I run the command with both --configtest and -f it fails as well with the correct error message. If I run just logstash -t with no filename specified I also get a config Ok message. So it looks like logstash always requires the -f option even for testing.
What I think is happening is that Logstash, absent the -f option, uses the default for the -e option,
-e CONFIG_STRING Use the given string as the configuration
data. Same syntax as the config file. If no
input is specified, then the following is
used as the default input:
"input { stdin { type => stdin } }"
and if no output is specified, then the
following is used as the default output:
"output { stdout { codec => rubydebug } }"
If you wish to use both defaults, please use
the empty string for the '-e' flag.
(default: "")
and when you also supply -t it will test that configuration (which of course is okay).
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.