Fixed notification template (#6721)

* Fixed notification template

* Made if-clause equal to append

Like Slack and email notification

* Add custom_body attribute to discord test

* Add missing attribute
This commit is contained in:
Dirk van Donkelaar
2024-01-30 04:15:42 +01:00
committed by GitHub
parent 97db492531
commit d245ff7bb1
2 changed files with 4 additions and 3 deletions

View File

@@ -42,8 +42,8 @@ class Discord(BaseDestination):
"inline": True,
},
]
if alert.options.get("custom_body"):
fields.append({"name": "Description", "value": alert.options["custom_body"]})
if alert.custom_body:
fields.append({"name": "Description", "value": alert.custom_body})
if new_state == Alert.TRIGGERED_STATE:
if alert.options.get("custom_subject"):
text = alert.options["custom_subject"]

View File

@@ -97,13 +97,14 @@ class TestDestinationResource(BaseTestCase):
def test_discord_notify_calls_requests_post():
alert = mock.Mock(spec_set=["id", "name", "options", "render_template"])
alert = mock.Mock(spec_set=["id", "name", "options", "custom_body", "render_template"])
alert.id = 1
alert.name = "Test Alert"
alert.options = {
"custom_subject": "Test custom subject",
"custom_body": "Test custom body",
}
alert.custom_body = alert.options["custom_body"]
alert.render_template = mock.Mock(return_value={"Rendered": "template"})
query = mock.Mock()
query.id = 1