Splunk Search

Passing token to earliest time

smanojkumar
Contributor

Hi There!

   I'm having the case, If present day is "Monday" and if user selects the option "Exclude weekend", the time range picker should looks for the data on friday
If user selects the option "Include weekend", the time range picker should be yesterday

<input type="radio" token="weekends" searchWhenChanged="true">
<label>Weekends</label>
<choice value="exclude">Exclude Weekends</choice>
<choice value="include">Include Weekends</choice>
<default>exclude</default>
<initialValue>exclude</initialValue>
</input>


thanks!

0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

If you are just looking to define 'yesterday' as either Sunday or Friday on a Monday then this example shows you how to make a search time range that will be either the previous day, or if Monday and exclude weekends, is is Friday

<form version="1.1" theme="light">
  <label>ExcludeWeekends</label>
  <fieldset>
    <input type="radio" token="weekends" searchWhenChanged="true">
      <label>Weekends</label>
      <choice value="exclude">Exclude Weekends</choice>
      <choice value="include">Include Weekends</choice>
      <default>exclude</default>
      <initialValue>exclude</initialValue>
    </input>
  </fieldset>
  <search>
    <done>
      <set token="search_start">$result.search_start$</set>
      <set token="search_end">$result.search_end$</set>
    </done>
    <query>| makeresults
| fields - _time
| eval now=now()
| eval prev_day=if(strftime(now, "%a")="Mon" AND "$weekends$"="exclude", -3, -1)
| eval search_start=relative_time(now, prev_day."d@d")
| eval search_end=search_start + 86400</query>
  </search>
  <row>
    <panel>
      <table>
        <search>
          <query>index=_audit
| bin _time span=1d
| stats count by _time</query>
          <earliest>$search_start$</earliest>
          <latest>$search_end$</latest>
        </search>
        <option name="refresh.display">progressbar</option>
      </table>
    </panel>
  </row>
</form>

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

If you are just looking to define 'yesterday' as either Sunday or Friday on a Monday then this example shows you how to make a search time range that will be either the previous day, or if Monday and exclude weekends, is is Friday

<form version="1.1" theme="light">
  <label>ExcludeWeekends</label>
  <fieldset>
    <input type="radio" token="weekends" searchWhenChanged="true">
      <label>Weekends</label>
      <choice value="exclude">Exclude Weekends</choice>
      <choice value="include">Include Weekends</choice>
      <default>exclude</default>
      <initialValue>exclude</initialValue>
    </input>
  </fieldset>
  <search>
    <done>
      <set token="search_start">$result.search_start$</set>
      <set token="search_end">$result.search_end$</set>
    </done>
    <query>| makeresults
| fields - _time
| eval now=now()
| eval prev_day=if(strftime(now, "%a")="Mon" AND "$weekends$"="exclude", -3, -1)
| eval search_start=relative_time(now, prev_day."d@d")
| eval search_end=search_start + 86400</query>
  </search>
  <row>
    <panel>
      <table>
        <search>
          <query>index=_audit
| bin _time span=1d
| stats count by _time</query>
          <earliest>$search_start$</earliest>
          <latest>$search_end$</latest>
        </search>
        <option name="refresh.display">progressbar</option>
      </table>
    </panel>
  </row>
</form>
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...