Splunk Search

Need to exract amountTendered

yograjpatel
New Member

EWS Response Content:{_ "responseHeader" : {_ "success" : "true",_ "serviceName" : "payment",_ "resourceName" : "payments",_ "operationName" : "create",_ "version" : "1.25.261",_ "statementCode" : "001",_ "methodOfPaymentSequence" : "1",_ "amountTendered" : "705.14",_ "balanceBegin" : "1410.79",_ "balanceEnd" : "705.65",_ "icomsTransactionDateTime" : "20180116",_ "message" : {_ "code" : "PAYMENT_AUTH_SUCCESS",_ "message" : "Payment has been authorized."_ }_ } ]_}

Tags (1)
0 Karma
1 Solution

mayurr98
Super Champion

hey @yograjpatel

Try this run anywhere search

| makeresults 
| eval _raw="EWS Response Content:{ \"responseHeader\" : { \"success\" : \"true\", \"serviceName\" : \"payment\", \"resourceName\" : \"payments\", \"operationName\" : \"create\", \"version\" : \"1.25.261\", \"statementCode\" : \"001\", \"methodOfPaymentSequence\" : \"1\", \"amountTendered\" : \"705.14\", \"balanceBegin\" : \"1410.79\", \"balanceEnd\" : \"705.65\", \"icomsTransactionDateTime\" : \"20180116\", \"message\" : { \"code\" : \"PAYMENT_AUTH_SUCCESS\", \"message\" : \"Payment has been authorized.\" } } ]}" 
| rex field=_raw "amountTendered\"\s:\s\"(?<amountTendered>[^\"]+)" 
| convert num(amountTendered)

In your environment, you should write

index=<your_index> 
| rex field=_raw "amountTendered\"\s:\s\"(?<amountTendered>[^\"]+)" 
| convert num(amountTendered)

Let me know if this helps !

View solution in original post

0 Karma

yograjpatel
New Member

rex field=_raw "amountTendered\"\s:\s\"(?[^\"]+)" tried this and it worked

0 Karma

mayurr98
Super Champion

hey @yograjpatel

Try this run anywhere search

| makeresults 
| eval _raw="EWS Response Content:{ \"responseHeader\" : { \"success\" : \"true\", \"serviceName\" : \"payment\", \"resourceName\" : \"payments\", \"operationName\" : \"create\", \"version\" : \"1.25.261\", \"statementCode\" : \"001\", \"methodOfPaymentSequence\" : \"1\", \"amountTendered\" : \"705.14\", \"balanceBegin\" : \"1410.79\", \"balanceEnd\" : \"705.65\", \"icomsTransactionDateTime\" : \"20180116\", \"message\" : { \"code\" : \"PAYMENT_AUTH_SUCCESS\", \"message\" : \"Payment has been authorized.\" } } ]}" 
| rex field=_raw "amountTendered\"\s:\s\"(?<amountTendered>[^\"]+)" 
| convert num(amountTendered)

In your environment, you should write

index=<your_index> 
| rex field=_raw "amountTendered\"\s:\s\"(?<amountTendered>[^\"]+)" 
| convert num(amountTendered)

Let me know if this helps !

0 Karma

mayurr98
Super Champion

Hey @yograjpatel
If you deem the posted answer is correct then pls accept/upvote to resolve this question.

0 Karma

yograjpatel
New Member

I'm getting the total count but not the actual amount to sum up.

0 Karma

horsefez
SplunkTrust
SplunkTrust

Hi,

yeah. We have extracted a string value. You need to convert it into a number first.

Just do the following after the "rex" command:
| convert num(amountTendered)

https://docs.splunk.com/Documentation/SplunkCloud/6.6.3/SearchReference/Convert

0 Karma

yograjpatel
New Member

tried this too rex "\"amountTendered\"\s:\s\"(?P\d+)\""

0 Karma

horsefez
SplunkTrust
SplunkTrust

did you really do the following:

| rex field=_raw "amountTendered\"\s*\:\s*(?<amountTendered>[^\"]+)"
| convert num(amountTendered)
0 Karma

yograjpatel
New Member

not working

0 Karma

horsefez
SplunkTrust
SplunkTrust

Hi,

how about a regular expression.

| rex field=_raw "amountTendered\"\s*\:\s*(?<amountTendered>[^\"]+)"

0 Karma
Get Updates on the Splunk Community!

Observability | How to Think About Instrumentation Overhead (White Paper)

Novice observability practitioners are often overly obsessed with performance. They might approach ...

Cloud Platform | Get Resiliency in the Cloud Event (Register Now!)

IDC Report: Enterprises Gain Higher Efficiency and Resiliency With Migration to Cloud  Today many enterprises ...

The Great Resilience Quest: 10th Leaderboard Update

The tenth leaderboard update (11.23-12.05) for The Great Resilience Quest is out &gt;&gt; As our brave ...