Splunk Search

xml field extraction

carmackd
Communicator

could someone please explain what stanza configuration i should include in the props.conf file to extract the size attribute from <email> into the field emailSize.

<stream TimeScanned="1271078550">
<command class="MAIL FROM" data="&lt;me@gmail.com&gt; SIZE=42446" />
<email size="42521">
    <header Name="attachmentname" Value="driver-install.pdf" />
    </email>

thanks,

Tags (1)
1 Solution

Lowell
Super Champion

This should do the trick:

EXTRACT-emailsize = <email\s+size=["'](?<emailSize>\d)["'][> ]

Of course, if size isn't always the first attribute in the email element, then the regex can start to get ugly.

If you are asking how you can automatically extract key value pairs using a combination of the element name and attribute name (like emailSize, headerName, headerValue, commandClass, commandData, ... and so on), then it's not something splunk does out of the box...

You may also find the xmlkv command helpful. The the search source=*.xml | xmlkv

View solution in original post

sideview
SplunkTrust
SplunkTrust

If the regexes just get too crazy one other option is to leave props.conf alone and just use the xpath command at search time:

<your search> | xpath "//email/@size" outfield=emailSize | search emailSize > 40000
0 Karma

Lowell
Super Champion

This should do the trick:

EXTRACT-emailsize = <email\s+size=["'](?<emailSize>\d)["'][> ]

Of course, if size isn't always the first attribute in the email element, then the regex can start to get ugly.

If you are asking how you can automatically extract key value pairs using a combination of the element name and attribute name (like emailSize, headerName, headerValue, commandClass, commandData, ... and so on), then it's not something splunk does out of the box...

You may also find the xmlkv command helpful. The the search source=*.xml | xmlkv

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 ...