Dashboards & Visualizations

Button to run splunk query

Communicator

Hello

I'm pretty new to the Dashboard creating in splunk, and to xml in general.

I want to know if there is a way to create a button that will run a splunk search on a click.

I'm trying to create a button that if is clicked, it will create a lookup file by the next search :

| inputlookup "template.csv" | outputlookup "newlookup"."csv" 

I know that there is an option to use java script through onclick but the problem is that the query is in splunk syntax and i don't think java script can parse it.

Also can i create this button to appear only if there is a value in other input ?

Can anyone help?

1 Solution

SplunkTrust
SplunkTrust

Setup your dashboard like this:

<dashboard script="run_action.js">
  <label>Test Action</label>
  <row>
    <panel>
      <html>
        <button class="btn btn-primary button1">Run search!</button>
      </html>
    </panel>
  </row>
</dashboard>

the add run_action.js to <app_folder>/appserver/static of the

         require([
            "jquery",
            "splunkjs/mvc/searchmanager",
            "splunkjs/mvc/simplexml/ready!"
          ], function(
              $,
              SearchManager
          ) {
              var mysearch = new SearchManager({
                  id: "mysearch",
                  autostart: "false",
                  search: "|makeresults| outputlookup myfile" 
              });
              $(".button1").on("click", function (){
                  var ok = confirm("Are you sure?");
                  if (ok){
                      mysearch.startSearch();
                      alert('attempted restart!');
                  } //else {
                  //    alert('user did not click ok!');
                  //}
              });
         });

The dashboard needs to be in the same splunk "app" as the javascript file.

View solution in original post

SplunkTrust
SplunkTrust

Setup your dashboard like this:

<dashboard script="run_action.js">
  <label>Test Action</label>
  <row>
    <panel>
      <html>
        <button class="btn btn-primary button1">Run search!</button>
      </html>
    </panel>
  </row>
</dashboard>

the add run_action.js to <app_folder>/appserver/static of the

         require([
            "jquery",
            "splunkjs/mvc/searchmanager",
            "splunkjs/mvc/simplexml/ready!"
          ], function(
              $,
              SearchManager
          ) {
              var mysearch = new SearchManager({
                  id: "mysearch",
                  autostart: "false",
                  search: "|makeresults| outputlookup myfile" 
              });
              $(".button1").on("click", function (){
                  var ok = confirm("Are you sure?");
                  if (ok){
                      mysearch.startSearch();
                      alert('attempted restart!');
                  } //else {
                  //    alert('user did not click ok!');
                  //}
              });
         });

The dashboard needs to be in the same splunk "app" as the javascript file.

View solution in original post

Explorer

I have also the same problem.. I want search particular parameter inside the host file with the selectable date drop down

Below source code only shows one field and also not giving any output.

++++++++++

<form>
<label>ODSEE Backend SEARCH</label>
<fieldset autoRun="false" submitButton="true">
<input type="text" token="twguid">
<label>Search ID</label>
<default>put your search here</default>
<prefix>'twguid'="</prefix>
<suffix>"</suffix>
</input>
</fieldset>
<row>
<panel>
<table>
<search>
<query>
index=auth_odsee* host="*" conn=* twguid=*
| search $twguid$
| table '_date' 'twguid' 'host' </query>
<earliest>-10m</earliest>
<latest>now</latest>
</search>
</table>
</panel>
</row>
</form>

+++++++++++++++++++++

0 Karma

Communicator

I did it but for some reason it doesn't work.
Nothing happens when i press the button.

Also is there a way to send a token (of one of the other inputs in the dashboard) to that java script ?

Thank you very much!!

0 Karma

Communicator

I managed to get it work, based on your answer.
Thanks !

0 Karma
State of Splunk Careers

Access the Splunk Careers Report to see real data that shows how Splunk mastery increases your value and job satisfaction.

Find out what your skills are worth!