【问题标题】:logstash-2.2.2, windows, IIS log file formatlogstash-2.2.2、windows、IIS日志文件格式
【发布时间】:2016-03-26 06:19:18
【问题描述】:

当我以 UTF-8 格式解析 iis 日志文件时,出现以下错误,当我使用 ANSI 格式解析日志文件时,Logstash 没有任何工作,只是在控制台上显示消息“Logstash 启动已完成”。我的服务器上有近 1000 个文件,我无法将每种文件格式从 ANSI 更改为 UTF-8。你能帮我在我的配置文件中更改哪里吗?当我解析 UTF-8 格式的文件时,我还附加了调试文件。我在同一个盒子上使用弹性搜索,它完全工作正常。我还可以使用 127.0.0.1 远程登录端口 9200。

日志样本:

2016-03-26T05:40:40.764Z WIN-AK44913P759 2016-03-24 00:16:31 W3SVC20 ODSANDBOXWEB01 172.x.x.x GET /healthmonitor.axd - 80 - 172.x.x.x HTTP/1.1 - - - www.xyz.net 200 0 0 4698 122 531

标准输出:

{
  "message" => "2016-03-24 04:43:02 W3SVC20 ODSANDBOXWEB01 172.x.x.x GET /healthmonitor.axd - 80 - 172.x.x.x HTTP/1.1 - - - www.xyz.net 200 0 0 4698 122 703\r",
  "@version" => "1",
  "@timestamp" => "2016-03-26T05:42:15.045Z",
  "path" => "C:\\IISLogs/u_ex160324.log",
  "host" => "WIN-AK44913P759",
  "type" => "IISLog",
  "tags" => [
     [0] "_grokparsefailure"
  ]
}  

下面是我的logstash conf文件配置

input {
  file {
    type => "IISLog"
    path => "C:\IISLogs/u_ex*.log"
    start_position => "beginning"
  }
}
filter {
  #ignore log comments
  if [message] =~ "^#" {
    drop {}
  }
  grok {
    match => ["message", "%{TIMESTAMP_ISO8601:log_timestamp} %{WORD:iisSite} %{IPORHOST:site} %{WORD:method} %{URIPATH:page} %{NOTSPACE:querystring} %{NUMBER:port} %{NOTSPACE:username} %{IPORHOST:clienthost} %{NOTSPACE:useragent} %{NOTSPACE:referer} %{NUMBER:response} %{NUMBER:subresponse} %{NUMBER:scstatus} %{NUMBER:bytes:int} %{NUMBER:timetaken:int}"]
  }
  #Set the Event Timesteamp from the log
  date {
    match => [ "log_timestamp", "YYYY-MM-dd HH:mm:ss" ]
    timezone => "Etc/UCT"
  }
  useragent {
    source=> "useragent"
    prefix=> "browser"
  }
  mutate {
    remove_field => [ "log_timestamp"]
  }
}
# output logs to console and to elasticsearch
output {
  stdout {}
  elasticsearch {
    hosts => ["127.0.0.1:9200"]
  }
  stdout {
    codec => rubydebug
  }
}

【问题讨论】:

    标签: elasticsearch logstash logstash-grok


    【解决方案1】:

    _grokparsefailure 标记表示您的 grok 模式与您的输入不匹配。看起来您打算让模式跳过前两个字段,这很好。

    然后,查看接下来的四个字段,我看到了:

    2016-03-24 00:16:31 W3SVC20 ODSANDBOXWEB01 172.1.1.1
    

    但你的模式正在寻找

    %{TIMESTAMP_ISO8601:log_timestamp} %{WORD:iisSite} %{IPORHOST:site} %{WORD:method}
    

    您没有考虑 IP 地址(因为 ODSANDBOXWEB01 将进入 [站点])。

    构建 grok 模式是一个深思熟虑的迭代过程。从debugger 开始。输入示例输入行,然后添加 grok 模式 - 一次一个! - 直到整行匹配。

    此外,当您混淆数据时,请将其保留为有效数据。将 ip 更改为 172.x.x.x 意味着它不会匹配 %{IP} 模式,而我们不必弄清楚你做了什么。在本例中,我将其更改为 172.1.1.1。

    【讨论】:

    • 嗨阿兰,感谢更新。在我的情况下 172.x.x.x 意味着是正常的 IP 地址格式。是否有任何帮助可用于构建 Grok 模式。我对 Elastic search 和 logstash 并不陌生。
    • 我知道 172.x.x.x 是什么意思,但是由于该输入永远不会匹配 %{IP},因此您让我们这些试图帮助您做更多工作来调试您的模式的人。如果您已将其更改为其他一些有效的 IP,则调试起来会更容易。至于学习grok,或许从这里开始:svops.com/blog/introduction-to-logstash-grok-patterns
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多