Hi,
I have a splunk search which give back the testcase_id's.
I need a button which call a rest API request.
Rest API input should the testcase_id from splunk search. and separate the testcase_id with coma.
Hi,@kamlesh_vaghela
Independent from table. Somwehere in Dashboard
Can you please try this Sample Dashboard?
XML:
<dashboard script="html_button.js">
<label>HTML Button</label>
<search base="main_search">
<query>| stats delim="," values(testcase_id) as testcase_id | mvcombine testcase_id</query>
<done>
<set token="tkn_testcase_ids">$result.testcase_id$</set>
</done>
</search>
<row>
<panel>
<table>
<search id="main_search">
<query>| makeresults count=10 | eval testcase_id =1 | accum testcase_id</query>
<earliest>-24h@h</earliest>
<latest>now</latest>
<sampleRatio>1</sampleRatio>
</search>
<option name="count">100</option>
<option name="dataOverlayMode">none</option>
<option name="drilldown">none</option>
<option name="percentagesRow">false</option>
<option name="rowNumbers">false</option>
<option name="totalsRow">false</option>
<option name="wrap">true</option>
</table>
</panel>
</row>
<row>
<panel>
<html>
Testcase Ids: $tkn_testcase_ids$
<br />
<br />
<br />
<button type="button" id="callRest" value="Call Rest Api">Call Rest Api</button>
</html>
</panel>
</row>
</dashboard>
html_button.js
require([
'underscore',
'splunkjs/mvc',
'splunkjs/mvc/simplexml/ready!'
], function(_, mvc) {
var tokens = mvc.Components.get("default");
$(document).ready(function() {
var t = setTimeout(function() {
$("#callRest").click(function() {
var uri = "API URI";
$.ajax({
type: "POST",
url: uri,
data: {
testcase_ids: tokens.get("tkn_testcase_ids")
},
beforeSend: function(x) {
if (x && x.overrideMimeType) {
x.overrideMimeType("application/j-son;charset=UTF-8");
}
},
success: function(rsp) {
}
});
});
clearTimeout(t);
}, 3000);
})
});
Thanks
KV
▄︻̷̿┻̿═━一
If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.
I'm attempting to call a REST API with a button click and display its JSON response on the dashboard. I'm using the following code as a reference. However, I'm not getting any results, and I can see this message in the developer tools console tab:
"Error handling response: TypeError: Cannot read properties of undefined (reading 'mmrConsoleLoggingEnabled')"