Skip to content

Commit

Permalink
NAS-132712 / 25.04 / Fix alert text format for Mattermost. (#15025)
Browse files Browse the repository at this point in the history
* Mattermost does not render html code sent in
messages. This edit removes/replaces html code from
the message text and adopts the markdown formatting
used by Mattermost. As the message text is modified
only before sending, this fix will be immune to future
changes to the generic alert message formatting.

* Mattermost does not render html code.
This edit uses html2text to match approach used for the Slack, Telegram
and the other messaging services.
  • Loading branch information
nicodemusjls authored Nov 25, 2024
1 parent c03dd3a commit 7d85d22
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/middlewared/middlewared/alert/service/mattermost.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json
import requests
import html
import html2text

from middlewared.alert.base import ThreadedAlertService
from middlewared.schema import Dict, Str
Expand All @@ -26,7 +28,7 @@ def send_sync(self, alerts, gone_alerts, new_alerts):
"username": self.attributes["username"],
"channel": self.attributes["channel"],
"icon_url": self.attributes["icon_url"],
"text": self._format_alerts(alerts, gone_alerts, new_alerts),
"text": html.escape(html2text.html2text(self._format_alerts(alerts, gone_alerts, new_alerts))),
}),
timeout=INTERNET_TIMEOUT,
)
Expand Down

0 comments on commit 7d85d22

Please sign in to comment.