0

首先感谢您的任何建议和您的时间。

我最近为刚开始工作的公司设置了一个 Elk 堆栈。(这是我第一次使用 Logstash 和 Nxlog。)我想做的是使用 nxlog 将 IIS 日志和 EventLogs 从同一个网络服务器发送到 logstash。

我只是不明白如何从一个来源发送两种类型的日志并让 logstash.conf 正确过滤这些数据。

这是我的 nxlog.conf

## This is a sample configuration file. See the nxlog reference manual about the
## configuration options. It should be installed locally and is also available
## online at http://nxlog.org/nxlog-docs/en/nxlog-reference-manual.html

## Please set the ROOT to the folder your nxlog was installed into,
## otherwise it will not start.

#define ROOT C:\Program Files\nxlog
define ROOT C:\Program Files (x86)\nxlog

Moduledir %ROOT%\modules
CacheDir %ROOT%\data
Pidfile %ROOT%\data\nxlog.pid
SpoolDir %ROOT%\data
LogFile %ROOT%\data\nxlog.log

<Extension json>
    Module xm_json
</Extension>
<Input iis_1>  
      Module    im_file
      File    "F:\inetpub\logs\LogFiles\W3SVC1\u_ex*.log"
    ReadFromLast True
    SavePos True
    Exec    if $raw_event =~ /^#/ drop();
</Input>  
<Input iis_2>  
      Module    im_file
      File    "F:\inetpub\logs\LogFiles\W3SVC2\u_ex*.log"
    ReadFromLast True
    SavePos True
    Exec    if $raw_event =~ /^#/ drop();
</Input>
<Input iis_4>  
      Module    im_file
      File    "F:\inetpub\logs\LogFiles\W3SVC4\u_ex*.log"
    ReadFromLast True
    SavePos True
    Exec    if $raw_event =~ /^#/ drop();
</Input>  
<Input eventlog>
        Module im_msvistalog
        Exec $EventReceivedTime = integer($EventReceivedTime) / 1000000; to_json();
</Input>
<Output out_iis>  
    Module  om_tcp
    Host    10.191.132.86
    Port    5555
    OutputType  LineBased
</Output>  
<Route 1>  
    Path    iis_1, iis_2, iis_4, eventlog=> out_iis
</Route> 

我当前的 logstash.conf

input {  
      tcp {
              type => "iis"
              port => 5555
              host => "10.191.132.86"
      }
}
filter {  
    if [type] == "iis" {
        grok {
            match => ["@message", "%{TIMESTAMP_ISO8601:timestamp} %{IPORHOST:hostip} %{WORD:method} %{URIPATH:page} %{NOTSPACE:query} %{NUMBER:port} %{NOTSPACE:username} %{IPORHOST:clientip} %{NOTSPACE:useragent} %{NOTSPACE:referrer} %{NUMBER:response} %{NUMBER:subresponse} %{NUMBER:scstatus} %{NUMBER:timetaken}"]
        }
    }
}
output {  
    elasticsearch {
    protocol => "http"
        host => "10.191.132.86"
        port => "9200"
    }
}

看起来您可以通过设置类型和执行 if type else this type 来过滤不同的数据。但是,如果它们来自同一来源,我该如何指定不同的类型?

:) 谢谢!

4

2 回答 2

1

NXLog使用值iis_1iis_2等设置字段SourceModuleName。您可能希望使用它来代替。

于 2015-04-18T10:14:26.737 回答
0

A way to do this is filter by a known record entry in each log and wont exist in the other, for example [cs_bytes etc]:

e.g.

if [iisfield] {
   mark type as IIS
else 
   mark type as EventLog
}

I have written a IIS and Event log agent that captures logs for Logit.io they might already do everything you already want

于 2015-04-17T19:27:25.530 回答