Dashboards & Visualizations

How to use other values if the token is undefined in a dashboard?

michaelrosello
Path Finder

I have a dashboard that can be access two way. first is from a drill down from another dashboard and other is accessing directly the dashboard link.

What I want to do is use $timestamp$ when access through drill down and when access using the link where as $timestamp$ is not defined use the date today for my datepicker.

Here is what I did so far but not working because the search will not run when $timestamp$ is not existing.

<search>
    <query> | makeresults 
            | eval fromDilldown = "$timestamp$"
            | eval defaultDateToday=strftime(relative_time(now(),"-1d@d"),"%Y-%m-%d") 
            | eval myDate = if(fromDilldown="",defaultDateToday,fromDilldown)
         </query>
    <earliest>-1s@s</earliest>
    <latest>now</latest>
    <done>
      <set token="timestampA">$value.myDate$</set>
    </done>
  </search>
0 Karma
1 Solution

niketn
Legend

@michaelrosello try the following run anywhere example which mimics scenario where timestamp is not set.
For testing the scenario where timestamp is set in your source dashboard, you can un-comment the <init> section and set specific value as per your need.
It uses <eval> tag in an independent <search> event handler to evaluate whether input token i.e. $timestamp$ in this case is null or not and then sets the token i.e. $timestampA$ in the dashboard (destination) accordingly.

<dashboard>
  <label>Use Deafult Token if Provided Token is Null</label>
  <!-- UNCOMMENT init section to default timestamp to some value.
       For testing drilldown with timestamp value set-->
  <!-- 
    <init>
      <set token="timestamp">-7d@d</set>
    </init>
  -->
  <search>
     <query> | makeresults 
     </query>
     <earliest>-1s@s</earliest>
     <latest>now</latest>
     <done>
       <eval token="timestampA">case(isnull($timestamp$),relative_time(now(),"-1d@d"),true(),$timestamp$)</eval>
     </done>
   </search>
  <!-- HTML Panel to display the tokens for testing i.e. $timestamp$ from source dashboard and $timestampA$ set in destination dashboard. -->
  <row>
    <panel>
      <html>
        <div>timestamp: $timestamp$</div>
        <div>timestampA: $timestampA$</div>
      </html>
    </panel>
  </row>
</dashboard>

Please try out and confirm!

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

0 Karma

niketn
Legend

@michaelrosello try the following run anywhere example which mimics scenario where timestamp is not set.
For testing the scenario where timestamp is set in your source dashboard, you can un-comment the <init> section and set specific value as per your need.
It uses <eval> tag in an independent <search> event handler to evaluate whether input token i.e. $timestamp$ in this case is null or not and then sets the token i.e. $timestampA$ in the dashboard (destination) accordingly.

<dashboard>
  <label>Use Deafult Token if Provided Token is Null</label>
  <!-- UNCOMMENT init section to default timestamp to some value.
       For testing drilldown with timestamp value set-->
  <!-- 
    <init>
      <set token="timestamp">-7d@d</set>
    </init>
  -->
  <search>
     <query> | makeresults 
     </query>
     <earliest>-1s@s</earliest>
     <latest>now</latest>
     <done>
       <eval token="timestampA">case(isnull($timestamp$),relative_time(now(),"-1d@d"),true(),$timestamp$)</eval>
     </done>
   </search>
  <!-- HTML Panel to display the tokens for testing i.e. $timestamp$ from source dashboard and $timestampA$ set in destination dashboard. -->
  <row>
    <panel>
      <html>
        <div>timestamp: $timestamp$</div>
        <div>timestampA: $timestampA$</div>
      </html>
    </panel>
  </row>
</dashboard>

Please try out and confirm!

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

michaelrosello
Path Finder

Thanks @niketnilay as always!

Ayn
Legend

You could probably use coalesce for this. It takes a number of values and returns the first non-null one.

... | eval fromDilldown = coalesce($timestamp$,"some other value")
0 Karma

michaelrosello
Path Finder

I've already tried this also. but same result, the search wont run because of undefined token.

0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...