Splunk Search

How do you use the rex command to obtain values to be put into a table?

JyotiP
Path Finder

I have a query :

host=*perf* bf19f0c3-2f10-4db2-b33f-efb946b0ee24 {"StatusCode":204* | table Message
Out put  of the above query is as follows :
{"StatusCode":204,"ReasonPhrase":"No Content","Method":"GET","PathAndQuery":"/api/ibor/v2/positionValuations?businessDate=2017-09-04\u0026closeoutSchemeId=1\u0026expand=*\u0026logicalTimeId=150\u0026positionStateId=40","MessageType":"Response"}

I want to take out the following value :
1. businessDate
2. positionStateId
3. closeoutSchemeId

and put them in a table in which the basic value should be businessDate=2017-09-04, positionStateId=40,closeoutSchemeId=1

0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi JyotiP,
use this regex with rex command

| rex ".*businessDate(?<businessDate>[^\\]*)\\u0026closeoutSchemeId\=(?<closeoutSchemeId>[^\\]*)\\u0026.*positionStateId\=(?<positionStateId>[^\"]*)"

or extracting fields.

Test it at https://regex101.com/r/USbhRP/1

Bye.
Giuseppe

View solution in original post

0 Karma

amy25
New Member

Hi
I know it's too late to answer but I would like to contribute the following idea:

|rex ".businessDate=(?\d.-\d*)\.closeoutSchemeId=(?\d\u\d).positionStateId=(?\d)"

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi JyotiP,
use this regex with rex command

| rex ".*businessDate(?<businessDate>[^\\]*)\\u0026closeoutSchemeId\=(?<closeoutSchemeId>[^\\]*)\\u0026.*positionStateId\=(?<positionStateId>[^\"]*)"

or extracting fields.

Test it at https://regex101.com/r/USbhRP/1

Bye.
Giuseppe

0 Karma

JyotiP
Path Finder

{"StatusCode":204,"ReasonPhrase":"No Content","Method":"GET","PathAndQuery":"/api/ibor/v2/positionValuations?businessDate=2017-09-04\u0026closeoutSchemeId=1\u0026expand=*\u0026logicalTimeId=150\u0026positionStateId=40","MessageType":"Response"}

The highlighted value (\u0026expand=*\u0026logicalTimeId=150\u0026) are unique every time I hit it will change, and for different query the values are different but the
businessDate=2017-09-04
closeoutSchemeId=1
positionStateId=40
will be as it is. So I want to capture only above 3 value irrespective of the values followed by the above values.

0 Karma

JyotiP
Path Finder

Hi Giuseppe,

It is not working because "\" is not supporting.

0 Karma

JyotiP
Path Finder

@cusello,
tried but given the a pattern error please refer the following
https://regex101.com/r/USbhRP/1 and please select javascript.

0 Karma

gcusello
SplunkTrust
SplunkTrust

I usually use regexes in Splunk never in Javascripts, anyway try something like

.*businessDate\=([^\\]*)\\u0026closeoutSchemeId\=([^\\]*)\\u0026.*positionStateId\=([^\"]*)

where:

  • Group1 is businessDate
  • Group2 is closeoutSchemeId
  • Group3 is positionStateId

test it in https://regex101.com/r/USbhRP/3
Bye.
Giuseppe

0 Karma

JyotiP
Path Finder

Output table should contain the values as follows :

businessDate=2017-09-04,
positionStateId=40,
closeoutSchemeId=1

0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...