Splunk Search

How do I create a token from a hidden search in SimpleXML

Path Finder

I want to have a hidden search in my simple XML dashboard

<search id="base">
   <query>index=_internal | stats count</query>
   <set token="event_count">count</set>

which populates the $event_count$ token for use in later on in the dashboard, e.g. as the title of a panel

    <title>My events ($event_count$)</title>
0 Karma

Re: How do I create a token from a hidden search in SimpleXML


Searches produce variable results (i.e. tables, single rows, events, ...). The fact that your particular search returns only one row and one column does not mean you can just use that result and put in in a token. How would you expect a search such as index=_internal to populate a token?

What you can do however is extract that search result in Javascript and edit your title accordingly. To do that, change your XML to contain the id of the panel for later reference with jquery:

<panel id="panel_id">
    <title>My events </title>

and add the following code to your .js:

var $ = require("jquery");
var search = splunkjs.mvc.Components.getInstance("base");
var myResults = search.data("results");
var panel = $("#panel_id").find("h2").first(); // If neccessary, adjust this to the right title
myResults.on("data", function() {
    resultArray = myResults.data().rows;

View solution in original post