Splunk Search

How to modify the search query to get the count of fields separately?

man03359
Communicator

Hi,

I am relatively new to Splunk. I am trying to achieve the output as -

Store Register Success_Count Failure_Count Total
         
         
         
         

 

I am using the below search query -

index=idx-stores-pos sourcetype=GSTR:Adyen:log Success OR Failure
| eval Store= substr(host,1,7)        ---------   extracting store and register from the host
| eval Register= substr(host,8,2)
| rex field=_raw "AdyenPaymentResponse:.+\sResult\s:\s(?<Status>.+)"
| stats count as Status_Count by Status
| eventstats sum(Status_Count) AS Total

it is giving me this result -

Status Status_Count Total
Failure 23 597
Success 574 597
     

 

Please help!

Labels (3)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

HI @man03359,

there are two issues:

you have to use Store instead Status in the BY clause:

index=idx-stores-pos sourcetype=GSTR:Adyen:log Success OR Failure
| eval Store= substr(host,1,7)
| eval Register= substr(host,8,2)
| rex field=_raw "AdyenPaymentResponse:.+\sResult\s:\s(?<Status>.+)"
| stats 
   count(eval(Status="Success")) AS Success_Count
   count(eval(Status="Failure")) AS Failure_Count 
   BY Store
| eval Total= Success_Count + Failure_Count
| table Store Register Success_Count Failure_Count Total

Then, please check the host value and if Store and Register fields are correctly extracted: you can check this running the search in Verbose mode and viewing the interesting fields in the events tab. 

Ciao.

Giuseppe

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi @man03359,

please tri something like this:

index=idx-stores-pos sourcetype=GSTR:Adyen:log Success OR Failure
| eval Store= substr(host,1,7)
| eval Register= substr(host,8,2)
| rex field=_raw "AdyenPaymentResponse:.+\sResult\s:\s(?<Status>.+)"
| stats 
   values(Register) AS Register
   count(eval(Status="Success")) AS Success_Count 
   count(eval(Status="Failure")) AS Failure_Count 
   BY Store
| eventstats sum(Status_Count) AS Total

please check the real conditions for success and failure.

Ciao.

Giuseppe

0 Karma

man03359
Communicator

I modified my query to - 

index=idx-stores-pos sourcetype=GSTR:Adyen:log Success OR Failure
| eval Store= substr(host,1,7)
| eval Register= substr(host,8,2)
| rex field=_raw "AdyenPaymentResponse:.+\sResult\s:\s(?<Status>.+)"
| stats count(eval(Status="Success")) as Success_Count,count(eval(Status="Failure")) as Failure_Count by Status
| eval Total= Success_Count + Failure_Count
| table Store Register Success_Count Failure_Count Total

which is giving me result -

StoreRegisterSuccess_CountFailure_CountTotal
  03535
  8930893
     
     

 

not sure why Store and Register values are blank

0 Karma

man03359
Communicator

I tried this query and its working 🙂 🙂

 

 index=idx-stores-pos sourcetype=GSTR:Adyen:log Success OR Failure
| eval Store= substr(host,1,7)
| eval Register= substr(host,8,2)
| rex field=_raw "AdyenPaymentResponse:.+\sResult\s:\s(?<Status>.+)"
| stats
count(eval(Status="Success")) AS Success_Count
count(eval(Status="Failure")) AS Failure_Count
BY Store Register
| eval Total= Success_Count + Failure_Count

 

THANKS A LOT ❤️

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @man03359 ,

good for you, see next time!

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated 😉

0 Karma

gcusello
SplunkTrust
SplunkTrust

HI @man03359,

there are two issues:

you have to use Store instead Status in the BY clause:

index=idx-stores-pos sourcetype=GSTR:Adyen:log Success OR Failure
| eval Store= substr(host,1,7)
| eval Register= substr(host,8,2)
| rex field=_raw "AdyenPaymentResponse:.+\sResult\s:\s(?<Status>.+)"
| stats 
   count(eval(Status="Success")) AS Success_Count
   count(eval(Status="Failure")) AS Failure_Count 
   BY Store
| eval Total= Success_Count + Failure_Count
| table Store Register Success_Count Failure_Count Total

Then, please check the host value and if Store and Register fields are correctly extracted: you can check this running the search in Verbose mode and viewing the interesting fields in the events tab. 

Ciao.

Giuseppe

man03359
Communicator

Thank you so much for the help 🙂 The above search query is giving the output like which is correct, but the register value should be in separate rows as well - 

StoreRegisterSuccess_CountFailure_Count
tkg045202 04101
tkg045302 04140
tkg045903 04 0680
tkg047701 0370
tkg047902 03 05120
tkg048603 04 05 06 07150

 

where as I am expecting like --

StoreRegisterSuccess_CountFailure_CountTotal
tkg04522   
tkg04524   
     
0 Karma
Get Updates on the Splunk Community!

Splunk App for Anomaly Detection End of Life Announcment

Q: What is happening to the Splunk App for Anomaly Detection?A: Splunk is officially announcing the ...

Aligning Observability Costs with Business Value: Practical Strategies

 Join us for an engaging Tech Talk on Aligning Observability Costs with Business Value: Practical ...

Mastering Data Pipelines: Unlocking Value with Splunk

 In today's AI-driven world, organizations must balance the challenges of managing the explosion of data with ...