Splunk Search

Help with Splunk search based on eventType dynamic table value

dmuley
Explorer

Hello Team, I am new to splunk and have requirement to create table based on raw data

This is how the data looks in splunk

Date  threadId=ABC123   eventType=”InMsg” data=”<rootrq><a>hi</a></rootrq>”

Date  threadId=ABC123   eventType=”thirdPartyReq” data=”<root1req><a>hi</a></root1req>”

Date  threadId=ABC123   eventType=” thirdPartyRes” data=”<root1res><a>hi</a></root1res>”

Date  threadId=ABC123   eventType=”OutMsg” data=”<rootrs><a>hi</a></rootrs>”

 

and wanted to create table like below. Please can some one help? threadId is common for all four records.

 

index=test | 

 

date threadId InMsg OutMsg thirdPartyreq thirdprtyRes
date ABC123  

<rootrq><a>hi</a></rootrq>

<rootrs><a>hi</a></rootrs>

<root1req><a>hi</a></root1req>

<root1res><a>hi</a></root1res>

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Assuming you already have extracted these fields, you could do something like this

| eval {eventType}=data
| stats values(*) as * by Date threadId

View solution in original post

dmuley
Explorer

@ITWhisperer this works thank you. also do you mind in sharing how can I remove double quotes from xml String having attribute ? 

<root1res>
          <a  test="testdata">hi</a>
</root1res>

Currently after pulling info I m just receiving upto <a test=

I already tried   | eval data1=replace(data,"\"","")  but its not working

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

It sounds like your embedded quotes haven't been escaped and/or your extraction isn't taking embedded quotes into account. How are you extracting the data field?

dmuley
Explorer

frankly not sure. dealing with splunk admin from company tooks longer than fixing by our self. Is there any way to extract key value from xml ? @ITWhisperer I really appreciate your help on this. 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

You can re-extract the fields from the _raw event field. Can you share your raw events (anonymised of course) in a code block </> so we can better see what you are dealing with?

0 Karma

dmuley
Explorer
<TestRQ><Device_Info><Device_Type>GATEWAY</Device_Type><conf Name="test1"/><conf Name="test2">NONE</conf><conf Name="test3">Y</conf></Device_Info><Request_Version>3.0</Request_Version><EMV><TAG isEncrypted="false" sierra="Y" tagDescription="KernalVersionNumber" tagLength="0F" tagName="DF79">DF790F36</TAG></EMV></TestRQ>


This is how one of the data field looks like in  our 1 event and I want extract all fields that are in data . @ITWhisperer 


2022-06-12 21:51:42.274 threadId=L4C9D6WIYK2K class="HttpConnector" mname="Adapter_Connector" callId="F2JAMR29ZCE5" eventType="REQUEST" data="<TestRQ><Device_Info><Device_Type>GATEWAY</Device_Type><conf Name="test1"/><conf Name="test2">NONE</conf><conf Name="test3">Y</conf></Device_Info><Request_Version>3.0</Request_Version><EMV><TAG isEncrypted="false" sierra="Y" tagDescription="KernalVersionNumber" tagLength="0F" tagName="DF79">DF790F36</TAG></EMV></TestRQ>"

0 Karma

dmuley
Explorer

@ITWhisperer Please can you help to get root name of xml under data node and add it in table with count of occurences per thread ?

2022-06-12 21:51:42.274 threadId=L4C9D6WIYK2K class="HttpConnector" mname="Adapter_Connector" callId="F2JAMR29ZCE5" eventType="REQUEST" data="<TestRQ><Device_Info><Device_Type>GATEWAY</Device_Type><conf Name="test1"/><conf Name="test2">NONE</conf><conf Name="test3">Y</conf></Device_Info><Request_Version>3.0</Request_Version><EMV><TAG isEncrypted="false" sierra="Y" tagDescription="KernalVersionNumber" tagLength="0F" tagName="DF79">DF790F36</TAG></EMV></TestRQ>"

 

I need to get

datacount
TestRQ 1 20
OtherRQ10

 

etc

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| rex "data=\"\<(?<data>[^\>]+)"
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

I am a little confused. Your data field looks complete, i.e. it doesn't end at the first double quote. 

0 Karma

dmuley
Explorer

index="test" eventType="*"
| eval length=len(threadId) | where length = 12
| eval {eventType}=data
| stats values(*) as * by threadId
| table threadId REQUEST RESPONSE

When I am using above query it only displays xml till  conf tag's name attribute and removes all contents after that.

<TestRQ><Device_Info><Device_Type>GATEWAY</Device_Type><conf Name=

I am expecting to recieve full xml in tables column. @ITWhisperer 

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Assuming data is the last field in your event, you can re-extract it with some rex

 

index="test" eventType="*"
| eval length=len(threadId) | where length = 12
| rex "data=\"(?<data>.*)\"$"
| eval {eventType}=data
| stats values(*) as * by threadId
| table threadId REQUEST RESPONSE

 

dmuley
Explorer

Perfect it works. thank you much @ITWhisperer 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Assuming you already have extracted these fields, you could do something like this

| eval {eventType}=data
| stats values(*) as * by Date threadId
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...