gpt4 book ai didi

filter - Logstash 用系统日志日期替换@timestamp

转载 作者:行者123 更新时间:2023-12-04 05:24:20 25 4
gpt4 key购买 nike

我有点困惑。我正在尝试拔出 syslog date (backfilling the logstash)并替换 @timestamp用它。我几乎什么都试过了。

这是我的过滤器

filter {
if [type] == "syslog" {
grok {
match => {
"message" => ["%{SYSLOGTIMESTAMP:DATETIME} %{WORD:SERVER} (?<BINARY>(.*?)(php\-cgi|php))\: %{DATA:PHP_ERROR_TYPE}\:\s\s(?<PHP_ERROR_DESC>(.*?)(e\s\d))""]
}
}

date {
match => { "DATETIME" => [ "MMM d HH:mm:ss", "MMM dd HH:mm:ss", "ISO8601" ] }
target => "@timestamp"
add_tag => [ "tmatch" ]
}

if !("_grokparsefailure" in [tags]) {
mutate {
replace => [ "@source_host", "%{SERVER}" ]
}
}
mutate {
remove_field => [ "SERVER" ]
}
}
}

示例输出:
{
"message" => "Sep 10 00:00:00 xxxxxxx",
"@timestamp" => "2013-12-05T13:29:35.169Z",
"@version" => "1",
"type" => "xxxx",
"host" => "127.0.0.1:xxx",
"DATETIME" => "Sep 10 00:00:00",
"BINARY" => "xxxx",
"PHP_ERROR_TYPE" => "xxxx",
"PHP_ERROR_DESC" => "xxxxx",
"tags" => [
[0] "tmatch"
],
"@source_host" => "xxx"
}

tmatch 在标签中,所以我假设日期过滤器有效,但为什么我仍然有:
@timestamp => "2013-12-05T13:29:35.169Z"

?

感谢您的帮助(我的 logstashlogstash-1.2.2-flatjar.jar)

最佳答案

让我们来看看您的日期过滤器:

date {
match => { "DATETIME" => [ "MMM d HH:mm:ss", "MMM dd HH:mm:ss", "ISO8601" ] }
target => "@timestamp"
add_tag => [ "tmatch" ]
}

特别是 match范围:
match => { "DATETIME" => [ "MMM  d HH:mm:ss", "MMM dd HH:mm:ss", "ISO8601" ] }

匹配需要一个数组。我不确定你传递的是什么,确切地说,但它绝对不是一个数组。我试着用 -v 运行它,我很惊讶地发现它没有提示。

您的意思可能更接近于此:
match => ["DATETIME", "MMM  d HH:mm:ss", "MMM dd HH:mm:ss", "ISO8601"]

注意数组的第一个元素是目标字段;附加元素是要匹配的模式。

在那之后,您实际上只需要传递您期望的一种格式,但看起来它包含在您发送的三种格式中。

关于filter - Logstash 用系统日志日期替换@timestamp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20401663/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com