Dashboards & Visualizations

Why search is not taking input from textarea when clicked on decode button?"| eval encoded="$input_encoded$"

ajayjuneja
Loves-to-Learn Lots

<form version="1.1" theme="dark">
<label> Backtrace</label>
<init>
<unset token="input_encoded"></unset>
<unset token="show"></unset>
</init>
<fieldset autoRun="true" submitButton="false">
<input type="dropdown" token="appBranchName" searchWhenChanged="true">
<label>Select appBranchName:</label>
<fieldForLabel>appBranchName</fieldForLabel>
<fieldForValue>appBranchName</fieldForValue>
<search>
<query>| makeresults count=1
| table appBranchName</query>
<earliest>-30d@d</earliest>
<latest>now</latest>
</search>
</input>
<input type="dropdown" token="build" searchWhenChanged="true">
<label>Select Build-Id:</label>
<fieldForLabel>build</fieldForLabel>
<fieldForValue>build</fieldForValue>
<search>
<query>
<![CDATA[
| makeresults
| table build
]]>
</query>
<earliest>-30d@d</earliest>
<latest>now</latest>
</search>
</input>
</fieldset>
<search>
<query>
| makeresults count=1
| eval encoded="$input_encoded$"
| eval branch="$appBranchName$"
| eval buildId="$build$"
| table encoded  branch buildId
</query>
<done>
<set token="backtrace_show">$result.decoded$</set>
</done>
</search>
<row>
<panel>
<title>Encoded</title>
<html>
<textarea id="input_encoded" style="width: 100%; height: 250px;"></textarea>
<input id="decode" type="button" value="Decode" style="width: 180px;height: 40px;"/>
</html>
</panel>
</row>
<row depends="$show$">
<panel>
<title>backtrace</title>
<html>
<textarea id="output" style="width: 100%; height: 300px;">$how$</textarea>
</html>
</panel>
</row>
</form>

0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

@ajayjuneja - Its because input_encoded is HTML input and not Splunk Input Filter.

* You see with HTML input there is no token binding.

* Either you use Splunk's Text Input Filter instead of HTML textarea.

* Or you need to manually bind the HTML text input value with a token with custom Javascript handler.

    // Get a reference to the textarea element
    var textarea = document.getElementById('input_encoded');
    var tokens = mvc.Components.getInstance('default');
    var submittedTokens = mvc.Components.getInstance('submitted');

    // Add an event listener to capture textarea input changes
    textarea.addEventListener('input', function() {
      // Get the current value of the textarea
      var newValue = textarea.value;

      // Update the Splunk token value
      tokens.set('input_encoded', newValue);
      submittedTokens.set('input_encoded', newValue);
    });

(Above is not the complete code, but for your reference, how you can achieve this in Splunk JS.)

 

I hope this helps!!! Kindly upvote if it does!!!

0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...