Dashboards & Visualizations

Issue in Reading xml data

karunagaraprabh
Explorer

I have similar XML data stated below and output of my query as shared in snapshot

<root>
<Jobs>
<job>
<id>Customer-1</id>
<startrange>
<sideA>
<serialNumber>1</serialNumber>
<timestramp>2021-03-23T07:14:09.906-0700</timestramp>
</sideA>
<sideB>
<serialNumber>2</serialNumber>
<timestramp>2021-03-23T07:15:29.906-0700</timestramp>
</sideB>
</startrange>
</job>
<job>
<id>Customer-2</id>
<startrange>
<sideA>
<serialNumber>3</serialNumber>
<timestramp>2021-03-23T07:14:29.906-0700</timestramp>
</sideA>
<sideB>
<serialNumber>4</serialNumber>
<timestramp>2021-03-23T07:15:39.906-0700</timestramp>
</sideB>
</startrange>
</job>
<job>
<id>Customer-3</id>
<startrange>
<sideA>
<serialNumber>5</serialNumber>
<timestramp>2021-03-23T07:14:49.906-0700</timestramp>
</sideA>
</startrange>
</job>
<job>
<id>Customer-4</id>
<startrange>
<sideA>
<serialNumber>7</serialNumber>
<timestramp>2021-03-23T07:14:29.906-0700</timestramp>
</sideA>
<sideB>
<serialNumber>8</serialNumber>
<timestramp>2021-03-23T07:15:39.906-0700</timestramp>
</sideB>
</startrange>
</job>
</Jobs>
</root>

Sample Query:

samplerquery.png

 

My output:

sampleoutput.png

for the customer-3 Side-B is un-available so Splunk is taking customer-4 -side B data and displaying for Customer-3, i need blank values for the customer B

Required output:

sampleoutput-1.png


Could any one help me how can i achieve it.

Labels (1)
0 Karma

manjunathmeti
Champion

hi @karunagaraprabh,
You can extract each job and then use spath to extract key-value pairs. See if this works for you.

| rex max_match=0 "(?<event>\<job\>[^\?]+?\<\/job\>)" 
| mvexpand event 
| spath input=event 
| rename job.startrange.* as *, *.* as *_* 
| table job_id, sideA*, sideB*

 

If this reply helps you, a like would be appreciated.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

We'll need to see the SPL that produced the output (the "Sample Query" is not a query), but I'm guessing it uses the appendcols command.  This is an example of why I discourage the use of appendcols.  Use append, instead, and follow it with stats values(*) as * by ID to re-group the results.

---
If this reply helps you, Karma would be appreciated.
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

.conf26 Registration is Live: Secure Your Early Bird Pass Now

  Lock in Your Spot: Registration Open for .conf26 in Denver Hello Splunkers, I have exciting news! Your ...

Mile High Learning with Splunk University, Denver, Colorado

If Denver is known for its mile-high elevation, Splunk University is about to raise the bar on technical ...

IT Service Intelligence 5.0 Series: Your Guide to the June Launch

We are excited to announce the June release of Splunk IT Service Intelligence (ITSI) 5.0. This update ...