Splunk Search

Need help to combine queries

mahesh27
Communicator

Query1:

index=app-index source=application.logs "Initial message received with below details"
|rex field= _raw "RampData :\s(?<RampdataSet>\w+)"
|stats count as IntialMessage by RampdataSet


output:

RampdataSet IntialMessage
WAC 10
WAX 30
WAM 22
STC 33
STX 66
OTP 20

 

Query2:

index=app-index source=application.logs "Initial message Successfull"
|rex field= _raw "RampData :\s(?<RampdataSet>\w+)"
|stats count as SuccessfullMessage by RampdataSet


output:

RampdataSet SuccessfullMessage
WAC 0
WAX 15
WAM 20
STC 12
STX 30
OTP 10
TTC 5
TAN 7
TXN 10
WOU 12

 

Query3:

index=app-index source=application.logs "Initial message Error"
|rex field= _raw "RampData :\s(?<RampdataSet>\w+)"
|stats count as ErrorMessage by RampdataSet


output:

RampdataSet ErrorMessage
WAC 0
WAX 15
WAM 20
STC 12

 

We want to combine three queries and want to get the output as shown below, how to do that???

RampdataSet IntialMessage SuccessfullMessage ErrorMessage Total
WAC 10 0 0 10
WAX 30 15 15 60
WAM 22 20 20 62
STC 33 12 12 57
STX 66 30 0 96
OTP 20 10 0 30
TTC 0 5 0 5
TAN 0 7 0 7
TXN 0 10 0 10
WOU 0 12 0 12

 

Labels (1)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

What do you want to extract?

See this example which extracts parts  of the text 

| makeresults
| fields - _time
| eval msgs=split("Initial message received with below details,Letter published correctley to ATM subject,Letter published correctley to DMM subject,Letter rejected due to: DOUBLE_KEY,Letter rejected due to: UNVALID_LOG,Letter rejected due to: UNVALID_DATA_APP",",")
| mvexpand msgs
| rex field=msgs "(Initial message |Letter published correctley to |Letter rejected due to: )(?<reason>.*)"

you'll need to decide what you want and what you intend to use it for.

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

Try

index=app-index source=application.logs ("Initial message received with below details" OR "Initial message Successfull" OR "Initial message Error")
| rex field= _raw "RampData :\s(?<RampdataSet>\w+)"
| rex "Initial message (?<type>\w+)"
| chart count over RampdataSet by type
| addtotals

This extracts a 'type' field which will be received, Error or Successfull and then the chart command will do what you want - it will give you fields names as above, but you can rename those to what you want.

0 Karma

mahesh27
Communicator

Hi @bowesmana , Thank you for sharing the query, it worked.
But i have another query, how do we write rex to extract  these strings:

index=app-index source=application.logs ("Initial message received with below details" OR "Letter published correctley to ATM subject" OR Letter published correctley to DMM subject" OR "Letter rejected due to: DOUBLE_KEY" OR "Letter rejected due to: UNVALID_LOG" OR "Letter rejected due to: UNVALID_DATA_APP")

 

0 Karma

bowesmana
SplunkTrust
SplunkTrust

What do you want to extract?

See this example which extracts parts  of the text 

| makeresults
| fields - _time
| eval msgs=split("Initial message received with below details,Letter published correctley to ATM subject,Letter published correctley to DMM subject,Letter rejected due to: DOUBLE_KEY,Letter rejected due to: UNVALID_LOG,Letter rejected due to: UNVALID_DATA_APP",",")
| mvexpand msgs
| rex field=msgs "(Initial message |Letter published correctley to |Letter rejected due to: )(?<reason>.*)"

you'll need to decide what you want and what you intend to use it for.

mahesh27
Communicator

Hi @bowesmana, As you suggested We tried below query, but i am getting same values for each msgs strings. Can you please let me know is my query correct??

index=app-index source=application.logs 
|rex field= _raw "RampData :\s(?<RampdataSet>\w+)"
| eval msgs=split("Initial message received with below details,Letter published correctley to ATM subject,Letter published correctley to DMM subject,Letter rejected due to: DOUBLE_KEY,Letter rejected due to: UNVALID_LOG,Letter rejected due to: UNVALID_DATA_APP",",")
| mvexpand msgs
| rex field=msgs "(Initial message |Letter published correctley to |Letter rejected due to: )(?<reason>.*)"
|chart count over RampdataSet by reason
|addtotals

OUTPUT:

Railsbelow detailsATM subjectDMM subjectDOUBLE_KEYUNVALID_LOGUNVALID_DATA_APPTotal
WAC0000000
WAX15151515151590
WAM202020202020120
STC12121212121272
STX303030303030180
OTP10101010101060
TTC55555530
TAN77777742
TXN10101010101060
WOU12121212121272

 

0 Karma

bowesmana
SplunkTrust
SplunkTrust

My code was an example using your data - you are using that fixed set of strings in your code - you should do the rex against your raw data not the fixed msgs field - remove the eval msgs.... and the mvexpand, that was just example code.

Your rex statement should either use _raw or if you have those messages extracted to a separate field, use that field.

mahesh27
Communicator

@bowesmana , thank you for ur inputs.

We created queries according to our data working now.

Thank you once again.

0 Karma

mahesh27
Communicator

@bowesmana , Thank you so much, it worked😊

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

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