Dashboards & Visualizations

How to use a custom token filter within Simple XML

Lowell
Super Champion

I'm trying to implement a custom token filter based on the Transform and validate tokens docs, but can't quite seem to make it work.

Targeting Splunk 6.3-6.5. Testing on 6.5.0.

Broken Example

Javascript $SPLUNK_HOME/etc/apps/search/appserver/static/lowell_filter.js:

require([
    "splunkjs/mvc",
    ], function(mvc) {

mvc.setFilter("testFilter", function(inputValue) {
    return "It worked " + inputValue;
});
}

Example Dashboard:

<dashboard script="lowell_filter.js">
  <label>token_test</label>
  <row>
    <panel>
      <table>
        <search>
          <query>index=_internal sourcetype=splunkd | cluster showcount=true | table _time, log_level, component, message, cluster_count | sort - cluster_count</query>
          <earliest>-1h@m</earliest>
          <latest>@m</latest>
        </search>
        <option name="drilldown">row</option>
        <drilldown>
          <set token="message">$row.message$</set>
        </drilldown>
      </table>
    </panel>
  </row>
  <row>
    <html depends="$message$">
      <h1>Message</h1>
      Filter s:  $message|s$  &lt;br/&gt;
      Filter s+u:  $message|s|u$  &lt;br/&gt;
      Filter testFilter: $message|testFilter$ &lt;br/&gt;
    </html>
  </row>
</dashboard>

When I click on a row, the s and s+u filters show what I would expected, but the last line shows the literal value, still surrounded in dollar marks.

 Filter testFilter: $message|testFilter$

Update:

I've determined that if I run the following code interactively from my browser's Javascript console, that the filter is called as expected.

window.splunkjs.mvc.setFilter("testFilter", function(inputValue) {
    return "It worked " + inputValue;
});

If I click on the table, triggering the drilldown action, then it adds the "It worked" prefix onto the token value. I think this validates that I'm calling the right function, and the desired functionality is present, just that I have something wrong in how/where I'm calling setFilter().

1 Solution

rjthibod
Champion

Add the missing the closing parenthesis to your JS file

 require([
     "splunkjs/mvc",
     ], function(mvc) {
 mvc.setFilter("testFilter", function(inputValue) {
     return "It worked " + inputValue;
   });
 });

View solution in original post

rjthibod
Champion

Add the missing the closing parenthesis to your JS file

 require([
     "splunkjs/mvc",
     ], function(mvc) {
 mvc.setFilter("testFilter", function(inputValue) {
     return "It worked " + inputValue;
   });
 });
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 ...