Splunk Search

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

joxley
Path Finder

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

<search id="base">
   <query>index=_internal | stats count</query>
   <earliest>-60m</earliest>
   <latest>now</latest>
   <set token="event_count">count</set>
</search>

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

<panel>
    <title>My events ($event_count$)</title>
    <table>
0 Karma
1 Solution

jeffland
SplunkTrust
SplunkTrust

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>
<table>

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;
    panel.append(resultArray[0][0];);
});

View solution in original post

jeffland
SplunkTrust
SplunkTrust

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>
<table>

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;
    panel.append(resultArray[0][0];);
});
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

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 ...