Hello,
I have an XML structure
<?xml version="1.0" ?>
<XMLdata>
<Policy>
<policyName>Arena Standard</policyName>
<Preferences>
<ServerPreferences>max_simult_tcp_sessions></ServerPreferences>
</Preferences>
</Policy>
<Report name="Scan">
<ReportHost name="huit.com">
<HostProperties>
<tag name="LastUnauthenticatedResults">111111</tag>
<tag name="Credentialed_Scan">false</tag>
</HostProperties>
<ReportItem port="0" svc_name="general">
<description>55555</description>
<risk>none</risk>
</ReportItem>
</ReportHost>
<ReportHost name="1.2.3.4">
<HostProperties>
<tag name="LastUnauthenticatedResults">22222</tag>
<tag name="Credentialed_Scan">true</tag>
</HostProperties>
<ReportItem port="15672" svc_name="general">
<description>9999</description>
<risk>none</risk>
</ReportItem>
</ReportHost>
</Report>
</XMLdata>
I’d like Logstash to output this structure
{
"name": "huits.com",
"LastUnauthenticatedResults": "111111",
"Credentialed_Scan": "false",
"Port": "0",
"svc_name": "general",
"description": "55555",
"risk": "none"
}
I tried it with xml and ruby filters like the guy in Stackoverflow posted.
This is my cfg:
input {
file {
path => "/home/vagrant/data/test.xml"
start_position => "beginning"
sincedb_path => "/dev/null"
codec => multiline {
pattern => "<XMLdata>"
negate => "true"
what => "previous"
auto_flush_interval => 1
max_lines => 333333
}
}
}
filter {
xml {
store_xml => "false"
source => "message"
target => "parsed"
}
ruby {
code => '
# event.set("Preference", event.get("[parsed][ServerPreferences][0][ServerPreverences]"))
# event.set("HostProperties", event.get("[parsed][ReportHost][HostProperties][0][tag]"))
event.set("HostName", event.get("[parsed][Report][0][name]"))
event.set("Port", event.get("[parsed][Report][ReportHost][ReportItem][0][port]"))
'
}
mutate {
remove_field => ["parsed","@version","message"]
}
}
output {
stdout { }
}
This is my output
{
"@timestamp" => 2018-10-23T12:57:04.661Z,
"tags" => [
[0] "multiline"
],
"HostName" => nil,
"path" => "/home/vagrant/test.xml",
"Port" => nil,
"host" => "localhost"
}
Why I just get nil when i expect my values. Am I using ruby wrong? I hope for some help.