<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to extract name/value pair from XML datasource? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-name-value-pair-from-XML-datasource/m-p/264869#M79549</link>
    <description>&lt;P&gt;posted working version of props/transforms above...playing with the "null" values now...&lt;/P&gt;</description>
    <pubDate>Tue, 31 Jan 2017 01:06:51 GMT</pubDate>
    <dc:creator>mattymo</dc:creator>
    <dc:date>2017-01-31T01:06:51Z</dc:date>
    <item>
      <title>How to extract name/value pair from XML datasource?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-name-value-pair-from-XML-datasource/m-p/264863#M79543</link>
      <description>&lt;P&gt;I'm asking this question on behalf of a customer.  We are ingesting XML data and it comes in clean. Timestamp is being received correctly.  When i do a search in Splunk the raw data looks like this as a typical event.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;col name="time"&amp;gt;1/15/2017 10:43:38 AM&amp;lt;/col&amp;gt;
  &amp;lt;col name="TimeSpan"&amp;gt;N/A&amp;lt;/col&amp;gt;
  &amp;lt;col name="ThreadID"&amp;gt;0x00000516&amp;lt;/col&amp;gt;
  &amp;lt;col name="User"&amp;gt;&amp;lt;/col&amp;gt;
  &amp;lt;col name="HTTPSessionID"&amp;gt;p21hued5eusxsxc3zl5ekbyo&amp;lt;/col&amp;gt;
  &amp;lt;col name="SessionGUID"&amp;gt;p21hued5eusxsxc3zl5ekbyo&amp;lt;/col&amp;gt;
  &amp;lt;col name="SessionID"&amp;gt;0&amp;lt;/col&amp;gt;
  &amp;lt;col name="Datasource"&amp;gt;&amp;lt;/col&amp;gt;
  &amp;lt;col name="AppPoolName"&amp;gt;AppNet&amp;lt;/col&amp;gt;
  &amp;lt;col name="IpAddress"&amp;gt;10.65.6.47&amp;lt;/col&amp;gt;
  &amp;lt;col name="MachineName"&amp;gt;10.65.6.47&amp;lt;/col&amp;gt;
  &amp;lt;col name="Result"&amp;gt;0xFFFFFFFF80131500&amp;lt;/col&amp;gt;
  &amp;lt;col name="Message"&amp;gt;&amp;lt;/col&amp;gt;
  &amp;lt;col name="Module"&amp;gt;Hyland.Applications.Web.Client&amp;lt;/col&amp;gt;
  &amp;lt;col name="Class"&amp;gt;Hyland.Applications.Web.Client.ProviderPages.WorkflowSOAProvider&amp;lt;/col&amp;gt;
  &amp;lt;col name="Method"&amp;gt;ReleaseLicense&amp;lt;/col&amp;gt;
  &amp;lt;col name="SourceFile"&amp;gt;&amp;lt;/col&amp;gt;
  &amp;lt;col name="SourceLine"&amp;gt;0&amp;lt;/col&amp;gt;
  &amp;lt;col name="Severity"&amp;gt;Error&amp;lt;/col&amp;gt;
  &amp;lt;col name="ErrorId"&amp;gt;3dc1d8b4-cbab-4649-a09e-8c3434484aaa&amp;lt;/col&amp;gt;
&amp;lt;/row&amp;gt;
&amp;lt;row&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;We want Splunk to extract the name/value pairs or key-value pairs and add them as interesting fields.  We have tried REX as an option with this string but it isn't pulling it out.  (we built this string in regex101.com and it yanks things out correctly using the global option but doesn't seem to be working here).  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex max_match=0 field=_raw ".+?name="(?&amp;lt;_KEY_1&amp;gt;.+?)"\&amp;gt;(?&amp;lt;_VAL_1&amp;gt;.+?)\&amp;lt;\/col&amp;gt;"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm looking for an answer or advice on how we can get Splunk to extract these name/value pairs.&lt;/P&gt;

&lt;P&gt;Thank you.&lt;/P&gt;

&lt;P&gt;Rich&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/2399i494052EB14795955/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2017 20:33:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-name-value-pair-from-XML-datasource/m-p/264863#M79543</guid>
      <dc:creator>rvoninski_splun</dc:creator>
      <dc:date>2017-01-30T20:33:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract name/value pair from XML datasource?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-name-value-pair-from-XML-datasource/m-p/264864#M79544</link>
      <description>&lt;P&gt;Hey Rich!&lt;/P&gt;

&lt;P&gt;Your regex is fine, I think the issue is that rex didn't like the leading underscores on your field and value names...(remember, leading underscores are reserved for Splunk internal use)&lt;/P&gt;

&lt;P&gt;This worked for me:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex max_match=0 field=_raw ".+?name="(?&amp;lt;KEY_1&amp;gt;.+?)"\&amp;gt;(?&amp;lt;VAL_1&amp;gt;.+?)\&amp;lt;\/col&amp;gt;"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Once you have the rex the way you like it, you can implement this with props and transforms...&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.5.1/Knowledge/Configureadvancedextractionswithfieldtransforms"&gt;http://docs.splunk.com/Documentation/Splunk/6.5.1/Knowledge/Configureadvancedextractionswithfieldtransforms&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;I tried using KV_MODE= xml but it didn't extract what I think you will want...the whole "col name =" got in the way, and made it messy..&lt;/P&gt;

&lt;P&gt;the main thing is we need to keep the KV pair relationship to do the reporting you want...will play in the lab and see what I can come up with then update this post. &lt;/P&gt;

&lt;P&gt;UPDATE:&lt;/P&gt;

&lt;P&gt;Here is the props.conf and transforms.conf I used to parse the fields and keep the KV pairs. Big Up MuS for the optimized regex to deal with null values in the XML. Previous regex was too greedy for null fields.&lt;/P&gt;

&lt;P&gt;props.conf &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[answers494268]
BREAK_ONLY_BEFORE=&amp;lt;row&amp;gt;
CHARSET=UTF-8
KV_MODE=none
MAX_TIMESTAMP_LOOKAHEAD=125
NO_BINARY_CHECK=true
SHOULD_LINEMERGE=true
category=Custom
disabled=false
pulldown_type=true
TIME_FORMAT=%m/%d/%Y %H:%M:%S %p
TIME_PREFIX=&amp;lt;col name="time"&amp;gt;

REPORT-xml = answers494268xml
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;transforms.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[answers494268xml]
#REGEX = .+?name="(.+?)"&amp;gt;(.+?)&amp;lt;/col&amp;gt; 
#Above regex too greedy for null values
REGEX = .+?name=\"([^\"\&amp;gt;]+)\"\&amp;gt;([^\&amp;lt;]+)\&amp;lt;\/col&amp;gt;
FORMAT = $1::$2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;One thing to note in this data...there are some fields with no values....not sure if this is because you were scrubbing the data to be shared...but just keep in mind the first regex wont match if there is no value for the key, thus messing up the transform...updated rex ensures no erroneous matches&lt;/P&gt;

&lt;P&gt;ie. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;col name="User"&amp;gt;&amp;lt;/col&amp;gt;
&amp;lt;col name="Message"&amp;gt;&amp;lt;/col&amp;gt;
&amp;lt;col name="Datasource"&amp;gt;&amp;lt;/col&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;IMG src="http://i.imgur.com/bBQoWCh.png" alt="alt text" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2017 21:06:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-name-value-pair-from-XML-datasource/m-p/264864#M79544</guid>
      <dc:creator>mattymo</dc:creator>
      <dc:date>2017-01-30T21:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract name/value pair from XML datasource?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-name-value-pair-from-XML-datasource/m-p/264865#M79545</link>
      <description>&lt;P&gt;Thank you very much.  Was pulling my hair out trying to figure out.  Customer was trying to use the variables with the underscores.  We wont make that mistake again!  Again TY &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;  Props/Transforms is a good idea and we will put that into place.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2017 21:31:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-name-value-pair-from-XML-datasource/m-p/264865#M79545</guid>
      <dc:creator>rvoninski_splun</dc:creator>
      <dc:date>2017-01-30T21:31:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract name/value pair from XML datasource?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-name-value-pair-from-XML-datasource/m-p/264866#M79546</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;

&lt;P&gt;I applied the modified REGEX into an inline search. The search successfully gives us a list of the desired field names under the "KEY_" field, and the desired values in a list under the "VAL_" field. Unfortunately not as individual key-val pairs. But getting much closer &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;I will give the Props/Transforms route a try next and post the results.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:40:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-name-value-pair-from-XML-datasource/m-p/264866#M79546</guid>
      <dc:creator>ferdbiffle</dc:creator>
      <dc:date>2020-09-29T12:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract name/value pair from XML datasource?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-name-value-pair-from-XML-datasource/m-p/264867#M79547</link>
      <description>&lt;P&gt;Yeah thats what I was eluding to with keeping the KV Pair relationship for reporting....will post as soon as I have a working version&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2017 23:55:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-name-value-pair-from-XML-datasource/m-p/264867#M79547</guid>
      <dc:creator>mattymo</dc:creator>
      <dc:date>2017-01-30T23:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract name/value pair from XML datasource?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-name-value-pair-from-XML-datasource/m-p/264868#M79548</link>
      <description>&lt;P&gt;Love to see a working version of the KV Pair also.  But this is definitely on the rt track and provides access to the specific items.  Thanks for helping us out.  Rich&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 00:25:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-name-value-pair-from-XML-datasource/m-p/264868#M79548</guid>
      <dc:creator>rvoninski_splun</dc:creator>
      <dc:date>2017-01-31T00:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract name/value pair from XML datasource?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-name-value-pair-from-XML-datasource/m-p/264869#M79549</link>
      <description>&lt;P&gt;posted working version of props/transforms above...playing with the "null" values now...&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 01:06:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-name-value-pair-from-XML-datasource/m-p/264869#M79549</guid>
      <dc:creator>mattymo</dc:creator>
      <dc:date>2017-01-31T01:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract name/value pair from XML datasource?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-name-value-pair-from-XML-datasource/m-p/264870#M79550</link>
      <description>&lt;P&gt;Update:&lt;BR /&gt;
The props/transforms method allowed us to successfully extract KV pairs for all fields that are not Null. And for our use case that works just fine! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Thanks so much Matthew and Rich for your help in tackling this sticky issue!&lt;/P&gt;

&lt;P&gt;Eric&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2017 16:14:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-name-value-pair-from-XML-datasource/m-p/264870#M79550</guid>
      <dc:creator>ferdbiffle</dc:creator>
      <dc:date>2017-02-01T16:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract name/value pair from XML datasource?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-name-value-pair-from-XML-datasource/m-p/264871#M79551</link>
      <description>&lt;P&gt;Saved my day !! Thank you very much. I made a workaround if events had no value like so :&lt;/P&gt;

&lt;P&gt;Using 2 options : &lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;SEDCMD to make it , generally not preferred because people don't want to mess with their data before being sent into Splunk.&lt;/LI&gt;
&lt;LI&gt;Using another report feature in props like so : 
.+?name=\"([^\"&amp;gt;]+)\"()&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Wed, 07 Mar 2018 23:21:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-name-value-pair-from-XML-datasource/m-p/264871#M79551</guid>
      <dc:creator>kkrishnan_splun</dc:creator>
      <dc:date>2018-03-07T23:21:10Z</dc:date>
    </item>
  </channel>
</rss>

