Splunk Search

How to pass 0 to variable if no search result is found?

ahmadsaadwarrai
Explorer

I have scenario where I want variable (Loss) to be 0 if no result found of below search:

| dbxquery query="SELECT * FROM \"Cherwell\".\"dbo\".\"v_ServicelineToLogicalDevice_Splunk\"" connection="Cherwell-DB" 
| rename LNCID as RecID 
| join type=inner RecID 
    [| dbxquery query="SELECT * FROM \"Cherwell\".\"dbo\".\"v_LogicalCircuits_Splunk\"" connection="Cherwell-DB"] 
| rename RecID as LNCID 
| fields - Bandwidth Status 
| rename LogicalObjectSiteAID as Rec_ID 
| join type=inner Rec_ID 
    [ inputlookup objects] 
| rename Device_Name as Hostname 
| join type=inner Hostname 
    [ search index=index_zabbixnotify 
    | dedup IP Alarm 
    | search Status="PROBLEM"] 
| rename ServiceLineID as RecID 
| join type=left RecID 
    [| dbxquery query="SELECT * FROM \"Cherwell\".\"dbo\".\"v_ServiceLines_Splunk\"" connection="Cherwell-DB"] 
| search Status=Active 
| stats sum(Bandwidth) as Loss

I want Loss to be filled with 0 if nothing found. Search is working fine if it find some events.

0 Karma
1 Solution

denzelchung
Path Finder

You can add the following line at the end of your search:

| appendpipe [stats count | where count=0 | eval Loss=0 | fields - count]

View solution in original post

0 Karma

denzelchung
Path Finder

You can add the following line at the end of your search:

| appendpipe [stats count | where count=0 | eval Loss=0 | fields - count]
0 Karma
Get Updates on the Splunk Community!

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...