Splunk Search

Multivalued field mapping issue from an nested XML source

sundarrajan
Path Finder

Hello Splunkers!

I have an issue in grouping multivalued field after extracting fields from nested xml. The sample is as follows,

 

 <WorkstationMetrics xmlns=“xxxxxxxx”>
                    <WorkstationMetricData TypeCode="None" WorkstationID="0">
                      <SequenceNumberValue Timestamp="2022-05-1" TypeCode="First">15704</SequenceNumberValue>
                      <SequenceNumberValue Timestamp="2022-05-1" TypeCode="Last">15710</SequenceNumberValue>
                    </WorkstationMetricData>
                    <WorkstationMetricData TypeCode="Manual" WorkstationID="03">
                      <SequenceNumberValue Timestamp="2022-05-1" TypeCode="First">9395</SequenceNumberValue>
                      <SequenceNumberValue Timestamp="2022-05-1" TypeCode="Last">9463</SequenceNumberValue>
                    </WorkstationMetricData>
                    <WorkstationMetricData TypeCode="Manual" WorkstationID="05">
                      <SequenceNumberValue Timestamp="2022-05-1" TypeCode="First">62</SequenceNumberValue>
                      <SequenceNumberValue Timestamp="2022-05-1" TypeCode="Last">297</SequenceNumberValue>
                    </WorkstationMetricData>
                  </WorkstationMetrics>

 

I tried with following search query to  extract field. But the fields extracted are multivalued with varying cardinality and hence some of my mvzip commands are not working as expected. Please find below my search query for your reference.

 

index=... sourcetype=...
| spath output=workstationNumber path=WorkstationMetrics.WorkstationMetricData{@WorkstationID}
| spath output=sequenceType path=WorkstationMetrics.WorkstationMetricData.SequenceNumberValue{@TypeCode}
| spath output=sequenceNumber path=WorkstationMetrics.WorkstationMetricData.SequenceNumberValue
| eval consolidate=mvzip(sequenceType,sequenceNumber)
| mvexpand consolidate
| eval temp=split(consolidate,","), type=mvindex(temp,0), seqno=mvindex(temp,1)
| table workstationNumber type seqno

 

I expect to present this data in following format, could some one 

Sl.noWorkstationIDTypeCodeSequenceNumberValue
10First15704
20Last15710

Any help in mapping 2 multivalued fields with varying cardinality would resolve this issue. Or do we need think out of box?

Labels (3)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| spath output=workstationNumber path=WorkstationMetrics.WorkstationMetricData{@WorkstationID}
| spath output=workstationData path=WorkstationMetrics.WorkstationMetricData
| fields - _raw
| eval workstation=mvzip(workstationNumber, workstationData,"|")
| mvexpand workstation
| eval workstationNumber=mvindex(split(workstation,"|"),0)
| eval workstationData=mvindex(split(workstation,"|"),1)
| spath output=sequenceType input=workstationData path=SequenceNumberValue{@TypeCode}
| spath output=sequenceNumber input=workstationData path=SequenceNumberValue
| eval typevalue=mvzip(sequenceType, sequenceNumber,"|")
| mvexpand typevalue
| eval sequenceType=mvindex(split(typevalue,"|"),0)
| eval sequenceNumber=mvindex(split(typevalue,"|"),1)
| fields - workstation workstationData typevalue

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust
| spath output=workstationNumber path=WorkstationMetrics.WorkstationMetricData{@WorkstationID}
| spath output=workstationData path=WorkstationMetrics.WorkstationMetricData
| fields - _raw
| eval workstation=mvzip(workstationNumber, workstationData,"|")
| mvexpand workstation
| eval workstationNumber=mvindex(split(workstation,"|"),0)
| eval workstationData=mvindex(split(workstation,"|"),1)
| spath output=sequenceType input=workstationData path=SequenceNumberValue{@TypeCode}
| spath output=sequenceNumber input=workstationData path=SequenceNumberValue
| eval typevalue=mvzip(sequenceType, sequenceNumber,"|")
| mvexpand typevalue
| eval sequenceType=mvindex(split(typevalue,"|"),0)
| eval sequenceNumber=mvindex(split(typevalue,"|"),1)
| fields - workstation workstationData typevalue

sundarrajan
Path Finder

Thanks @ITWhisperer ! It even works over a large dataset with multiple lines. A clear out-of box view, of taking the portion of event as a field and piping to rex  the relevant field. 

Thanks again!

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!

Mastering Threat Intelligence in ES 8.5, Splunk AI Assistant v2, and More from Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...

Break the Build: Inside the KubeDoom Lounge at .conf26

    You step up to the machine. The pixelated corridors of a certain 1993 FPS load in front of you, EMP Pulse ...

Splunk Auto Ingestion Parallel Pipeline Scaling

Why this feature matters Many Splunk environments experience ingestion pressure long before the host is fully ...