Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify logstash configuration on command line with docker

Logstash 6.0 documentation for Stashing your first event shows the following command to run logstash with a simple pipeline which simply pipes stdin to stdout:

$ bin/logstash -e 'input { stdin { } } output { stdout {} }'

This does however not work when running logstash from the official docker container and fails with an error message about incompatible command line options:

$ docker run --rm -it docker.elastic.co/logstash/logstash-oss:6.0.0 \
  -e 'input { stdin { } } output { stdout {} }'
ERROR: Settings 'path.config' (-f) and 'config.string' (-e) can't be used simultaneously.

I'm not specifying -f or path.config. I simply want to test if logstash can be started and is working for this simple case. How to get around this error without mounting a config file?

like image 568
knittl Avatar asked Dec 02 '17 10:12

knittl


People also ask

What is a Logstash pipeline?

Logstash is an open source data processing pipeline that ingests events from one or more inputs, transforms them, and then sends each event to one or more outputs. Some Logstash implementations may have many lines of code and may process events from multiple input sources.

How do you check if Logstash is installed or not?

Verify Service is Running If Logstash isn't running, try starting it with this command: sudo service logstash start.

What is Logstash used for?

Logstash is a light-weight, open-source, server-side data processing pipeline that allows you to collect data from a variety of sources, transform it on the fly, and send it to your desired destination. It is most often used as a data pipeline for Elasticsearch, an open-source analytics and search engine.


1 Answers

Looking into the startup scripts inside the logstash docker image, one can find the following function in the logstash-core/lib/logstash/runner.rb file:

# where can I find the logstash.yml file?
# 1. look for a "--path.settings path"
# 2. look for a "--path.settings=path"
# 3. check if the LS_SETTINGS_DIR environment variable is set
# 4. return nil if not found
def fetch_settings_path(cli_args)
  if i=cli_args.find_index("--path.settings")
    cli_args[i+1]
  elsif settings_arg = cli_args.find {|v| v.match(/--path.settings=/) }
    match = settings_arg.match(/--path.settings=(.*)/)
    match[1]
  elsif ENV['LS_SETTINGS_DIR']
    ENV['LS_SETTINGS_DIR']
  else
    nil
  end
end

So the solution seems to either pass --path.settings= (=-syntax with empty value) or set the LS_SETTINGs_DIR variable to a falsy value. And indeed:

$ docker run --rm -it docker.elastic.co/logstash/logstash-oss:6.0.0 \
  --path.settings= -e 'input { stdin { } } output { stdout { } }'
The stdin plugin is now waiting for input:
like image 191
knittl Avatar answered Sep 24 '22 19:09

knittl