Dashboards & Visualizations

How to dynamically change time period of search and results in dashboard

technie101
Explorer

My Splunk dashboard contains a timepicker along with a search results panel which displays a table output. The dashboard can be accessed by passing a input parameter 'form.queryParam.earliest' from another dashboard. Or it can directly be accessed independently without passing a parameter.

The expected behavior is:

  • If accessed with the input parameter, on loading, the results should be shown based on query param passed.
    • Now, if the value of the timepicker is changed, it should refresh the search and update the results.
  • If accessed without the input parameter, the results should be shown based on the default value of the time picker.
    • Now, if the timepicker value is changed, it should refresh the search and update the results.

With this in mind, I configured it with the following.

<form>
  <label>Test Dashboard</label>
  <fieldset submitButton="false" autoRun="true">
    <input type="time" token="selectedTimestamp" searchWhenChanged="true">
      <label>Time</label>
      <default>
        <earliest>-1d@d</earliest>
        <latest></latest>
      </default>
      <change>
        <set token="timeChanged">true</set>
      </change>
    </input>
  </fieldset>
  <!-- DUMMY SEARCH TO EVALUATE FINAL VALUE BASED ON CONDITIONS --> 
  <search>
    <query>| makeresults</query>
    <earliest>-1s@s</earliest>
    <latest>now</latest>
    <done>
      <eval token="finalEarliest">case(isnotnull($timeChanged$), $form.selectedTimestamp.earliest$, isnotnull($form.queryParam.earliest$), $form.queryParam.earliest$, true(), $form.selectedTimestamp.earliest$)</eval>
    </done>
  </search>
  <!-- ACTUAL SEARCH --> 
  <row>
    <panel>
      <title>Results Tale</title>
      <table>
        <search>
          <query>ACTUAL QUERY</query>
          <earliest>$finalEarliest$</earliest>
          <latest>now</latest>
        </search>
        <option name="link.exportResults.visible">0</option>
        <option name="link.inspectSearch.visible">0</option>
        <option name="link.openPivot.visible">0</option>
        <option name="link.openSearch.visible">0</option>
        <option name="refresh.link.visible">0</option>
        <format type="color" field="percent_of_total_count">
          <colorPalette type="list">[#65A637,#6DB7C6,#F7BC38,#F58F39,#D93F3C]</colorPalette>
          <scale type="threshold">0,30,70,100</scale>
        </format>
      </table>
    </panel>
  </row>
</form>

I am having 2 problems with this.

  1. The timeChanged value always returns true because of which the dashboard always loads with the default value of the timepicker even when the input parameter is passed in the url.
  2. The search results don't get refreshed when the timepicker value is changed in the dropdown.

Can someone please help.

Regards.

0 Karma

maciep
Champion

Seem like you may be over complicating this a bit? Why not just pass the actual timepicker values in the URL from the other dashboard? Something like this?

form.selectedTimestamp.earliest=-5d&form.selectedTimestamp.latest=now

And just set your search to use the timepicker's values?

       <earliest>$selectedTimestamp.earliest$</earliest>
       <latest>$selectedTimestamp.latest$</latest>

technie101
Explorer

Thanks maciep for the reply.

This helps. Although, one scenario is still open. The child dashboard can also be accessed directly, in which case I want to set defaults for the earliest and latest values of the timepicker. Can you please suggest?

Thanks

0 Karma

maciep
Champion

what part of that doesn't work currently? The timepicker in the child dashboard would have the default range configured, right? So if you go there manually, without populating anything in the url, then it should use those defaults.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...