Set a environment variable as a part of the path in Output file


I have two logstash nodes in a cluster
I want both Logstash to output a txt file with a name something like


being "node1" the HOSTNAME of the logstash node. So each logstash node would output a diferent file name.

I try


and I have this result


My logstash output config looks like

output {
    file {
			id => "outputTest"
			path => "/test/index_name-%{+YYYY-MM}_${HOSTNAME:12345}.txt"
			codec => line { format => "%{message}"}

However, the text file name it creates is


I start logstash as a service by typing:

sudo systemctl start logstash.service

Thanks a lot in advance!

Although there is a HOSTNAME environment variable for login shells, that does not mean it is set for services. This explains how to get an environment variable set for a service.

Hi Badger!

Thanks a lot, you were right, I modified logstash.service, adding this line in the [Service] section:


And now in the pipeline set:

path => "/test/index_name-%{+YYYY-MM}_${logstashnode}.txt"

Now, the file it creates is named:


Thank you very much!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.