Dashboards & Visualizations

including javascript in data > ui> alert > test.html , but javascript is not working

avikramengg
Explorer

under this folder structure

├───appserver
|----------------└───static
|--------------------------└───test.js
├───default
│----------└───data
│---------------------└───ui
│-------------------------------└───alerts
--------------------------------------------└───test.html

I am trying to include a JavaScript code or JavaScript file under "test.html" but it is not happening

<form class="form-horizontal form-complex" script="test.js">
    <input type="text" name="action.test.param.confgid" id="create_tests_confgid"   />
</form>

following code is written in test.js

$(document).ready(function(){
  alert("testing the alert ");
  });

Note : I am able to see the form on web interface of splunk but the java script code is not executing .

Can anyone help me to include the JavaScript code to specified code structure?

Regards,
Amit Vikram

jeffland
SplunkTrust
SplunkTrust

It is not possible to use javascript in custom alert html code. The docs themselves don't say this explicitly, but you can refer to the comments below the appropriate documentation where SK8 asked the exact question.
Feel free to leave feedback on that page requesting clarification (using the "Was this topic useful?"-section at the bottom), the docs team is super awesome and will appreciate your input.

avikramengg
Explorer

Hi Jeffland,

Thank you for taking time to reply to my query.

I had read the article earlier which you suggested but it was ambiguous , under topic :Security Consideration they says:

"Except for a dynamic dropdown control, only static HTML markup should be used in the interface. Do not include scripts or other constructs that could put your system at risk."

by this line it sounds like it is possible but recommended not to use it.

As suggested by you , I have left my feedback on the article.

Regards,
Amit Vikram

0 Karma

quzen
Explorer

Hi!

I also understand the Security Consideration, but have no other option than include a javascript code.
I want to enable HTML email formatting inside a text box with WYSIWYG javascript interface like CKEditor.

Who can advise a solution?

0 Karma

JTG
Loves-to-Learn

@quzen , I have a similar use case. Would like to allow users to format an HTML email message body, and need to minify and escape the HTML before passing as a parameter. Did you find a solution?

0 Karma

quzen
Explorer

Hello @JTG !

 

I tried different ways to include javascript into Alert HTML, even asked that question to Documentation team.

But in the end I haven't found a way to do that. Apparently it's just not allowed by the application.

 

What I finally did is created my own Send Formatted Email addon which allows:

  • select from a list of predefined email templates (base templates with general styling + header and footer)
  • format message body using HTML tags (ex. <h1>, CSS inline styling, etc.)
  • include inline table with results (the same way as in the default Splunk's Send email addon)
  • include inline dashboard screenshot (supports dynamic link with parameters from results)

Configured alert trigger looks like this:

send_formatted_email.png

And an email example looks like this:

email_example.png

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...