I have tried to follow the documentation https://www.elastic.co/guide/en/logstash/current/environment-variables.html but it does not seem to work.
I have a bunch of log files to process. Say I have an input file /share/log-2017.09.07.json that I am trying to process with logstash.
An excerpt of my logstash config file is as follows :
input { file {
'exclude' => ['*.gz']
'path' => ["/share/log-${INPUT_DATE}.json"]
'type' => 'json'
start_position => "beginning"
codec => json
sincedb_path => "/dev/null"
}
}
I launch logstash as follows :
export INPUT_DATE="2017.09.07"
logstash -f myconfigfile.conf
The logstash does not seem to find the file /share/log-2017.09.03.json. When I replace
'path' => ["/share/log-${INPUT_DATE}.json"]
by
'path' => ["/share/log-2017.09.07.json"]
it works.
What am I doing wrong ?
3条答案
按热度按时间dba5bblo1#
根据https://www.elastic.co/guide/en/logstash/current/environment-variables.html,本文档${var}仅在以下情况下工作。
但在您代码中,您在以下位置使用了${var}。'path' =〉["/share/log-${INPUT_DATE}.json”]在此处/log-也必须在变量中。export INPUT_DATE=“log-2017.09.07.json”
根据文档示例,他们将此函数用于少数事件,而不是所有情况。
ojsjcaue2#
1.[If your logstash is in a docker container]在docker-compose.yml中将变量设置为默认值(仅其名称):
环境:- 输入日期
1.您需要在同一个命令行会话中运行
export INPUT_DATE="2017.09.07"
并启动Docker。j2datikz3#
未在中定义替换变量
INPUT_DATE
这可能意味着Logstash.conf文件无法访问从外部shell脚本设置的环境变量。