Alerting

How to add HTML markups to alert email?

Sasquatchatmars
Communicator

Hi all,

I have an alert which is sending an email to all users but i need to add HTML tags to the content. For example, I need to add images and make some text bold, colored and stuff like that.
When I add the tags and send the mail it doesn't work, does someone know how I could use it? I'm obligated to add it in the mail.

Thank you,

Sasquatchatmars

Labels (2)
1 Solution

Sasquatchatmars
Communicator

For anyone who needs an answer to this, I made a new command using the suggested changes, here , in the python script "sendemail.py". 

To do this go to: 

copy the script: splunk/etc/apps/search/bin/sendemail.py 

Go to the part where you can find:

def htmlMessageTemplate():
    return template.Template('<div style="margin: 0 20px;">${msg|h}</div>')

Change that to to the following:

def htmlMessageTemplate():
    return template.Template('<div style="margin: 0 20px;">${msg}</div>')

This way you will be able to send mails with html tags in it. If you decide to change the sendemail.py file with the above to use the integrated sendemail command, be aware that the changes will be reverted when splunk is updated. 

I hope this will help someone. 

Sasquatchatmars

View solution in original post

wmw
Explorer

I appreciate this semi-recent thread on this subject. I'm curious what someone is intended to do in Splunk Cloud though. Like... why does the email alert configuration have 2 buttons at the bottom. 1 says "HTML & Plain Text", the other just says "Plain Text", and regardless of what occurs you just get plain text. Uh, wut?

Sasquatchatmars
Communicator

For anyone who needs an answer to this, I made a new command using the suggested changes, here , in the python script "sendemail.py". 

To do this go to: 

copy the script: splunk/etc/apps/search/bin/sendemail.py 

Go to the part where you can find:

def htmlMessageTemplate():
    return template.Template('<div style="margin: 0 20px;">${msg|h}</div>')

Change that to to the following:

def htmlMessageTemplate():
    return template.Template('<div style="margin: 0 20px;">${msg}</div>')

This way you will be able to send mails with html tags in it. If you decide to change the sendemail.py file with the above to use the integrated sendemail command, be aware that the changes will be reverted when splunk is updated. 

I hope this will help someone. 

Sasquatchatmars

dstoev
Explorer

Thank you for this answer, it really get the job done. However according to some research this might not be good for safety reasons, because a XSS (Cross Site Scripting) attacks, especially if the content of msg can be influenced by user input. Also like mentioned this change will be lost after an upgrade.

For now I've decided to use Sendresults app, which I'm not 100% sure if it can avoid the XSS, but at least it won't break (hopefully) during an upgrade and also it should provide more features than the built-in one.

0 Karma
Get Updates on the Splunk Community!

Optimize Cloud Monitoring

  TECH TALKS Optimize Cloud Monitoring Tuesday, August 13, 2024  |  11:00AM–12:00PM PST   Register to ...

What's New in Splunk Cloud Platform 9.2.2403?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.2.2403! Analysts can ...

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

Dive into our sizzling summer lineup for July and August Community Office Hours and Tech Talks. Scroll down to ...