Setting variables in logstash configuration files

I have multiple logstash clients that use identical logstash configurations except for small things like the path to the file to monitor. I'm wondering if this value can be parameterized for easier templating?

Currently each file has:

input {
  file {
    path => "/path/instance[123..n]/to/access_log"
    type => "apache-access"
  }
}

Is it possible to set a variable in the logstash.conf file (or elsewhere) so I could do something like this:

INSTANCE=instance1
input {
  file {
    path => "/path/$INSTANCE/to/access_log"
    type => "apache-access"
  }
}

Thanks,
Ryan

Before launching logstash, you could set an environment variable :
export INSTANCE="MY_INSTANCE"

Then, in logstash configuration file, you can reference this environment variable using :
${INSTANCE}

Precision : you need logstash 2.3.x minimum.

1 Like