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

标签 filter timestamp logstash syslog logstash-grok

我有点困惑。我正在尝试拔出 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/

相关文章:

android - 如何从通知中删除时间计数器?

Elasticsearch 字段限制超过 1000

elasticsearch - 为什么filebeat只需要cert,metricbeat需要key、c​​a和cert?

python - django 查询集过滤器日期时间字段

css - IE 中的元素旋转和调整大小(jQuery UI + CSS)

hibernate - 在 hibernate 过滤器中运行代码

PHP/MySQL 时间戳和时区

pandas - 从 Pandas 数据框中删除 'dominated' 行(所有值都低于任何其他行的值的行)

php - 如何使用时间戳对元素进行计数

logstash - 在 Logstash 中将日期转换为 UNIX 时间