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!

A Guide To Cloud Migration Success

As enterprises’ rapid expansion to the cloud continues, IT leaders are continuously looking for ways to focus ...

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...