<?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 How can I parse XML with multivalue fields? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-parse-XML-with-multivalue-fields/m-p/354687#M64876</link>
    <description>&lt;P&gt;Here's a small snippet of an xml firewall event i'm trying to parse:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;response status="success"&amp;gt;
    &amp;lt;result&amp;gt;
        &amp;lt;thermal&amp;gt;
            &amp;lt;Slot1&amp;gt;
                &amp;lt;entry&amp;gt;
                    &amp;lt;slot&amp;gt;1&amp;lt;/slot&amp;gt;
                    &amp;lt;description&amp;gt;Temperature @ Ocelot&amp;lt;/description&amp;gt;
                    &amp;lt;min&amp;gt;0.0&amp;lt;/min&amp;gt;
                    &amp;lt;max&amp;gt;60.0&amp;lt;/max&amp;gt;
                    &amp;lt;alarm&amp;gt;False&amp;lt;/alarm&amp;gt;
                    &amp;lt;DegreesC&amp;gt;36.0&amp;lt;/DegreesC&amp;gt;
                &amp;lt;/entry&amp;gt;
                &amp;lt;entry&amp;gt;
                    &amp;lt;slot&amp;gt;1&amp;lt;/slot&amp;gt;
                    &amp;lt;description&amp;gt;Temperature @ Switch&amp;lt;/description&amp;gt;
                    &amp;lt;min&amp;gt;0.0&amp;lt;/min&amp;gt;
                    &amp;lt;max&amp;gt;60.0&amp;lt;/max&amp;gt;
                    &amp;lt;alarm&amp;gt;False&amp;lt;/alarm&amp;gt;
                    &amp;lt;DegreesC&amp;gt;37.5&amp;lt;/DegreesC&amp;gt;
                &amp;lt;/entry&amp;gt;
            &amp;lt;/Slot1&amp;gt;
        &amp;lt;/thermal&amp;gt;
    &amp;lt;/result&amp;gt;
&amp;lt;/response&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Ideally i'd like to set up a process to extract the two entries above as separate fields (Temp_Ocelot=36.0, Temp_Switch=37.5).  I know I can do this with xpath at search time pretty easily as:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;..... | xpath outfield=Temp_Ocelot "//response/result/thermal/Slot1/entry[description='Temperature @ Ocelot']/DegreesC"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But i'd like to define this in the configuration files to parse out the fields automatically.  For instance, here's how I set up a props.conf to extract the XML generically so that it extracts all possible fields:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; [pa_env]
 DATETIME_CONFIG = CURRENT
 KV_MODE = xml
 LINE_BREAKER = (&amp;lt;response&amp;gt;)
 MUST_BREAK_AFTER = \&amp;lt;/response\&amp;gt;
 NO_BINARY_CHECK = 1
 SHOULD_LINEMERGE = false
 TRUNCATE = 0
 pulldown_type = 1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But this leads to a lot of multivalue records, which I then have to deal with through mvzip, mvexpand, etc.&lt;/P&gt;

&lt;P&gt;Is there a way to set up props.conf (or additionally transforms.conf) to extract the individual  tags of interest as individual fields?  At first I thought I could do something with the FIELDALIAS in props.conf to extract a specific entry description following how it's done in xpath, but that didn't work.  Here's what I tried:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; FIELDALIAS-rootfields =  response.result.thermal.Slot1.entry[description='Temperature @ Ocelot'].DegreesC as Temp_Ocelot
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is there a way to specify a specific  tag based on its properties in a FIELDALIAS?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 13:13:50 GMT</pubDate>
    <dc:creator>wcooper003</dc:creator>
    <dc:date>2020-09-29T13:13:50Z</dc:date>
    <item>
      <title>How can I parse XML with multivalue fields?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-parse-XML-with-multivalue-fields/m-p/354687#M64876</link>
      <description>&lt;P&gt;Here's a small snippet of an xml firewall event i'm trying to parse:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;response status="success"&amp;gt;
    &amp;lt;result&amp;gt;
        &amp;lt;thermal&amp;gt;
            &amp;lt;Slot1&amp;gt;
                &amp;lt;entry&amp;gt;
                    &amp;lt;slot&amp;gt;1&amp;lt;/slot&amp;gt;
                    &amp;lt;description&amp;gt;Temperature @ Ocelot&amp;lt;/description&amp;gt;
                    &amp;lt;min&amp;gt;0.0&amp;lt;/min&amp;gt;
                    &amp;lt;max&amp;gt;60.0&amp;lt;/max&amp;gt;
                    &amp;lt;alarm&amp;gt;False&amp;lt;/alarm&amp;gt;
                    &amp;lt;DegreesC&amp;gt;36.0&amp;lt;/DegreesC&amp;gt;
                &amp;lt;/entry&amp;gt;
                &amp;lt;entry&amp;gt;
                    &amp;lt;slot&amp;gt;1&amp;lt;/slot&amp;gt;
                    &amp;lt;description&amp;gt;Temperature @ Switch&amp;lt;/description&amp;gt;
                    &amp;lt;min&amp;gt;0.0&amp;lt;/min&amp;gt;
                    &amp;lt;max&amp;gt;60.0&amp;lt;/max&amp;gt;
                    &amp;lt;alarm&amp;gt;False&amp;lt;/alarm&amp;gt;
                    &amp;lt;DegreesC&amp;gt;37.5&amp;lt;/DegreesC&amp;gt;
                &amp;lt;/entry&amp;gt;
            &amp;lt;/Slot1&amp;gt;
        &amp;lt;/thermal&amp;gt;
    &amp;lt;/result&amp;gt;
&amp;lt;/response&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Ideally i'd like to set up a process to extract the two entries above as separate fields (Temp_Ocelot=36.0, Temp_Switch=37.5).  I know I can do this with xpath at search time pretty easily as:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;..... | xpath outfield=Temp_Ocelot "//response/result/thermal/Slot1/entry[description='Temperature @ Ocelot']/DegreesC"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But i'd like to define this in the configuration files to parse out the fields automatically.  For instance, here's how I set up a props.conf to extract the XML generically so that it extracts all possible fields:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; [pa_env]
 DATETIME_CONFIG = CURRENT
 KV_MODE = xml
 LINE_BREAKER = (&amp;lt;response&amp;gt;)
 MUST_BREAK_AFTER = \&amp;lt;/response\&amp;gt;
 NO_BINARY_CHECK = 1
 SHOULD_LINEMERGE = false
 TRUNCATE = 0
 pulldown_type = 1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But this leads to a lot of multivalue records, which I then have to deal with through mvzip, mvexpand, etc.&lt;/P&gt;

&lt;P&gt;Is there a way to set up props.conf (or additionally transforms.conf) to extract the individual  tags of interest as individual fields?  At first I thought I could do something with the FIELDALIAS in props.conf to extract a specific entry description following how it's done in xpath, but that didn't work.  Here's what I tried:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; FIELDALIAS-rootfields =  response.result.thermal.Slot1.entry[description='Temperature @ Ocelot'].DegreesC as Temp_Ocelot
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is there a way to specify a specific  tag based on its properties in a FIELDALIAS?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:13:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-parse-XML-with-multivalue-fields/m-p/354687#M64876</guid>
      <dc:creator>wcooper003</dc:creator>
      <dc:date>2020-09-29T13:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: How can I parse XML with multivalue fields?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-parse-XML-with-multivalue-fields/m-p/354688#M64877</link>
      <description>&lt;P&gt;Assuming values Ocelot and Switch doesn't change, you can setup search time field extractions for those fields.&lt;/P&gt;

&lt;P&gt;props.conf on search head&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[pa_env]
EXTRACT-tempOcelot = Temperature @ Ocelot.+[\r\n]+(.+[\r\n]+){3}\s+\&amp;lt;DegreesC\&amp;gt;(?&amp;lt;Temp_Ocelot&amp;gt;[^\&amp;lt;]+)
EXTRACT-tempSwitch =Temperature @ Switch.+[\r\n]+(.+[\r\n]+){3}\s+\&amp;lt;DegreesC\&amp;gt;(?&amp;lt;Temp_Switch&amp;gt;[^\&amp;lt;]+)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;See the regex working in following runanywhere sample search.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval _raw="&amp;lt;response status=\"success\"&amp;gt;
    &amp;lt;result&amp;gt;
        &amp;lt;thermal&amp;gt;
            &amp;lt;Slot1&amp;gt;
                &amp;lt;entry&amp;gt;
                    &amp;lt;slot&amp;gt;1&amp;lt;/slot&amp;gt;
                    &amp;lt;description&amp;gt;Temperature @ Ocelot&amp;lt;/description&amp;gt;
                    &amp;lt;min&amp;gt;0.0&amp;lt;/min&amp;gt;
                    &amp;lt;max&amp;gt;60.0&amp;lt;/max&amp;gt;
                    &amp;lt;alarm&amp;gt;False&amp;lt;/alarm&amp;gt;
                    &amp;lt;DegreesC&amp;gt;36.0&amp;lt;/DegreesC&amp;gt;
                &amp;lt;/entry&amp;gt;
                &amp;lt;entry&amp;gt;
                    &amp;lt;slot&amp;gt;1&amp;lt;/slot&amp;gt;
                    &amp;lt;description&amp;gt;Temperature @ Switch&amp;lt;/description&amp;gt;
                    &amp;lt;min&amp;gt;0.0&amp;lt;/min&amp;gt;
                    &amp;lt;max&amp;gt;60.0&amp;lt;/max&amp;gt;
                    &amp;lt;alarm&amp;gt;False&amp;lt;/alarm&amp;gt;
                    &amp;lt;DegreesC&amp;gt;37.5&amp;lt;/DegreesC&amp;gt;
                &amp;lt;/entry&amp;gt;
            &amp;lt;/Slot1&amp;gt;
        &amp;lt;/thermal&amp;gt;
    &amp;lt;/result&amp;gt;
&amp;lt;/response&amp;gt;" | table _raw | rex "Temperature @ Ocelot.+[\r\n]+(.+[\r\n]+){3}\s+\&amp;lt;DegreesC\&amp;gt;(?&amp;lt;Temp_Ocelot&amp;gt;[^\&amp;lt;]+)" | rex "Temperature @ Switch.+[\r\n]+(.+[\r\n]+){3}\s+\&amp;lt;DegreesC\&amp;gt;(?&amp;lt;Temp_Switch&amp;gt;[^\&amp;lt;]+)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Mar 2017 18:43:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-parse-XML-with-multivalue-fields/m-p/354688#M64877</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-03-14T18:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: How can I parse XML with multivalue fields?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-parse-XML-with-multivalue-fields/m-p/354689#M64878</link>
      <description>&lt;P&gt;Thanks for that, I think these should be stable but will have to check.  &lt;/P&gt;

&lt;P&gt;Note - the actual raw data doesn't come in formmated with return characters, so I had to modify the regex.  Do you see any issues with how I did it below?  I'm a regex noob.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 
| eval _raw="&amp;lt;response status='success'&amp;gt;&amp;lt;result&amp;gt;  &amp;lt;thermal&amp;gt;    &amp;lt;Slot1&amp;gt;      &amp;lt;entry&amp;gt;        &amp;lt;slot&amp;gt;1&amp;lt;/slot&amp;gt;        &amp;lt;description&amp;gt;Temperature @ Ocelot&amp;lt;/description&amp;gt;        &amp;lt;min&amp;gt;0.0&amp;lt;/min&amp;gt;        &amp;lt;max&amp;gt;60.0&amp;lt;/max&amp;gt;        &amp;lt;alarm&amp;gt;False&amp;lt;/alarm&amp;gt;        &amp;lt;DegreesC&amp;gt;36.0&amp;lt;/DegreesC&amp;gt;      &amp;lt;/entry&amp;gt;      &amp;lt;entry&amp;gt;        &amp;lt;slot&amp;gt;1&amp;lt;/slot&amp;gt;        &amp;lt;description&amp;gt;Temperature @ Switch&amp;lt;/description&amp;gt;        &amp;lt;min&amp;gt;0.0&amp;lt;/min&amp;gt;        &amp;lt;max&amp;gt;60.0&amp;lt;/max&amp;gt;        &amp;lt;alarm&amp;gt;False&amp;lt;/alarm&amp;gt;        &amp;lt;DegreesC&amp;gt;37.5&amp;lt;/DegreesC&amp;gt;      &amp;lt;/entry&amp;gt;      &amp;lt;entry&amp;gt;        &amp;lt;slot&amp;gt;1&amp;lt;/slot&amp;gt;        &amp;lt;description&amp;gt;Temperature @ Cavium&amp;lt;/description&amp;gt;        &amp;lt;min&amp;gt;0.0&amp;lt;/min&amp;gt;        &amp;lt;max&amp;gt;60.0&amp;lt;/max&amp;gt;        &amp;lt;alarm&amp;gt;False&amp;lt;/alarm&amp;gt;        &amp;lt;DegreesC&amp;gt;42.5&amp;lt;/DegreesC&amp;gt;      &amp;lt;/entry&amp;gt;      &amp;lt;entry&amp;gt;        &amp;lt;slot&amp;gt;1&amp;lt;/slot&amp;gt;        &amp;lt;description&amp;gt;Temperature @ Intel PHY&amp;lt;/description&amp;gt;        &amp;lt;min&amp;gt;0.0&amp;lt;/min&amp;gt;        &amp;lt;max&amp;gt;60.0&amp;lt;/max&amp;gt;        &amp;lt;alarm&amp;gt;False&amp;lt;/alarm&amp;gt;        &amp;lt;DegreesC&amp;gt;35.0&amp;lt;/DegreesC&amp;gt;      &amp;lt;/entry&amp;gt;      &amp;lt;entry&amp;gt;        &amp;lt;slot&amp;gt;1&amp;lt;/slot&amp;gt;        &amp;lt;description&amp;gt;Temperature @ Switch Core&amp;lt;/description&amp;gt;        &amp;lt;min&amp;gt;0.0&amp;lt;/min&amp;gt;        &amp;lt;max&amp;gt;85.0&amp;lt;/max&amp;gt;        &amp;lt;alarm&amp;gt;False&amp;lt;/alarm&amp;gt;        &amp;lt;DegreesC&amp;gt;62.0&amp;lt;/DegreesC&amp;gt;      &amp;lt;/entry&amp;gt;      &amp;lt;entry&amp;gt;        &amp;lt;slot&amp;gt;1&amp;lt;/slot&amp;gt;        &amp;lt;description&amp;gt;Temperature @ Cavium Core&amp;lt;/description&amp;gt;        &amp;lt;min&amp;gt;0.0&amp;lt;/min&amp;gt;        &amp;lt;max&amp;gt;85.0&amp;lt;/max&amp;gt;        &amp;lt;alarm&amp;gt;False&amp;lt;/alarm&amp;gt;        &amp;lt;DegreesC&amp;gt;47.0&amp;lt;/DegreesC&amp;gt;      &amp;lt;/entry&amp;gt;    &amp;lt;/Slot1&amp;gt;  &amp;lt;/thermal&amp;gt;  &amp;lt;/result&amp;gt; &amp;lt;/response&amp;gt;" 
| table _raw 
| rex field=_raw "Temperature @ Ocelot&amp;lt;\/description&amp;gt;\s+(&amp;lt;\w+&amp;gt;[\w\d.]+&amp;lt;\/\w+&amp;gt;\s+){3}&amp;lt;DegreesC&amp;gt;(?&amp;lt;Temp_Ocelot&amp;gt;[^\&amp;lt;]+)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Mar 2017 19:23:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-parse-XML-with-multivalue-fields/m-p/354689#M64878</guid>
      <dc:creator>wcooper003</dc:creator>
      <dc:date>2017-03-14T19:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: How can I parse XML with multivalue fields?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-parse-XML-with-multivalue-fields/m-p/354690#M64879</link>
      <description>&lt;P&gt;Looks good to me. (and more importantly works too)&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2017 19:34:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-parse-XML-with-multivalue-fields/m-p/354690#M64879</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-03-14T19:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: How can I parse XML with multivalue fields?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-can-I-parse-XML-with-multivalue-fields/m-p/354691#M64880</link>
      <description>&lt;P&gt;Thanks for your help, it's working good after I added to the props.conf. &lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2017 19:39:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-can-I-parse-XML-with-multivalue-fields/m-p/354691#M64880</guid>
      <dc:creator>wcooper003</dc:creator>
      <dc:date>2017-03-14T19:39:12Z</dc:date>
    </item>
  </channel>
</rss>

