Dashboards & Visualizations

set time range token with multiselect input

Zero
Engager

I have a mutiselect input like this

 

<input type="multiselect" token="year">
<label>Year</label>
<choice value="*">All</choice>
<delimiter> OR year=</delimiter>
<fieldForLabel>year</fieldForLabel>
<fieldForValue>year</fieldForValue>
<search>
<query>| inputlookup supported_years.csv
| dedup year
| table year</query>
</search>
<default>2023</default>
<initialValue>2023</initialValue>
</input>

 



I want to set the time range token to the result of the input selection above. If 2023 was chosen, the token value for $timeRangeEarliest$ should be 2023/01/01 and the token value for $timeRangeLastet$ should be 2023/12/31.  If 2021 and 2023 was chosen, the token value for $timeRangeEarliest$ should be 2021/01/01 and the token value for $timeRangeLastet$ should be 2023/12/31. Etc.

I want to use this two tokens for time range in search. Don't know how to do it. Please help. Many thanks.

Labels (2)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Your question is a little confusing. You have mentioned the same token twice. Also, please can you clarify what you want if three different years are chosen? Also, how are you going to use the token(s) as this makes a difference to how they might be set up?

0 Karma

Zero
Engager

Thanks for your reply.

Sorry for the two identical token name, this was a typo and I have corrected it.

If there are three or more years, I want to find the earliest year and the latest year, and use the date as tokens. (I just want to find the smallest time range that covers all those years.) And I want to use the tokens for time range of searches in dashboard. Like this:

<search>
<query>| index=abc</query>
<earliest>$timeRangeEarliest$</earliest>
<latest>$timeRangeLastet$</latest>
</search>
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this - note that is doesn't deal with All - for that (should you decide it is necessary), you would have to do something a bit more complicated

<input type="multiselect" token="year">
<label>Year</label>
<fieldForLabel>year</fieldForLabel>
<fieldForValue>year</fieldForValue>
<search>
<query>| inputlookup supported_years.csv
| dedup year
| table year</query>
</search>
<default>2023</default>
<initialValue>2023</initialValue>
      <change>
        <eval token="earliest">mvindex(mvsort($form.year$),0)</eval>
        <eval token="latest">mvindex(mvsort($form.year$),mvcount($form.year$)-1)</eval>
        <eval token="timeRangeEarliest">strptime($earliest$."0101","%Y%m%d")</eval>
        <eval token="timeRangeLatest">relative_time(strptime(($latest$)."0101","%Y%m%d"),"+1y")</eval>
      </change>
</input>
0 Karma
Get Updates on the Splunk Community!

CX Day is Coming!

Customer Experience (CX) Day is on October 7th!! We're so excited to bring back another day full of wonderful ...

Strengthen Your Future: A Look Back at Splunk 10 Innovations and .conf25 Highlights!

The Big One: Splunk 10 is Here!  The moment many of you have been waiting for has arrived! We are thrilled to ...

Now Offering the AI Assistant Usage Dashboard in Cloud Monitoring Console

Today, we’re excited to announce the release of a brand new AI assistant usage dashboard in Cloud Monitoring ...