Splunk Search

How to extract a complete multiline XML message into a field?

ankithreddy777
Contributor

I have a xml message with multiple lines. How can we extract entire data into a field?

Tags (2)
0 Karma
1 Solution

niketn
Legend

Use replace command to remove new line characters from raw event data.
Use rex to identify start and end of XML data.

For example for the following data

2016/10/20 01:01:30.123 Request Data XML : <root>
<header>
    <name>test</name>
</header>
<data>
    <sno>12345</sno>
    <details>blah blah</details>
</root>

Following SPL should do the extraction. (PS: You might have to try to remove \r also based on whether you have just new line (\n) or line feed (\r) character as well in your raw data)

| <Your Base Search>
| eval rawsingleline= replace(_raw,"\n","") 
| rex field=rawsingleline "Request Data XML : (?<xmldata>.*)" 
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

niketn
Legend

Use replace command to remove new line characters from raw event data.
Use rex to identify start and end of XML data.

For example for the following data

2016/10/20 01:01:30.123 Request Data XML : <root>
<header>
    <name>test</name>
</header>
<data>
    <sno>12345</sno>
    <details>blah blah</details>
</root>

Following SPL should do the extraction. (PS: You might have to try to remove \r also based on whether you have just new line (\n) or line feed (\r) character as well in your raw data)

| <Your Base Search>
| eval rawsingleline= replace(_raw,"\n","") 
| rex field=rawsingleline "Request Data XML : (?<xmldata>.*)" 
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...