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!

.conf24 | Day 0

Hello Splunk Community! My name is Chris, and I'm based in Canberra, Australia's capital, and I travelled for ...

Enhance Security Visibility with Splunk Enterprise Security 7.1 through Threat ...

 (view in My Videos)Struggling with alert fatigue, lack of context, and prioritization around security ...

Troubleshooting the OpenTelemetry Collector

  In this tech talk, you’ll learn how to troubleshoot the OpenTelemetry collector - from checking the ...