Dashboards & Visualizations

How to create a checkbox For Auto Refresh

aditsss
Builder

Hi  Everyone,

I have one requirement. 

As of now I have put Auto Refresh for my panel.

My requirement is I want to create a checkbox for Auto Refresh which when  checked will start Auto Refresh for every 5 sec and will close in 5 minutes automatically.

By Default the check box should ne unchecked.

Below is my code:

<form theme="dark">
<label> Process Dashboard Auto Refresh</label>
<fieldset submitButton="true" autoRun="true">
<input type="time" token="field1" searchWhenChanged="true">
<label>Date/Time</label>
<default>
<earliest>-15m</earliest>
<latest>now</latest>
</default>
</input>
<input type="text" token="process_tok1">
<label>Processor Id</label>
<default>*</default>
</input>
<input type="text" token="ckey" searchWhenChanged="true">
<label>Parent Chain</label>
<default></default>
<prefix>parent_chain="*</prefix>
<suffix>*"</suffix>
<initialValue></initialValue>
</input>
<input type="text" token="usr">
<label>User</label>
<default>*</default>
</input>

<input type="checkbox" token="auto">
<label>Auto Refresh</label>
</input>
</fieldset>
<row>
<panel>
<table>
<search>
<query>index=abc  sourcetype=xyz  source="user.log" $process_tok1$
| rex field=_raw "(?&lt;id&gt;[A_Za-z0-9]{8}[\-][A_Za-z0-9]{4}[\-][A_Za-z0-9]{4}[\-][A_Za-z0-9]{4}[\-][A_Za-z0-9]{12})"
| join type=outer id [inputlookup parent_chains_e1.csv]|search $ckey$|search $usr$|eval ClickHere=url|rex field=url mode=sed "s/\\/\\//\\//g s/https:/https:\\//g"
| table _time _raw host id parent_chain url</query>
<earliest>$field1.earliest$</earliest>
<latest>$field1.latest$</latest>
<sampleRatio>1</sampleRatio>
<refresh>5s</refresh>
<refreshType>delay</refreshType>
</search>
<option name="count">100</option>
<option name="dataOverlayMode">none</option>
<option name="drilldown">cell</option>
<option name="percentagesRow">false</option>
<option name="refresh.display">progressbar</option>
<option name="rowNumbers">false</option>
<option name="totalsRow">false</option>
<option name="wrap">true</option>
<drilldown>
<condition field="url">
<link target="_blank">$row.url|n$</link>
</condition>
</drilldown>
</table>
</panel>
</row>
</form>

Can someone guide me how to achieve

Labels (4)
0 Karma
1 Solution

manjunathmeti
Champion

I have simplified it, check if this works.

<form>
  <label>AutoRefresh Dashboard</label>
  <fieldset submitButton="false" autoRun="false">
    <input type="checkbox" token="autorefresh" searchWhenChanged="false">
      <label></label>
      <choice value="autorefresh">Enable Auto Refresh</choice>
      <change>
        <condition value="autorefresh">
          <set token="refresh_after">5s</set>
          <eval token="start_time">now()</eval>
        </condition>
      </change>
    </input>
  </fieldset>
  <row>
    <panel>
      <title>Panel - with auto refresh</title>
      <table>
        <search>
          <query>index=_internal | stats count by sourcetype, source</query>
          <earliest>-15m</earliest>
          <latest>now</latest>
          <refresh>$refresh_after$</refresh>
          <refreshType>delay</refreshType>
          <done>
            <condition match="relative_time(now(), &quot;-5m&quot;) &gt;= $start_time$">
              <set token="refresh_after">none</set>
              <unset token="form.autorefresh"></unset>
            </condition>
          </done>
        </search>
        <option name="refresh.display">preview</option>
      </table>
    </panel>
  </row>
</form>

 

If this reply helps you, an upvote/like would be appreciated.

View solution in original post

0 Karma

manjunathmeti
Champion

hi @aditsss,

Check if the below code works for you. The below dashboard contains two rows with the same panel with the same queries. One row depends on token $autorefresh_row$ and its panels refresh every 5 seconds and another row depends on token $static_row$ and there is no refresh.

Token autorefresh_row is set when the checkbox is checked and token static_row is set when the checkbox is unchecked.

And it is a difficult task to implement to close the dashboard after 5 minutes when autorefresh is checked. So instead of closing the dashboard, you can unset autorefresh_row  token and set static_row token after 5 mins. This will display the panel with no autorefresh.

<form>
  <label>Test</label>
  <fieldset submitButton="false" autoRun="false">
    <input type="checkbox" token="autorefresh" searchWhenChanged="false">
      <label></label>
      <choice value="autorefresh">Enable Auto Refresh</choice>
      <change>
        <condition value="autorefresh">
          <set token="autorefresh_row">1</set>
          <unset token="static_row"></unset>
          <eval token="start_time">now()</eval>
        </condition>
        <condition>
          <unset token="autorefresh_row"></unset>
          <set token="static_row">1</set>
        </condition>
      </change>
    </input>
  </fieldset>
  <row depends="$autorefresh_row$">
    <panel>
      <title>Panel - with auto refresh</title>
      <table>
        <search>
          <query>index=_internal | stats count by sourcetype, source</query>
          <earliest>-15m</earliest>
          <latest>now</latest>
          <refresh>5s</refresh>
          <refreshType>delay</refreshType>
          <done>
            <condition match="relative_time(now(), &quot;-5m&quot;) &gt;= $start_time$">
              <set token="static_row">1</set>
              <unset token="autorefresh_row"></unset>
              <unset token="form.autorefresh"></unset>
            </condition>
          </done>
        </search>
        <option name="refresh.display">preview</option>
      </table>
    </panel>
  </row>
  <row depends="$static_row$">
    <panel>
      <title>Panel - without auto refresh</title>
      <table>
        <search>
          <query>index=_internal | stats count by sourcetype, source</query>
          <earliest>-15m</earliest>
          <latest>now</latest>
        </search>
      </table>
    </panel>
  </row>
</form>

 

If this reply helps you, an upvote/like would be appreciated. 

aditsss
Builder

@manjunathmeti 

I have only single query .

How can I set and unset two tokens.

Can you guide me which token I need to set and unset as per requirement.

As I can't set two row depends token as I have only one raw 

Thanks in advance

0 Karma

manjunathmeti
Champion

Yes, you have only one row. You make a copy of it so there will be two rows but only one will be displayed in the dashboard. The row is visible based on its token is set or not.

Did you try the above XML and see if it is working?

0 Karma

aditsss
Builder

@manjunathmeti 

This is an Excellent approach that is working fine.

The only issue I am facing is after 5 minutes when its stopping its going back to panel without Auto refresh.

Cant it be stopped at that moment after 5 minutes when  and checkbox can be unchecked.

Because after 5 minutes its going back to panel with out Auto Refresh which consists of old logs

Thanks in advance. 

0 Karma

manjunathmeti
Champion

I have simplified it, check if this works.

<form>
  <label>AutoRefresh Dashboard</label>
  <fieldset submitButton="false" autoRun="false">
    <input type="checkbox" token="autorefresh" searchWhenChanged="false">
      <label></label>
      <choice value="autorefresh">Enable Auto Refresh</choice>
      <change>
        <condition value="autorefresh">
          <set token="refresh_after">5s</set>
          <eval token="start_time">now()</eval>
        </condition>
      </change>
    </input>
  </fieldset>
  <row>
    <panel>
      <title>Panel - with auto refresh</title>
      <table>
        <search>
          <query>index=_internal | stats count by sourcetype, source</query>
          <earliest>-15m</earliest>
          <latest>now</latest>
          <refresh>$refresh_after$</refresh>
          <refreshType>delay</refreshType>
          <done>
            <condition match="relative_time(now(), &quot;-5m&quot;) &gt;= $start_time$">
              <set token="refresh_after">none</set>
              <unset token="form.autorefresh"></unset>
            </condition>
          </done>
        </search>
        <option name="refresh.display">preview</option>
      </table>
    </panel>
  </row>
</form>

 

If this reply helps you, an upvote/like would be appreciated.

View solution in original post

0 Karma

aditsss
Builder

@manjunathmeti 

 

Thank you so much

0 Karma
Take the 2021 Splunk Career Survey

Help us learn about how Splunk has
impacted your career by taking the 2021 Splunk Career Survey.

Earn $50 in Amazon cash!