Dashboards & Visualizations

Progress bar/status for custom script

yogip86
Explorer

I am building application in which which click of button, custom script (python) is executed.

yogip86_0-1596098606590.png

In this image once we click Run Simulation button, it execute custom script (python). The issue is i am not able to see the progress on application/dashboard. I have to see console to see if execution is complete.

Below is html panel on dashboard.

<panel>
     <html>
      <button class="btn btn-default" id="run_search_btn">Run Simulation</button>
    </html>
</panel>

 

I want something like below : 

This is screenshot from MLTK app. Once we click on "find cluster", it show status as "Running" (2nd screenshot below). How I can style my button to show such status in my custom script run?  

yogip86_1-1596099072539.png

yogip86_2-1596099124672.png

 

 

Labels (4)
0 Karma
1 Solution

niketn
Legend

@yogip86 you can use Simple XML JS extension to change the Button attribute to disabled. Refer to one of my older answers on similar lines: https://community.splunk.com/t5/Security/Can-i-restrict-permissions-for-the-text-box-drilldown-input...

  1. On Click of the Run Simulation button, you can set a dummy Token using SplunkJS which should have dependency with the custom command search that you want to run. This will ensure that the Custom command does not execute when the dashboard loads.
  2. Disable the Run simulation button by setting the button's disabled attribute.
  3. Call startSearch() function using SplunkJS based on the Search ID to start the custom command search.
  4. Once the search completes, capture the same using done search event handler in JS.
  5. Unset the dummy token after search completes so that Simulation can be executed again.
  6. Enable the Run Simulation button using jQuery to remove disabled attribute.

PS: I have added alert messages towards beginning and end of custom command execution to capture and demo the behavior, you can get rid of them if not required.


Screen Shot 2020-07-30 at 11.08.08 PM.png

 

Screen Shot 2020-07-30 at 11.18.17 PM.png

 
Following is a run Anywhere example based on details provided.
Simple XML Dashboard Code:

 

<form script="run_simulation.js">
  <label>Command Execution on Button Click</label>
  <fieldset submitButton="false" autoRun="false"></fieldset>
  <row>
    <panel>
      <html>
        <b>Demand</b>
      </html>
    </panel>
  </row>
  <row>
    <panel>
      <html>Category 1</html>
    </panel>
    <panel>
      <input type="text" token="min_deviation" searchWhenChanged="false">
        <label>Min Deviation (%age)</label>
      </input>
      <input type="text" token="max_deviation" searchWhenChanged="false">
        <label>Min Deviation (%age)</label>
      </input>
    </panel>
  </row>
  <row>
    <panel>
      <html>Category 2</html>
    </panel>
    <panel>
      <input type="text" token="field3" searchWhenChanged="false">
        <label></label>
      </input>
      <input type="text" token="field4" searchWhenChanged="false">
        <label></label>
      </input>
    </panel>
  </row>
  <row>
    <panel>
      <html>
        <button id="run_simulation" class="btn btn-primary">Run Simulation</button>
      </html>
    </panel>
  </row>
</form>

Required JS Code run_simulation.js

require([
        'jquery',
        'splunkjs/mvc',
        'splunkjs/mvc/searchmanager',
        'splunkjs/mvc/simplexml/ready!'
], function ($,mvc,SearchManager) {
        var submittedTokenModel=mvc.Components.get("submitted");
        var sSim = new SearchManager({
                "search": "index=_internal earliest=-1h latest=now | table _time component log_level _raw",
                "id": "sSim",
                "tokenDependencies": {
                        "depends": "$runSimulation$"
                }
        }, { tokens: true, tokenNamespace: "submitted" });

        $('#run_simulation').on("click", function () {
                $('#run_simulation').attr( "disabled", "disabled" );
                alert("Starting Simulation!");
                submittedTokenModel.set("runSimulation","true");
                sSim.startSearch();
        });

        sSim.on("search:done", function () {
                alert("Simulation Complete,");
                submittedTokenModel.unset("runSimulation");
                $("#run_simulation").removeAttr( "disabled");
        });
});

Please try out and confirm!

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

View solution in original post

niketn
Legend

@yogip86 you can use Simple XML JS extension to change the Button attribute to disabled. Refer to one of my older answers on similar lines: https://community.splunk.com/t5/Security/Can-i-restrict-permissions-for-the-text-box-drilldown-input...

  1. On Click of the Run Simulation button, you can set a dummy Token using SplunkJS which should have dependency with the custom command search that you want to run. This will ensure that the Custom command does not execute when the dashboard loads.
  2. Disable the Run simulation button by setting the button's disabled attribute.
  3. Call startSearch() function using SplunkJS based on the Search ID to start the custom command search.
  4. Once the search completes, capture the same using done search event handler in JS.
  5. Unset the dummy token after search completes so that Simulation can be executed again.
  6. Enable the Run Simulation button using jQuery to remove disabled attribute.

PS: I have added alert messages towards beginning and end of custom command execution to capture and demo the behavior, you can get rid of them if not required.


Screen Shot 2020-07-30 at 11.08.08 PM.png

 

Screen Shot 2020-07-30 at 11.18.17 PM.png

 
Following is a run Anywhere example based on details provided.
Simple XML Dashboard Code:

 

<form script="run_simulation.js">
  <label>Command Execution on Button Click</label>
  <fieldset submitButton="false" autoRun="false"></fieldset>
  <row>
    <panel>
      <html>
        <b>Demand</b>
      </html>
    </panel>
  </row>
  <row>
    <panel>
      <html>Category 1</html>
    </panel>
    <panel>
      <input type="text" token="min_deviation" searchWhenChanged="false">
        <label>Min Deviation (%age)</label>
      </input>
      <input type="text" token="max_deviation" searchWhenChanged="false">
        <label>Min Deviation (%age)</label>
      </input>
    </panel>
  </row>
  <row>
    <panel>
      <html>Category 2</html>
    </panel>
    <panel>
      <input type="text" token="field3" searchWhenChanged="false">
        <label></label>
      </input>
      <input type="text" token="field4" searchWhenChanged="false">
        <label></label>
      </input>
    </panel>
  </row>
  <row>
    <panel>
      <html>
        <button id="run_simulation" class="btn btn-primary">Run Simulation</button>
      </html>
    </panel>
  </row>
</form>

Required JS Code run_simulation.js

require([
        'jquery',
        'splunkjs/mvc',
        'splunkjs/mvc/searchmanager',
        'splunkjs/mvc/simplexml/ready!'
], function ($,mvc,SearchManager) {
        var submittedTokenModel=mvc.Components.get("submitted");
        var sSim = new SearchManager({
                "search": "index=_internal earliest=-1h latest=now | table _time component log_level _raw",
                "id": "sSim",
                "tokenDependencies": {
                        "depends": "$runSimulation$"
                }
        }, { tokens: true, tokenNamespace: "submitted" });

        $('#run_simulation').on("click", function () {
                $('#run_simulation').attr( "disabled", "disabled" );
                alert("Starting Simulation!");
                submittedTokenModel.set("runSimulation","true");
                sSim.startSearch();
        });

        sSim.on("search:done", function () {
                alert("Simulation Complete,");
                submittedTokenModel.unset("runSimulation");
                $("#run_simulation").removeAttr( "disabled");
        });
});

Please try out and confirm!

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

yogip86
Explorer

Thanks @niketn . It worked for me!!  

Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...