Splunk Search

Want to add a custom slider input

sumeetsirohi1
New Member

Hi,

How can i add a custom input which will be a slider with values ranging from 0 - 100 and pass the token value to the search query.

0 Karma

gaurav_maniar
Builder

hi,

Add html input in the dashboard and handle change values from javascript to set token.

<form script="html_input.js">
    <fieldset submitButton="true">
        <html>
            <label>Range 0-20 step=2</label>
            <input type="range" id="slider_input" value="10" min="0" max="20" step="1"/>
        </html>
    </fieldset>
    <row>
        <panel>
            <table>
                <search>
                    <query>|makeresults | eval slider_value=$slider_value$</query>
                    <earliest>-1h@h</earliest>
                    <latest>now</latest>
                </search>
            </table>
        </panel>
    </row>
<form>

html_input.js

require([
    'underscore',
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/simplexml/ready!'
 ], function(_, $, mvc){

    var tokens = mvc.Components.get('default');

    $(document).on("input change", "#slider_input", function(){
        tokens.set("slider_value", $(this).val());
    });
});

UPDATE
at line 10, element id was used without #.

0 Karma

sumeetsirohi1
New Member

I tried the above the js file but $slider_value$ is not taking the value from slider.Just says "waiting for input"

0 Karma

ND
Path Finder

Yes, its saying waiting for input.

can someone explain , how we are passing token value in table query for search for slider. after eval Slider_value= $Slider_Value$

@sumeetsirohi1 @patrickprodoehl @gaurav_maniar 

thanks.

0 Karma

gaurav_maniar
Builder

answer updated.

Splunk javascript is stored in browser cache and in Splunk javascript changes are not loaded automatically on browser side.
So once you update your script, goto https://splunk_host:8000/en-US/_bump and click Bump Version it will reload the updated javascript.

accept the answer if it helps.

0 Karma

patrickprodoehl
Explorer

amendment: the first code sections contains a closing form tag, which is missing the closing / in </form>.

Thanks for sharing the answer! Works like a charm for me!

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...