Splunk Enterprise

How to create time/date token for a dbxlookup?

genesiusj
Builder

Hello,

Need to create a date/time token for a dbxlookup. The default values for start needs to be Thursday from the previous week, and the end needs to be Monday from the current week.

Here is the dbxlookup command.

 

| dbxquery connection="SPLUNK" maxrows=0 query="select * 
from VW_SPLUNK 
where to_date (TO_CHAR (create_date_time, 'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm-dd hh24:mi:ss') 
between to_date ('$tokFromDate1$ $tok_startTime$','yyyy-mm-dd hh24:mi:ss') AND to_date ('$tokToDate1$ $tok_EndTime$','yyyy-mm-dd hh24:mi:ss') "

 

Here is the XML I have for the tokens.

 

      <input type="radio" token="tok_toggleTime">
        <label>Select date: Thu-Mon vs Mon-Thu</label>
        <choice value="ThM">Last Thursday to Monday</choice>
        <choice value="MTh">Last Monday to Thursday</choice>
        <change>
          <condition value="ThM">
            <set token="tok_startTime1">06:45:00</set>
            <set token="tok_endTime1">09:30:00</set>
            <set token="tok_textStartTime">1</set>
    <set token="tokFromDate1">@w0-3d</set>
    <set token="tokToDate1">@w0+1d</set>          
          </condition>
          <condition value="MTh">
            <set token="tok_startTime1">06:45:00</set>
            <set token="tok_endTime1">09:30:00</set>
            <set token="tok_textEndTime">1</set>
    <set token="tokFromDate1">@w0+1d</set>
    <set token="tokToDate1">@w0-3d</set>          
          </condition>
        </change>
      </input>
      <input type="text" token="tok_startTime" searchWhenChanged="true">
        <label>Start Time - Can enter new time</label>
        <default>$tok_startTime1$</default>
        <suffix/>
      </input>
      <input type="text" token="tok_endTime" searchWhenChanged="true">
        <label>End Time - Can enter new time</label>
        <default>$tok_endTime1$</default>
        <suffix/>
      </input>

 

 

Thanks and God bless,
Genesius

0 Karma
1 Solution

genesiusj
Builder

I figured out the solution.

Use eval instead of set in the <condition>. Then use relative_time and time modifiers.
See the final input XML code below (showing only one condition for brevity).

    <input type="radio" token="tok_toggleTime">
      <label>Select preset days</label>
      <choice value="ThM">Last Thursday to Monday</choice>
:
:
      <change>
        <condition value="ThM">
          <set token="tok_fromTime1">06:45:00</set>
          <set token="tok_toTime1">06:45:00</set>
          <eval token="tok_fromDate1">strftime(relative_time(now(),"@w-3d"),"%Y-%m-%d")</eval>
          <eval token="tok_toDate1">strftime(relative_time(now(),"@w+1d"),"%Y-%m-%d")</eval>
        </condition>
      </change>
    </input>

Thanks and God bless,
Genesius

View solution in original post

0 Karma

genesiusj
Builder

I figured out the solution.

Use eval instead of set in the <condition>. Then use relative_time and time modifiers.
See the final input XML code below (showing only one condition for brevity).

    <input type="radio" token="tok_toggleTime">
      <label>Select preset days</label>
      <choice value="ThM">Last Thursday to Monday</choice>
:
:
      <change>
        <condition value="ThM">
          <set token="tok_fromTime1">06:45:00</set>
          <set token="tok_toTime1">06:45:00</set>
          <eval token="tok_fromDate1">strftime(relative_time(now(),"@w-3d"),"%Y-%m-%d")</eval>
          <eval token="tok_toDate1">strftime(relative_time(now(),"@w+1d"),"%Y-%m-%d")</eval>
        </condition>
      </change>
    </input>

Thanks and God bless,
Genesius

0 Karma
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 ...