Splunk Search

Return 0 when "no results found"

moizmmz
Path Finder

Hello,

In the following query, I'm hoping to return the value 0 to my dashboard panel if no results are found by the search query.

index=test "slice_played" externalUserID="$ext$" assetID!="806d682119ac46d18b9f4a5f3dc20b10"
assetID!="5c117f3141244a3a9d6899395b5c65aa" $ass$
| stats sum(duration) as "y_seconds"

Please help! I've tried using the solution asked in a similar question, but to no avail.

Tags (1)
0 Karma

woodcock
Esteemed Legend

Add this to the bottom of your search SPL string:

| appendpipe [stats count | where count=0]

You can thank @martin_mueller for this!

MuS
SplunkTrust
SplunkTrust

Hi moizmmz,

need to trick Splunk for this, because if there are no events Splunk will show No results found. So you need to add fake events and do some logic around. Try this run everywhere search:

index=_internal sourcetype!=splunkd_* baz
| append 
    [| makeresults 
    | stats count(foo) AS count 
    | eval _raw="Nothing to see here, move along!"] 
| streamstats count AS line_num 
| eval head_num=if((line_num > 1),(line_num - 1),1) 
| where (true() XOR ((count == 0) AND (head_num < line_num))) 
| fields - column, count, head_num, line_num 
| sort -_time | table *

The benefit of this search is that if there are no events it will only show one column with the message 😉

Hope this helps to get you started ...

cheers, MuS

PS: another example can be found here https://answers.splunk.com/answers/704513/how-do-i-show-0-when-no-results-are-found-in-a-rep.html

Vijeta
Influencer

@moizmmz- Try below

index=test "slice_played" externalUserID="$ext$" assetID!="806d682119ac46d18b9f4a5f3dc20b10" assetID!="5c117f3141244a3a9d6899395b5c65aa" $ass$ | append [|makeresults| eval duration=0]|stats sum(duration) as "y_seconds"
0 Karma

koshyk
Super Champion

Please try

<your search>..
| fillnull value=0 duration 
| stats sum(duration)  as "y_seconds"
0 Karma

moizmmz
Path Finder

Tried this. Doesn't Work 😞

0 Karma

koshyk
Super Champion

please provide some sample data and final output how you want to look like and we could write it for u

0 Karma

moizmmz
Path Finder

Thats the thing though. For now, it returns "No results found". So instead of seeing "No results found" in my dashboard panel, I want to see 0 !!

0 Karma

koshyk
Super Champion

strange. what i've done is, if the value is empty, put the value to 0. So it will sum up 0 and should show 0. But anyways

0 Karma

moizmmz
Path Finder

Yeah!!! that's exactly what I thought!

0 Karma

moizmmz
Path Finder

Thanks though 🙂

0 Karma
Get Updates on the Splunk Community!

.conf25 technical session recap of Observability for Gen AI: Monitoring LLM ...

If you’re unfamiliar, .conf is Splunk’s premier event where the Splunk community, customers, partners, and ...

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...

Announcing the Migration of the Splunk Add-on for Microsoft Azure Inputs to ...

Announcing the Migration of the Splunk Add-on for Microsoft Azure Inputs to Officially Supported Splunk ...