我在阅读How to reference environment variables in logstash configuration file?后来到这里。
不幸的是它对我不起作用。 我正在跑步:
bin/logstash -f my_filters.conf --debug
我的配置文件是:
input {
file {
path => "/tmp/${RUN_ID}/*.txt"
start_position => beginning
sincedb_path => "/dev/null"
ignore_older => 0
}
}
output {
elasticsearch {
hosts => [ "localhost:9200" ]
index => "${RUN_ID}"
}
}
并没有创建新索引。 在设置后
export RUN_ID=500
例如。
如果我将配置更改为具有硬编码值(例如500),则创建索引时没有问题。
我已阅读documentation,它正好提到了我现在正在做的事情......
我做错了什么,我怎样才能使环境变量有效?
答案 0 :(得分:4)
Logstash 2.4需要--allow-env
的命令行参数来进行环境替换。
没有旗帜,它不会抱怨(但不起作用)
bin/logstash -f test.conf
Settings: Default pipeline workers: 8
Pipeline main started
有了旗帜,如果你没有设置它就会抱怨:
bin/logstash --allow-env -f test.conf
fetched an invalid config {:config=>"input {\n file {\n path => \"/tmp/${RUN_ID}/*.txt\"\n start_position => beginning\n sincedb_path => \"/dev/null\"\n ignore_older => 0\n }\n}\n\noutput {\nstdout { codec=>rubydebug}\n elasticsearch {\n hosts => [ \"localhost:9200\" ]\n index => \"${RUN_ID}\"\n }\n}\n\n\n", :reason=>"Cannot evaluate `${RUN_ID}`. Environment variable `RUN_ID` is not set and there is no default value given.", :level=>:error}
当然,有了论点和旗帜,一切正常:
export RUN_ID=10
bin/logstash --allow-env -f test.conf
Pipeline main started
{
"message" => "asdfasdf",
"@version" => "1",
"@timestamp" => "2016-11-01T21:10:15.964Z",
"path" => "/tmp/10/test.txt",
"host" => "XXXXXXXXX.local"
}