如何在 logstash 配置文件中使用当前日期作为输入文件

How to use current date in logstash config file as input file

我正在尝试在 Logstash 中处理名称为 "YYYYMMDD.json" 的当前日期文件。但是我不能在此配置文件中使用日期变量。如果不对日期进行硬编码,是否仍然可以这样做?

input {
        file {
                path => "/home/ubuntu/YYYYMMDD.json
                        type => "ip-address"
                        start_position => "beginning"
                        sincedb_path => "/dev/null"
        }
}
filter {
        json {
                source => "message"
        }
}
output {
        elasticsearch {
                hosts => ["IP:Port"]
                        index => "results"
                        document_id => "%{ip}"
                        doc_as_upsert => true
                        action => "update"
                        retry_on_conflict => 10
        }
}

path 中,您在路径末尾缺少 "

path => "/home/ubuntu/YYYYMMDD.json"

试试这个

file {
    path => "/home/ubuntu/%{+YYYYMMDD}.json"
    type => "ip-address"
    start_position => "beginning"
    sincedb_path => "/dev/null"
}

您可以使用:path => "/home/ubuntu/*.json" 并解析文件夹中的所有 JSON。

每天添加一个文件就可以使用filebeats