All Apps and Add-ons

i want to refresh the dashboard on button click. is it possible?

DataOrg
Builder

i want to refresh a token to read a file and fetch the input to other search.so to refresh a token i want to reload the page or pls suggest any other way to refresh the token

1 Solution

niketn
Legend

@premranjithj, while your actual use case requires more attention depending on actual fields and values, I will answer your question in the description i.e. "Refresh the dashboard on button click"

Save the following as "refresh_button.js"

require([
    'jquery',
    'splunkjs/mvc/simplexml/ready!'
], function($){
        $('#refresh').on("click",function(){
                setTimeout("location.reload();", 0);
        });
});

Following is a dashboard with runanywhere search that will show the current time.

<dashboard script="refresh_button.js">
  <label>Splunk Answers 554639 - Refresh Dashboard on Button Click</label>
  <row>
    <panel>
      <html>
        <button id="refresh" type="button" class="btn">Refresh
        <i class="icon-rotate" style="font-size: 1em;"></i>
        </button>
      </html>
    </panel>
  </row>
  <row>
    <panel>
      <table>
        <search>
          <query>| makeresults
          </query>
        </search>
      </table>
    </panel>
  </row>
</dashboard>
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

niketn
Legend

@premranjithj, while your actual use case requires more attention depending on actual fields and values, I will answer your question in the description i.e. "Refresh the dashboard on button click"

Save the following as "refresh_button.js"

require([
    'jquery',
    'splunkjs/mvc/simplexml/ready!'
], function($){
        $('#refresh').on("click",function(){
                setTimeout("location.reload();", 0);
        });
});

Following is a dashboard with runanywhere search that will show the current time.

<dashboard script="refresh_button.js">
  <label>Splunk Answers 554639 - Refresh Dashboard on Button Click</label>
  <row>
    <panel>
      <html>
        <button id="refresh" type="button" class="btn">Refresh
        <i class="icon-rotate" style="font-size: 1em;"></i>
        </button>
      </html>
    </panel>
  </row>
  <row>
    <panel>
      <table>
        <search>
          <query>| makeresults
          </query>
        </search>
      </table>
    </panel>
  </row>
</dashboard>
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

DataOrg
Builder

Hi @niketnilay
i had saved the js file in the static file path and restarted splunk. the panel is not getting refreshed

0 Karma

niketn
Legend

Panel should refresh on button click. Have you included js file in your dashboard root node i.e. script="refresh_button.js"?

You should also try clearing browser history to see if changes reflect. If it still does not work try to check with browser Inspector tool and see if there is any error with JavaScript file code.

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

DataOrg
Builder

@niketnilay
thanks. 🙂 it worked

0 Karma

niketn
Legend

Yay Way to go!!!

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

proyleJDS
Path Finder

Hi Nik, can this be used to just refresh a single panel rather than the entire dashboard?
Regards
Peter

worshamn
Contributor

I added a simple solution on this quesiton that might do what you are asking for https://answers.splunk.com/answers/114331/how-to-refresh-the-panel-not-entire-dashboard.html?childTo...

0 Karma

nick405060
Motivator

Also would like to do ^

0 Karma

niketn
Legend

@premranjithj, you will have to provide more information on when you want to refresh and what is the token (along with value) that you want to refresh.

Following are few of interactions/events which can be used to refresh token:

1) Input Change event handler
2) Search Event Handler (Progress and Done)
3) Visualization Drilldown events
4) Even for automatic refresh, Dashboard and Panels can be refreshed on a regular interval.
5) Using JavaScript you can create your own refresh scenarios like setTimeOut() etc.

Please add details as to which is applicable in your situation.

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

DataOrg
Builder

@niketnilay

a new file will be generated and kept in the splunk path. so when ever the file generated i should invoke to read the file and store the value in token. the value in the token will be passed to another search.
i want to create a own refresh scenerios using any button click or suggest any way

0 Karma

niketn
Legend

@premranjithj, are you setting the filename as token? How frequently do you want to poll/anticipate new file/s?

If by Splunk path you mean that new file is indexed in Splunk, you can write a search in Splunk (either realtime with window as per your poll interval or with historic time but refresh as per window you need). The search can set token through progress or done search event handler for filename in your search result.

However, for us assist you with solution to your problem, you would need to provide more details about source(filename), frequency of new file, index, token and search that needs to be performed.

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

DataOrg
Builder

@niketnilay
there is no frequency for the file. it will be placed manually and no time frame for it. source will be kept as a csv file and i have a base search which will read the csv file and filter results and stores in token. concurrently below a panel will run a dbquery where i will give the inputs from the token which i used in base query

0 Karma

niketn
Legend

By frequency I meant some window like 1 min, 5 min or so. In case you do not have one, you would need to run a realtime query possibly with streamstats to monitor change in file name. This will be expensive as the search will always be running in background if you want your query to behave like a File Watcher.

The question is still open for others to provide their suggestion/answer to your issue, if there is a better way.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Get Updates on the Splunk Community!

Introduction to Splunk Observability Cloud - Building a Resilient Hybrid Cloud

Introduction to Splunk Observability Cloud - Building a Resilient Hybrid Cloud  In today’s fast-paced digital ...

Observability protocols to know about

Observability protocols define the specifications or formats for collecting, encoding, transporting, and ...

Take Your Breath Away with Splunk Risk-Based Alerting (RBA)

WATCH NOW!The Splunk Guide to Risk-Based Alerting is here to empower your SOC like never before. Join Haylee ...