Dashboards & Visualizations

How to keep multiple events in one XML file but pull the key-value pairs from each transaction line?

thesba
New Member

I have thousands of XML files which are being indexed in Splunk and I would like to extract values from the XML. The XML data contains product information and transactions every time a sale occurs. However, when I used xmlkv to extract the values from the XML, if there are multiple transactions, Splunk only sees the last key-value pair and disregards that multiple items were in the bucket/shopping cart. I've played with xmlsplit and reviewed the documents regarding splitting the XML file in the props.conf, however then each event would lose valuable information like the timestamp and location which isn't stored in each transactionline. An example of the data is below:

<JournalHeader>
</JournalHeader>
<SaleEvent>
  <TransactionDetailGroup>
    <TransactionLine status="normal">
      <ItemLine>
        <ItemCode>
          <POSCode>1001</POSCode>
        </ItemCode>
        <Description>Product A</Description>
      </ItemLine>
    </TransactionLine>
    <TransactionLine status="normal">
      <ItemLine>
        <ItemCode>
          <POSCode>1011</POSCode>
        </ItemCode>
        <Description>Product B</Description>
      </ItemLine>
    </TransactionLine>
    <TransactionLine status="normal">
      <ItemLine>
        <ItemCode>
          <POSCode>1021</POSCode>
        </ItemCode>
        <Description>Product C</Description>
      </ItemLine>
    </TransactionLine>
    <TransactionLine status="normal">
    ...
    </TransactionLine>
  </TransactionDetailGroup>
  <TransactionSummary>
...
  </TransactionSummary>
</SaleEvent>

If I do a table of 100 events and list the POSCode and Description, I would get 100 events with either 1001 & Product A or 1021 & Product C.

Is there a way to keep the event as a single event but drill down into each TransactionLine and pull the key-values from each?

Tags (4)
0 Karma

martin_mueller
SplunkTrust
SplunkTrust
0 Karma

jensonthottian
Contributor

So @thesba finally what is the solution you undertake?
Can you share the approach, I am also trying to parse through POS XML log files.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Doing that with XML is a bit annoying... with JSON you can apply spath partially, mvexpand, and apply the second half of spath then. Here you can do something like this:

... | spath | eval temp = mvzip(Description, Qty) | mvexpand temp | rex field=temp "(?<Description>[^,]+),(?<Qty>[^,]+)" | fields - temp

That's assuming the description doesn't contain a comma.

0 Karma

thesba
New Member

spath is helpful, thank you!. What I'm trying to do is calculate sums on the purchased quantity and product. With spath the fields have values of

Qty
1
2
1

Description
Product A
Product B
Product C

How would I associate
Product A, Qty 1
Product B, Qty 2
Product C, Qty 1

So I could do a search on all events and determine total products sold during different time periods? I've tried using mvjoin and eval?

0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...