Splunk Search

How to customize our search results using subsearches?

splunker9999
Path Finder

Hi SPlunkers,

We are looking customize our searches by using subsearches.

Search 1:

index=db source="Queue.Depth"|head 1 | stats values(Current_Depth)  -- This gives current queue depth in our MQ

Search 2:

index=db source="Queue.OldestMessageAge" |head 1|stats values(Oldest_Message_Age) as "Oldest_Message_Age_in_mins" -- This query gives us Oldest message Age in our MQ

At the moment, we have some issues with db and sometimes data is not updating. Due to this, we are getting inaccurate results.

So, we are looking for a search using the above 2 searches. Whenever current queue depth (Search 1) in our MQ is "zero", then "Oldest Message Age" (Search 2) should be "Zero".

Can some one please help us?

THanks

0 Karma

ppablo
Retired

Hi @splunker9999

Glad to see you found two working solutions through @woodcock and @somesoni2. Please be sure to resolve the post by clicking "Accept" directly below the answer that you decided to go with, and upvote them both for helping you out.

0 Karma

woodcock
Esteemed Legend

Like this:

| noop | stats count AS Oldest_Message_Age_in_mins
| eval Oldest_Message_Age_in_mins=if(([index=db source="Queue.Depth" | head 1 | return $Current_Depth] = 0), 0, [index=db source="Queue.OldestMessageAge" | head 1 | return $Oldest_Message_Age])
0 Karma

splunker9999
Path Finder

Thanks,this is working good.

0 Karma

woodcock
Esteemed Legend

Be sure to click Accept on the best answer to close the question.

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Try like this

index=db source="Queue.OldestMessageAge" |head 1|table Oldest_Message_Age | appendcols [search index=db source="Queue.Depth"|head 1 | table Current_Depth ] | eval Oldest_Message_Age=if(Current_Depth=0,0,Oldest_Message_Age)| rename Oldest_Message_Age as "Oldest_Message_Age_in_mins" 
0 Karma

splunker9999
Path Finder

Thanks , this works good.

0 Karma

woodcock
Esteemed Legend

s/eappendcols/appendcos/?

0 Karma

somesoni2
SplunkTrust
SplunkTrust

I did s/eappendcols/appendcols/ 🙂

Thanks for letting me know

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...