【问题标题】:Parsing XML with Xpath on logstash在 logstash 上使用 Xpath 解析 XML
【发布时间】:2018-11-14 20:50:35
【问题描述】:

我是 XML 解析的新手,我正在尝试使用包含多个 XML 日志的多个文件的文件夹/我正在使用 filebeat 将日志推送到 logstash。

这是我的 LOGSTASH 配置:

  input {
  beats {
     port => 5044
   }
 }
 filter{
   xml{
    target => "doc"
    store_xml => false
    source => "message"
    xpath =>
    ["/E2ETraceEvent/System/EventID/@EventID", "event_id",
     "/E2ETraceEvent/System/Type/@Type", "type",
     "/E2ETraceEvent/System/SubType/@SubType", "name",
     "/E2ETraceEvent/System/Level/@Level", "level",
     "/E2ETraceEvent/System/TimeCreated/@TimeCreated", "time"]
 }
 }
 output {
 stdout { codec => rubydebug }
   elasticsearch {
     hosts => "100.101.15.181:9200"
     manage_template => false
     index => "t11-%{+YYYY.MM}"
   }
 }

这里是一行 XML 日志的示例:

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>0</EventID><Type>3</Type><SubType Name="Information">0</SubType><Level>8</Level><TimeCreated SystemTime="2018-04-30T14:10:24.9708868Z" /><Source Name="All Events" /><Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" /><Execution ProcessName="w3wp" ProcessID="5840" ThreadID="6" /><Channel/><Computer>T-XXXX</Computer></System><ApplicationData><TraceData><DataItem>Timestamp: 4/30/2018 10:10:24 AM&#xD;&#xA;Message: T-XXX &#xD;&#xA;Method: XXX.Common.Config.Config:System.Object GetConfigFromDB(System.String, System.String, System.String) &#xD;&#xA;XXXX.Common.Config.Config:GetConfigFromDB: Done reading key:ClientAccountBaseURL for ApplicatioName:XXXX.DataLayer.AppDomainKey. value:https://test.XXXX.com/account&#xD;&#xA;&#xD;&#xA;Category: Information&#xD;&#xA;Priority: 8&#xD;&#xA;EventId: 0&#xD;&#xA;Severity: Information&#xD;&#xA;Title:T-XXXX &#xD;&#xA;Method: XXXX.Common.Config.Config:System.Object GetConfigFromDB(System.String, System.String, System.String) &#xD;&#xA;XXXX.Common.Config.Config:GetConfigFromDB: Done reading key:ClientAccountBaseURL for ApplicatioName:XXXX.DataLayer.AppDomainKey. value:https://test.XXXX.com/account&#xD;&#xA;&#xD;&#xA;Machine: T-XXXX&#xD;&#xA;App Domain: /YY/GGGG/1/ROOT/UnlistedUpgrade-1-131695710240192502&#xD;&#xA;ProcessId: 5840&#xD;&#xA;Process Name: c:\windows\system32\inetsrv\w3wp.exe&#xD;&#xA;Thread Name: &#xD;&#xA;Win32 ThreadId:4760&#xD;&#xA;Extended Properties: </DataItem></TraceData></ApplicationData></E2ETraceEvent>

在我的 conf 中,由于复杂性,我尝试只解析几列 的日志,我需要解析所有的日志数据。

我已经用了几天了,我在 logstash 日志或 filebeat 上没有收到任何错误 但没有数据插入 ELASTIC。

有人可以帮我理解如何解决吗?

提前致谢。

【问题讨论】:

    标签: xpath xml-parsing logstash


    【解决方案1】:

    试试:

       xml{
        target => "doc"
        store_xml => false
        source => "message"
        xpath =>
        ["//EventID/text()", "event_id",
         "//Type/text()", "type",
         "//SubType/text()", "name",
         "//Level/text()", "level",
         "//TimeCreated/@SystemTime", "time"]
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-21
      • 1970-01-01
      • 1970-01-01
      • 2013-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多