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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Unlocking Unified Insights: New Gigamon Federated Search App for Splunk

In today’s data-heavy environment, organizations are caught in a data distribution dilemma. As data volumes ...

GA: New Data Management App in Splunk Platform

Streamlining Data Management: Introducing a unified experience in Splunk Managing data at scale shouldn’t feel ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...