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!

Splunk Mobile: Your Brand-New Home Screen

Meet Your New Mobile Hub  Hello Splunk Community!  Staying connected to your data—no matter where you are—is ...

Introducing Value Insights (Beta): Understand the Business Impact your organization ...

Real progress on your strategic priorities starts with knowing the business outcomes your teams are delivering ...

Enterprise Security (ES) Essentials 8.3 is Now GA — Smarter Detections, Faster ...

As of today, Enterprise Security (ES) Essentials 8.3 is now generally available, helping SOC teams simplify ...