Dashboards & Visualizations

Is there a special token syntax within a "stats count by" in a search string for drop-down menu inputs?

skender27
Contributor

Hi,

I'd like to add some input control in a dashboard I have with this search string:

sourcetype=my_sourcetype  created_date>0  | stats count by field1 $token1$ $token2$

where $token1$ has to capture right values as searching manually custom_field="value1" or custom_field="value2"...

As you see, I need to select (with a drop-down menu) only the values for fields represented by token1 and token2 and so I put the right tokens, but it doesn't work (I get a syntax error).

Is there a special syntax to use tokens within stats count by?

Thanks a lot,
Skender k.

0 Karma
1 Solution

jeffland
SplunkTrust
SplunkTrust

There is no special syntax needed, have you tried running the search by hand? I.e. if the input to your token is textA and textB, can you run a search

sourcetype=my_sourcetype created_date>0 | stats count by field1 textA textB

?

Also, you can easily show the content of your tokens for debug reasons by simply adding them to a label or header of some panel, even the input itself - e.g. put this in the label of the input:

value of input is $token1$

and you'll immediately see what token1 contains to check if there's something amiss with that.

View solution in original post

0 Karma

jeffland
SplunkTrust
SplunkTrust

There is no special syntax needed, have you tried running the search by hand? I.e. if the input to your token is textA and textB, can you run a search

sourcetype=my_sourcetype created_date>0 | stats count by field1 textA textB

?

Also, you can easily show the content of your tokens for debug reasons by simply adding them to a label or header of some panel, even the input itself - e.g. put this in the label of the input:

value of input is $token1$

and you'll immediately see what token1 contains to check if there's something amiss with that.

0 Karma

skender27
Contributor

Hi Jeffland,

Thanks a lot.
I inspected the result and I got this error (row highlighted in yellow):
stats count by field1 "value of token1" "value of token2"

and the search returned no results.

I resolved it by adding in the search string separately:
... | search field_tokenized1=$token1$ field_tokenized2=$token2$

skender27
Contributor

I forgot to add the following comment:
There are two tokens in the same search string.

0 Karma
Get Updates on the Splunk Community!

What’s New & Next in Splunk SOAR

Security teams today are dealing with more alerts, more tools, and more pressure than ever.  Join us for an ...

Observability Unlocked: Kubernetes Monitoring with Splunk Observability Cloud

 Ready to master Kubernetes and cloud monitoring like the pros? Join Splunk’s Growth Engineering team for an ...

Update Your SOAR Apps for Python 3.13: What Community Developers Need to Know

To Community SOAR App Developers - we're reaching out with an important update regarding Python 3.9's ...