XML 格式数据
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<details>
<id>544538</id>
<name>john</icUrl>
<version>2.0.0-10</version>
<OptionalValues>
<metaData>
<name>Severity</name>
<value>Medium</value>
</metaData>
<metaData>
<name>Prioriry</name>
<value>5</value>
</metaData>
<OptionalValues>
<issue>
<summary>summary value</summary>
<description>It is possible to misconfigure an EtherChannel and create a spanning-tree loop. This misconfiguration would potentially overwhelm the switch process. Cisco IOS System Software includes a feature called 'spanning-tree etherchannel guard misconfig' to prevent this issue.</description>
</issue>
</details>
使用logstash,我需要像这样转换。ID,名称,版本,严重性,优先级,摘要,描述 .. 我如何将 xml 转换为 json 输出。我试图在应用所有字段之前解析 id 字段。
input {
file {
path => "C:/Users/Desktop/mydata.xml"
start_position => "beginning"
sincedb_path => "/dev/null"
}
}
filter {
xml {
source => "message"
force_array => false
remove_namespaces =>true
store_xml => true
target => "doc"
xpath => [
"details/id", "myid"
]
}
}
output
{
stdout{
codec => line {
format => "%{[myid]}"
}
}
}
在执行时,我在控制台中开始清空 myid 值。还告诉我格式化为 json 后如何重定向到 es 索引。