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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Mile High Learning with Splunk University, Denver, Colorado

If Denver is known for its mile-high elevation, Splunk University is about to raise the bar on technical ...

IT Service Intelligence 5.0 Series: Your Guide to the June Launch

We are excited to announce the June release of Splunk IT Service Intelligence (ITSI) 5.0. This update ...

Agent Mode Engaged! Enchaining Agentic Operations with Splunk AI Assistant 2.0

    Are you ready to transform how your team handles complex data requests? We invite you to our upcoming ...