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

Hi!

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

index_name-2019.09-node1

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

I try

@echo HOSTNAME

and I have this result

logstash_node_1

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

index_name-2019.09_12345.txt

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:

Environment="logstashnode=n1"

And now in the pipeline set:

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

Now, the file it creates is named:

index_name-2019.09_n1.txt

Thank you very much!

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