Splunk Search

How to change stats on optional field?

rangarbus
Path Finder

Hello Folks,

I have the below query on one of my dashboard panel.

Here I pass the IN_BUSINESSDATE field value from dashboard (form input) with default as % and prefix & sufix value as %. So incase user does not provide, the query gets IN_BUSINESSDATE as %%% (its ok)

index=dockerlogs 
| search app_name = ABCD AND logEvent="Delivered"
| spath input=businessKey path=businessDate output=businessDate
| spath input=businessKey output=sourceSystem path=sourceSystem
| eval businessDate=substr(businessDate,1,10)
| where like(businessDate, "$IN_BUSINESSDATE$")
| stats count by businessDate, sourceSystem

Now I would like to change the stats on the query as below if IN_BUSINESSDATE is not provided (meaning value is %%%)

| stats count by sourceSystem

How can I achieve this ?

Thank you!

Labels (2)
Tags (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Add a change handler to the input and set another token business_date_entered to "businessDate" if there is an entry and "" otherwise, then use this new token on the stats command

| stats count by $business_date_entered$ sourceSystem

 

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

Add a change handler to the input and set another token business_date_entered to "businessDate" if there is an entry and "" otherwise, then use this new token on the stats command

| stats count by $business_date_entered$ sourceSystem

 

Get Updates on the Splunk Community!

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

 Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

🔐 Trust at Every Hop: How mTLS in Splunk Enterprise 10.0 Makes Security Simpler

From Idea to Implementation: Why Splunk Built mTLS into Splunk Enterprise 10.0  mTLS wasn’t just a checkbox ...