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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...