如何使用XPath为Logstash提取XML属性

时间:2017-04-20 19:40:03

标签: xml elasticsearch xpath logstash elastic-stack

我试图在XML下面解析以获取所有类名,名称,失败和错误消息。但是我无法使用xpath提取单个xml元素。有人能指出我哪里出错了吗?

<testsuite errors="1" failures="1">
    <testcase classname="junit.framework.TestSuite" name="com.webdashboard.Report" time="0.0">
           <failure message="Login failed: User labuser"></failure>
    </testcase>
    <testcase classname="junit.framework.TestSuite" name="com.webdashboard.Report" time="0.002">
           <error message="no service found defining interface"> </error>
    </testcase>
</testsuite>

这是我的配置文件,用于提取classname。但它无法正常工作:(

input {
 file {
  path => "/home/jar/Documents/xml/*.xml"
  start_position => beginning
  codec => multiline
  {
   pattern => "^<\?testsuite .*\>"
   negate => true
   what => "previous"
  }
 }
}

filter {
  xml {
   source => "src"
   target => "testsuite"
   xpath =>
   [
    "//testcase/@classname", "classname"
   ]
}

if "message" in [tags] {
          drop { }
}


date {
    match => [ "date" , "dd-MM-yyyy HH:mm:ss" ]
    timezone => "Europe/Amsterdam"
}

}

output {
 file {
        path => "/home/jar/Documents/xml/output2.txt"
  }
}

0 个答案:

没有答案