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!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...