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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...