2015-07-11 177 views
0

我有以下logstash的conf文件:解析XML文件LogStash

input { 
file 
{ 
    path => "C:\Dashboard\Elmah\*.xml" 
    start_position => "beginning" 
    type => "error" 
    codec => multiline 
    { 
     pattern => "^<\?error .*\>" 
     negate => true 
     what => "previous" 
    } 
    sincedb_path => "C:\Dashboard\Elmah" 
    } 
} 

filter 
{ 
    xml 
    { 
     source => "error" 
     xpath => 
     [ 
      "/error/@errorId", "ErrorId", 
      "/error/@type", "Type", 
      "/error/@message", "Message", 
      "/error/@time", "Time", 
      "/error/@user", "User" 
     ] 
     store_xml => true 
    } 
} 

output 
{ 
    elasticsearch 
    { 
     action => "index" 
     host => "localhost" 
     index => "stock" 
     workers => 1 
    } 
    stdout 
    { 
     codec => rubydebug 
    } 
} 

當我運行斌/ logstash -f agent.conf我沒有得到一個錯誤,但沒有數據被插入到Elasticsearch。該文件的一個示例是: https://www.dropbox.com/s/6oni2zhorsdtz6p/error-2015-06-26203423Z-3026bd43-07d6-44d6-a6cf-6d27b28a607e.xml?dl=0

如何讓Logstash讀取外部xml文件的集合?

LogStash調試輸出:

Please see here: https://www.dropbox.com/s/g7g1154uvf9fr1f/outputlog2.txt?dl=0 
+0

你從stdout {}的輸出中得到了什麼? –

+0

@AlainCollins:我添加了你請求的信息 –

+0

我的意思是你的logstash stdout(你有一個輸出節引用它)。 –

回答

0

我不知道,你可以在這裏使用的文件輸入 - 我只看到它用於監視文件的變化,而不是監視新文件。除非你的XML文件被更新,否則我不認爲它會做任何事情。請記住,logstash通常會監視新的日誌行。

大多數人寫的工具,如下面的處理在批處理整個文件:

https://github.com/elastic/elasticsearch-river-wikipedia

https://github.com/andrewvc/wikiparse

https://github.com/elastic/stream2es

這些工具,特別是最後一個,似乎更接近你用例。

+0

如果您嘗試運行(重複)進行測試,請刪除sincedb文件或將路徑設置爲/ dev/null。 –

+0

@Martin:Stream2es似乎不支持解析xml文件。 –

+0

@AlainCollins:在C:\ Dashboard \ Elmah文件夾中未創建任何文件。我將「sincedb_path」更改爲/ dev/null,並再次運行LogStash和ElasticSearch,但得到了相同的結果。 –

0

我已經成功地使用以下logstash配置來處理每行上包含一個xml文檔的文件。希望這個幫助!

input { 
    file { 
     path => "/tmp/logstash/test.log" 
      start_position => "beginning" 
      sincedb_path => "/dev/null" 
    } 
} 

filter { 
    xml { 
     source => "message" 
      force_array => false 
      xpath => [ 
      "/Event/@timestamp", "time", 
      "/Event/user[1]/id[1]/text()", "user", 
      "/Event/user[1]/ip[1]/text()[1]", "ip", 
      "/Event/@eventType", "eventType", 
      "/Event/transactionDuration/text()", "trxDuration", 
      ] 
      store_xml => true 
    } 
} 

output 
{ 
    stdout{ 
     codec => line {  
      format => "%{[time]} %{[user]} %{[eventType]} %{[trxDuration]}" 
     } 
    } 
}