Splunk Search

How to extract multivalue fields in multiple events from xml data?

chironc
Engager

Hello,

I'm trying to extract information from a XML files. The file repeats the following pattern for each IP address.

<IP value="10.10.10.10" name="toto">
  <INFOS>
      <INFO number="6" severity="1">
            <TITLE>test1]></TITLE>
             <LAST_UPDATE><![CDATA[1999-01-01T08:00:00Z]]></LAST_UPDATE>
      </INFO>
      <INFO number="456" severity="12">
            <TITLE>test2</TITLE>
             <LAST_UPDATE><![CDATA[2010-01-01T08:00:00Z]]></LAST_UPDATE>
      </INFO>
      <INFO number="1234" severity="1">
            <TITLE>test3</TITLE>
             <LAST_UPDATE><![CDATA[2012-01-01T08:00:00Z]]></LAST_UPDATE>
      </INFO>
 </INFOS>
</IP>

In the props.conf files, I've added the parameter: KV_mode = xml. So I have the following multivalue fields:

IP.INFOS.INFO{@number}
6
456
1234

IP.INFOS.INFO{@severity}
1
12
1

IP.INFOS.INFO.LAST_UPDATE
1999-01-01T08:00:00Z
2010-01-01T08:00:00Z
2012-01-01T08:00:00Z

I would like to separate the fields in order to have those events:

10.10.10.10  |  6      | 1      | 1999-01-01T08:00:00Z
10.10.10.10  |  456    | 12     | 2010-01-01T08:00:00Z
10.10.10.10  |  1234   | 1      | 2012-01-01T08:00:00Z

I tried to use mvexpand, mvzip, spath, etc.. But I did not succeed.

Is there a way to do it ?

Best regards,

Corentin

1 Solution

somesoni2
Revered Legend

Give this a try

Your base search | eval temp=mvzip(mvzip(mvzip('IP.INFOS.INFO.LAST_UPDATE','IP.INFOS.INFO.TITLE',"#"), 'IP.INFOS.INFO{@number}',"#"), 'IP.INFOS.INFO{@severity}',"#") | table IP{@name},IP{@value},temp | mvexpand temp | rex field=temp "(?<LAST_UPDATE>.*)#(?<TITLE>.*)#(?<Number>.*)#(?<Severity>.*)" | rename IP{@name} as IP_Name IP{@value} as IP_Address | fields - IP.* temp

View solution in original post

somesoni2
Revered Legend

Give this a try

Your base search | eval temp=mvzip(mvzip(mvzip('IP.INFOS.INFO.LAST_UPDATE','IP.INFOS.INFO.TITLE',"#"), 'IP.INFOS.INFO{@number}',"#"), 'IP.INFOS.INFO{@severity}',"#") | table IP{@name},IP{@value},temp | mvexpand temp | rex field=temp "(?<LAST_UPDATE>.*)#(?<TITLE>.*)#(?<Number>.*)#(?<Severity>.*)" | rename IP{@name} as IP_Name IP{@value} as IP_Address | fields - IP.* temp

chironc
Engager

Hello,

Thank you. It works !

Best regards,

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...