0
我使用logstash,我想知道是否有處理以下方式:鍵值對logstash陣列
使用XML過濾器我能提取屬性字段中
<?xml version="1.0"?>
<event logger="RemoteEventReceiver1" timestamp="2016-07-21T12:39:04.0607421-05:00" level="DEBUG" thread="26" domain="/LM/W3SVC/2/ROOT-1-131135962764935573" username="TOOTHLESS\dvdp4">
<message>Test nessage</message>
<properties>
<data name="log4net:HostName" value="Toothless"/>
<data name="log4net:Customer" value="Bob"/>
</properties>
</event>
,看起來像這樣
"properties" => [
[0] {
"data" => [
[0] {
"name" => "HostName",
"value" => "Toothless"
},
[1] {
"name" => "Customer",
"value" => "Bob"
}
]
}
]
我怎樣才能將其轉換爲這個?
「propertiesParsed」 => {
「HostName」 => 「Toothless」,
「Customer」 => 「Bob」
}
* UPDATE ADDING CONFIG文件和數據文件*
input {
file {
type => "log4net"
path => ["D:/temp/MR4SPO.log"]
start_position => "beginning"
sincedb_path => "nul"
}
}
filter
{
mutate {
# remove xml prefices in the message field
gsub => [ "message", "log4net:", "" ]
}
xml {
source => "message"
target => "log4net"
add_field => {
log4net_message => "%{[log4net][message]}"
# "[log4net][messagetest]" => [log4net][message]
# xxx => "%{[log4net][properties][0][data]}"
}
remove_field => "message"
}
# get json message from log4net
if [log4net_message] =~ "^LS:\s{" {
ruby { code => "event['log4net_message'] = event['log4net_message'][3..-1]" }
json {
source => "log4net_message"
# target => "log4net_json"
}
mutate {
add_field => { forMQ => true }
}
}
mutate {
remove_field => "log4net_message"
}
}
# output logs to console and to elasticsearch
output {
if [forMQ] {
stdout { codec => rubydebug }
}
# elasticsearch { hosts => ["localhost:9200"] }
}
* DATA FILE *
<log4net:event logger="SPMRDLAdd_InWeb.Services.RemoteEventReceiver1" timestamp="2016-07-21T12:39:03.0607421-05:00" level="DEBUG" thread="26" domain="/LM/W3SVC/2/ROOT-1-131135962764935573" username="TOOTHLESS\dvdp4"><log4net:message>My test one</log4net:message><log4net:properties><log4net:data name="log4net:HostName" value="Toothless" /></log4net:properties></log4net:event>
<log4net:event logger="SPMRDLAdd_InWeb.Services.RemoteEventReceiver1" timestamp="2016-07-21T12:39:04.0607421-05:00" level="DEBUG" thread="26" domain="/LM/W3SVC/2/ROOT-1-131135962764935573" username="TOOTHLESS\dvdp4"><log4net:message>LS: { "name" : "file123.jpg", "size" : 50 }</log4net:message><log4net:properties><log4net:data name="log4net:HostName" value="Toothless" /></log4net:properties></log4net:event>
你可以顯示你的conf? – alpert
更新了帖子 –