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!

Strengthen Your Future: A Look Back at Splunk 10 Innovations and .conf25 Highlights!

The Big One: Splunk 10 is Here!  The moment many of you have been waiting for has arrived! We are thrilled to ...

Now Offering the AI Assistant Usage Dashboard in Cloud Monitoring Console

Today, we’re excited to announce the release of a brand new AI assistant usage dashboard in Cloud Monitoring ...

Stay Connected: Your Guide to October Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...