从事件逐个删除字段

编程入门 行业动态 更新时间:2024-10-28 04:17:33
本文介绍了从事件逐个删除字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以我使用标准的ELK堆栈来分析Apache访问日志,这是非常有效的,但是我正在使用KV过滤器将URL参数作为字段进行分析,以便让我更好地查询。我的问题是,我正在分析的应用程序具有缓存清除动态生成的参数,这导致了成千上万的字段,每次出现一次。 ElasticSearch似乎有这样的严重问题,他们对我没有价值,所以我想删除它们。以下是模式的一个示例:

GET / page?rand123PQY = ABC& other_var = something GET / page ?rand987ZDQ = DEF& other_var = something

在上面的示例中,我要删除的参数启动'rand'。目前,我的logstash.conf使用grok从访问日志中提取字段,其次是kv来提取Query字符串参数:

过滤器{ grok { path => /var/log/apache/access.log type => apache-access} kv { field_split =>与 &? } } 有没有办法可以过滤匹配模式的任何字段 rand [A-Z0- 9] * = [A-Z0-9] * ?我看到的大多数例子都是按照确切名称定位字段,我不能使用。我想知道将请求字段正则化到一个新的字段中,运行KV,然后删除它。这个工作吗?

解决方案

如果您对感兴趣的字段集是已知的定义您可以为 kv过滤器,使用突变过滤器将有趣的字段移到消息的顶层,并删除该字段嵌套的键/值对。我认为这完全是你建议的。

或者你可以使用一个 ruby​​ filter :

filter { ruby​​ { code => event.to_hash.keys.each {| k | 如果k.start_with?('rand') event.remove(k) end } } }

So I'm using a standard ELK stack to analyse Apache access logs, which is working well, but I'm looking to break out URL parameters as fields, using the KV filter, in order to allow me to write better queries.

My problem is that that app I'm analysing has 'cache-busting' dynamically generated parameters, which leads to tens of thousands of 'fields', each occurring once. ElasticSearch seems have severe trouble with this and they have no value to me, so I'd like to remove them. Below is an example of the pattern

GET /page?rand123PQY=ABC&other_var=something GET /page?rand987ZDQ=DEF&other_var=something

In the example above, the parameters I want to remove start 'rand'. Currently my logstash.conf uses grok to extract fields from the access logs, followed by kv to extract Query string parameters:

filter { grok { path => "/var/log/apache/access.log" type => "apache-access" } kv { field_split => "&?" } } Is there a way I can filter out any fields matching the pattern rand[A-Z0-9]*=[A-Z0-9]*? Most examples I've seen are targeting fields by exact name, which I cannot use. I did wonder about regexing the request field into a new field, running KV on that, then removing it. Would that work?

解决方案

If the set of fields that you are interested in is known and well-defined you could set target for the kv filter, move the interesting fields to the top level of the message with a mutate filter and delete the field with the nested key/value pairs. I think this is pretty much what you suggested at the end.

Alternatively you could use a ruby filter:

filter { ruby { code => " event.to_hash.keys.each { |k| if k.start_with?('rand') event.remove(k) end } " } }

更多推荐

从事件逐个删除字段

本文发布于:2023-11-11 13:39:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1578598.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   事件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!