Dashboards & Visualizations

Reading a text token with javascript.

mike-48735
Engager

I am starting to add some JS elements to dashboards.  I can't quite get the text input box to work like I think it should be. (nor is the time range working, but I hadn't worked on that really). I feel like I am close but I have tried a few options and it isn't loading.

 

<form script="js/views/js_testing.js">
  <label>JS Testing</label>
  <fieldset submitButton="true">
    <input type="text" token="ip_field1">
      <label>Test Value</label>
    </input>
    <input type="time" token="field1">
      <label>Time Picker</label>
      <default>
        <earliest>-24h@h</earliest>
        <latest>now</latest>
      </default>
    </input>
  </fieldset>
  <row>
    <panel>
      <title>Test data - $ip_field1$</title>
      <html>
        <div id="mytable1"/>
      </html>
    </panel>
  </row>
</form>

 

 

Javascript&colon;

 

// LIBRARIES

require([
    "splunkjs/mvc",
    "splunkjs/mvc/searchmanager",
    "splunkjs/mvc/singleview",
    "splunkjs/mvc/tableview",
    "splunkjs/mvc/simplexml/ready!"
], function(
    mvc,
    SearchManager,
    SingleView,
    TableView
) {

 // SEARCH MANAGERS
    var search1 = new SearchManager({
        id: "connections",
        search: "index=zeek_conn id.orig_h=$ip_field1$ OR id.resp_h=$ip_field1$ | table _time id.orig_h id.resp_h",
        preview: true,
        cache: true,
        earliest_time: "-30d",
        latest_time: "now"
    }, {tokens: true});

// TOKENS
    var tokens = mvc.Components.get("default");
    $(document).on("click", "#submit", function(e){
        var tok1 = tokens.get("ip_field1");

        if (tok1 == undefined || tok1 == ""){
            tokens.set("ip_field1", "*");
        }
    });
    
    var mytoken = tokens.get("ip_field1");

// INSERT_TABLE_VIEW
    var table1 = new TableView({
        id: "my-table1",
        managerid: "connections",
        el: $("#mytable1")
    }).render();

});

 

 

Thanks!

Labels (1)
0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...