Splunk Search

How do I Pass all Stats Values retrieved from a Query into a new Query?

Callum_f
Explorer

I am using the query below to gather all the request IDs of when an error occurs when calling an api. It provides a list of request ids (over 1000 per hour) in a table format.

index=prod_diamond sourcetype=CloudWatch_logs source=*downloadInvoice* AND *error* NOT ("lambda-warmer") | fields error.requestId | rename error.requestId as requestId | stats values by requestId

I want to then pass all the values gained from the query into a new query to find what device each requestId is coming from. The new query would look something like this.

*requestId_1* OR *requestId_2* OR ....requestId_1000* *ChannelName* *lambda*

This query will then be used to find the frequency of each device this error is occurring on.

Is there a way to pass all the values retrieved from the first query into the second query within that format?

 

Please help 🙂 

Labels (3)
0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

You could try this

<your real query which are using those regIds> 
 [ search index=prod_diamond sourcetype=CloudWatch_logs source=*downloadInvoice* AND *error* NOT ("lambda-warmer") 
| fields error.requestId 
| rename error.requestId as requestId 
| dedup requestId 
| format ]

Usually it's better to try replace those sub queries by stats etc. as sub queries and joins has serious limitations about returned event counts and time outs. Especially your *<TEXT>* search parameters are not good in any way. Those prevent splunk to use it's indexed fields and other query optimisations. Also NOT is no good way to use.

There are several .conf presentations and answers in community how to do that.

r. Ismo 

0 Karma

Callum_f
Explorer

Hi @isoutamo 

Thank you for the assistance 🙂 Your query works 🙂

However I need to edit the format that is returned from the first query. 

Currently the format is

( requestId="jjadjdfjjedd_jehdfjdjfhj" ) OR ( requestId="jgjfnfdn_jrhfjdbfd" )....

Is there a way to change the search to something less specific? Such as

(*jjadjdfjjedd_jehdfjdjfhj*) OR (*jgjfnfdn_jrhfjdbfd*) .....

As I need to find all events that include the requestId, not just when it is specific to that variable.

 

Thank you again,

 

Callum

0 Karma

isoutamo
SplunkTrust
SplunkTrust

Just replace in sub search the latest lines

| dedup requestId 
| format

with

| dedup requestId 
| rename requestId as search
| format

 

0 Karma

marysan
Communicator

index=prod_diamond sourcetype=CloudWatch_logs source=*downloadInvoice* AND *error* NOT ("lambda-warmer") | fields error.requestId | rename error.requestId as requestId | stats values by requestId
|join type=inner requestId
[search (second_query for example : "*ChannelName*" "*lambda*")]

Tags (1)
0 Karma

Callum_f
Explorer

Hi @marysan 

I have tried to implement your solution but have no luck, do I substitute the "second_query for example" text for something else?

Thanks,

Callum

0 Karma

marysan
Communicator

@Callum_f

No
this is correct form:
[search "*ChannelName*" "*lambda*")]

0 Karma
Get Updates on the Splunk Community!

Detecting Brute Force Account Takeover Fraud with Splunk

This article is the second in a three-part series exploring advanced fraud detection techniques using Splunk. ...

Buttercup Games: Further Dashboarding Techniques (Part 9)

This series of blogs assumes you have already completed the Splunk Enterprise Search Tutorial as it uses the ...

Buttercup Games: Further Dashboarding Techniques (Part 8)

This series of blogs assumes you have already completed the Splunk Enterprise Search Tutorial as it uses the ...