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!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

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