HTML in description field of OpsGenie alerts
Asked by Micha? K?okowski:

Hi,

I have an issue with the "Description" field of the OpsGenie Alert coming from an Email integration. The email I receive looks like this in HTML:

![Screenshot 2022-04-01 at 14.37.45.png](/t5/image/serverpage/image-id/191147iFB0CAA821C9C8241/image-dimensions/308x248?v=v2 "Screenshot 2022-04-01 at 14.37.45.png")

But the description of my generated alert is in one line with no proper spaces and line breaks. Is there anything I can do to fix this?

![Screenshot 2022-04-01 at 13.14.54.png](/t5/image/serverpage/image-id/191148i925D9AE087D658B9/image-dimensions/286x246?v=v2 "Screenshot 2022-04-01 at 13.14.54.png")

I know that there is the html version in attachments, but I would like to add some extra properties and tags based on the content of the mail. The fact that it comes all in one line is causing some troubles with that and thus my question. Also what is strange, this was working properly some months ago and then all of sudden the alerts started to arrive as oneliners without a change to the email format. What could be the reason for that?


Answers:
author: Tom Russell
body: [@Micha? K?okowski](/t5/user/viewprofilepage/user-id/1537379) we deal with similar inbound emails from some of our monitoring systems. We usually don't just pass the message through to the Description field, but use multiple 'message.extract' statements, with regexes, to parse out the relevant information. (Loads and loads of message.extract, sometimes, unfortunately). This should work whether the message comes in as a single line or multiple lines, though finding field-end boundaries might be more difficult with a single-line message.

comments: author: Micha? K?okowski
body: Thank you for the reply. We implemented a similar solution now by using the extract method and adding some self defined delimiters into the mails' content.


author: igorkop
body: [@Micha? K?okowski](/t5/user/viewprofilepage/user-id/1537379) Could you please share an example of your regex. I have the same problem but can't choose the right regex to extract my data. Not sure about the structure of {{ message }} if it's pure HTML or a string with some lines.


author: Micha? K?okowski
body: Hi [@igorkop](/t5/user/viewprofilepage/user-id/5258614) ,

In our case, we put custom tags in our alert bodies like this:

*** ** * ** ***

MY_TAG_APP: app-name  
MY_TAG_ENV: preprod  
MY_TAG_MESSAGE: this is a message  
MY_TAG_END

*** ** * ** ***

Then in the OpsGenie integration, we use the following regex to extract the information and add them to the correct fields:

*** ** * ** ***

{{message.extract(/(?s)(?\<=MY_TAG_APP:).+?(?=MY_TAG)/)}}

*** ** * ** ***

So basically we extract what is between "MY_TAG_APP" and "MY_TAG" (start of next tag)   

Hope this helps!


author: Mikel Stous
body: Now that we have an Argent integration, we have less trouble with this.

We mainly have text incoming on emails, but pull variables out for automation.

{{ message.extract( /.\*MY_TAG_APP: (.\*).\*/ ) }}

{{ message.extract( /.\*MY_TAG_ENV: (.\*).\*/ ) }}

{{ message.extract( /.\*MY_TAG_MESSAGE: (.\*).\*/ ) }}


author: Dennis Sheen
body: Just a note for others. if you just want the whole body of the message (i.e. you don't want to parse out everything) and effectively just need line return chars to render properly you can just surround most text with pre tags.

e.g.

\<pre\>  
line 1  
line 2  
line 3  
\</pre\>  
will likely render good enough for most purposes.


author: Alexandr Kalika
body: we need to see user\<-\>freshdesk \<-\>opsgenie interaction and all messages are broken because they are wrapped by html in slack and they a looks terrible!!!!

TRY TO FIND TEXT within all that HTML GARBAGE around, could you only imagine.....

I found one more complaint <https://jira.atlassian.com/browse/OPSGENIE-227> and ETA??? it is so ANNOYING as CAPS and more

please help Team, we count on your understanding!

much appreciated

ps

I've found a task on this matter\& hope you will include it into the upcoming "spring" <https://jira.atlassian.com/browse/OPSGENIE-227>


Tags: html