将filebeat中的文件路径提取到logstash中,然后提取到弹性索引中

发布于 2025-01-15 03:15:46 字数 1213 浏览 6 评论 0原文

我正在尝试获取路径的一部分并将其作为我的elasticsearch 索引的索引。

我的logstash配置文件看起来像这样(注意:配置文件可能是错误的,因为我尝试了100种不同的东西)

# The # character at the beginning of a line indicates a comment. Use
# comments to describe your configuration.
input {
    beats {
            port => "5044"
        }
}
# The filter part of this file is commented out to indicate that it is
# optional.
filter {
  grok {
      match => ["[log][file][path]", "c:\\PL_Logs\\%{GREEDYDATA:index_name}\\%{GREEDYDATA}" ]
  }
}
#output {
# stdout { codec => rubydebug }
#}
output {
   elasticsearch {
        hosts => [ "localhost:9222" ]
        index => "%{index_name}-%{+YYYY.MM.dd}"
   }
    stdout { codec => rubydebug }
}

我的日志是这样归档的 C:\Incoming_Logs\requested_pa​​rt\somesubfolder_doesnt_matter\2022\03\18\2022031814.txt

我的 filebeat 配置是这样的:

filebeat.inputs:
- type: log
  enabled: true
  paths:
    - c:\Incoming_Logs\**\*.txt

我的问题是我该如何采取我的路径中的 requested_pa​​rt 部分并将其设为索引? 我尝试了很多事情,比如用 [] (%[{index_name}]) 覆盖索引我尝试匹配“path”而不是“[log][file][path]”我已将 grok 条件更改为“c:\PL_Logs\%{GREEDYDATA:index_name}\**”,我也尝试使用“/”而不是双“\”

有人能指出我在这里做错了什么吗?

I'm trying to take a part of my path and give it as index to my elasticsearch index.

my logstash config file looks like this (Note: the config file might be wrong cuz I tried 100 different things)

# The # character at the beginning of a line indicates a comment. Use
# comments to describe your configuration.
input {
    beats {
            port => "5044"
        }
}
# The filter part of this file is commented out to indicate that it is
# optional.
filter {
  grok {
      match => ["[log][file][path]", "c:\\PL_Logs\\%{GREEDYDATA:index_name}\\%{GREEDYDATA}" ]
  }
}
#output {
# stdout { codec => rubydebug }
#}
output {
   elasticsearch {
        hosts => [ "localhost:9222" ]
        index => "%{index_name}-%{+YYYY.MM.dd}"
   }
    stdout { codec => rubydebug }
}

my logs are filed like this C:\Incoming_Logs\requested_part\somesubfolder_doesnt_matter\2022\03\18\2022031814.txt

my filebeat config is this:

filebeat.inputs:
- type: log
  enabled: true
  paths:
    - c:\Incoming_Logs\**\*.txt

My question is how can I take the requested_part part from my path and make it an index?
I've tried many things like covering the index with [] (%[{index_name}]) I tried to match with "path" instead of "[log][file][path]" I've changed the grok condition to "c:\PL_Logs\%{GREEDYDATA:index_name}\**" and I've also tried to use "/" instead of double "\"

Can someone point me out what I'm doing wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遇见了你 2025-01-22 03:15:46

我从这个问题中找到了适合我的 grok 匹配 如何在 Logstash 中获取部分 Filebeat 源文件名

我是这样制作的
<代码> 匹配 => { "[日志][文件][路径]" =>; ".*(\\|\/)(?.*)(\\|\/).*.*(\\|\/).*(\\|\/).*(\ \|\/).*(\\|\/)" }

它有效,但如果有人可以提供帮助,我更喜​​欢更优雅的正则表达式。

I found the grok match that works for me from this question How to get parts of Filebeat source filename in Logstash

I made mine like this
match => { "[log][file][path]" => ".*(\\|\/)(?<myIndex>.*)(\\|\/).*.*(\\|\/).*(\\|\/).*(\\|\/).*(\\|\/)" }

It works but I prefer a more elegance regex if someone can help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文