Logstash:使用环境变量

gpnt7bae  于 2022-12-09  发布在  Logstash
关注(0)|答案(3)|浏览(293)

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 ?

dba5bblo

dba5bblo1#

根据https://www.elastic.co/guide/en/logstash/current/environment-variables.html,本文档${var}仅在以下情况下工作。

  • 端口=〉“${TCP端口}”,导出TCP端口=12345
  • 添加标签=〉[“标签1”,“${环境标签}”],导出环境标签=“标签2”
  • 添加字段=〉{“我的路径”=〉“${HOME}/文件.log”,导出HOME="/路径”

但在您代码中,您在以下位置使用了${var}。'path' =〉["/share/log-${INPUT_DATE}.json”]在此处/log-也必须在变量中。export INPUT_DATE=“log-2017.09.07.json”
根据文档示例,他们将此函数用于少数事件,而不是所有情况。

ojsjcaue

ojsjcaue2#

1.[If your logstash is in a docker container]在docker-compose.yml中将变量设置为默认值(仅其名称):
环境:- 输入日期
1.您需要在同一个命令行会话中运行export INPUT_DATE="2017.09.07"并启动Docker。

j2datikz

j2datikz3#

未在中定义替换变量INPUT_DATE

  • Logstash机密存储区
  • 或作为环境条目
  • 且没有给定默认值。",

这可能意味着Logstash.conf文件无法访问从外部shell脚本设置的环境变量。

相关问题