# Logstash -t option returning false config ok message

**URL:** <https://discuss.elastic.co/t/logstash-t-option-returning-false-config-ok-message/58733>\
**Category:** Logstash\
**Created:** [August 23, 2016, 7:30pm UTC](https://discuss.elastic.co/t/logstash-t-option-returning-false-config-ok-message/58733 "2016-08-23T19:30:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![GardenMWM](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@GardenMWM](https://discuss.elastic.co/u/GardenMWM)\
**Post date:** [August 23, 2016, 7:30pm UTC](https://discuss.elastic.co/t/logstash-t-option-returning-false-config-ok-message/58733/1 "2016-08-23T19:30:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [August 23, 2016, 7:42pm UTC](https://discuss.elastic.co/t/logstash-t-option-returning-false-config-ok-message/58733/2 "2016-08-23T19:42:56Z")

</div>

Which version of Logstash? With 2.3.4 I get the expected error message:

```nohighlight
$ cat test.conf 
input { stdin {} }
filter {
if somefield == "somevalue" { drop {}}
}
output { stdout {} }
$ /opt/logstash/bin/logstash --configtest -f test.conf            
The given configuration is invalid. Reason: Expected one of #, ( at line 3, column 14 (byte 42) after filter {
if somefield {:level=>:fatal}
$ /opt/logstash/bin/logstash --version
logstash 2.3.4

```

---

<div class="post-metadata">

**Author:** ![GardenMWM](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@GardenMWM](https://discuss.elastic.co/u/GardenMWM)\
**Post date:** [August 23, 2016, 8:04pm UTC](https://discuss.elastic.co/t/logstash-t-option-returning-false-config-ok-message/58733/3 "2016-08-23T20:04:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [August 24, 2016, 6:15am UTC](https://discuss.elastic.co/t/logstash-t-option-returning-false-config-ok-message/58733/4 "2016-08-24T06:15:15Z")

</div>

What I think is happening is that Logstash, absent the `-f` option, uses the default for the `-e` option,

```nohighlight
    -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).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 4:41am UTC](https://discuss.elastic.co/t/logstash-t-option-returning-false-config-ok-message/58733/5 "2017-07-06T04:41:55Z")

</div>


