0
0
Fork 0
mirror of https://github.com/healthchecks/healthchecks.git synced 2025-04-11 07:41:19 +00:00

Add support for $SLUG placeholder in webhook payloads

Fixes: 
This commit is contained in:
Pēteris Caune 2024-08-16 13:24:12 +03:00
parent cda744d0c1
commit d3ae4e7fac
No known key found for this signature in database
GPG key ID: E28D7679E9A9EDE2
4 changed files with 9 additions and 2 deletions

View file

@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
- Update timezone dropdowns to show frequently used timezones at the top
- Update the "Set Password" page to reject very weak passwords
- Implement search by slug in the checks list (#1048)
- Add support for $SLUG placeholder in webhook payloads (#1049)
### Bug Fixes
- Fix Check.ping() to lock the check before updating (#1023)

View file

@ -133,19 +133,20 @@ class NotifyWebhookTestCase(BaseTestCase):
def test_webhooks_support_variables(self, mock_get: Mock) -> None:
definition = {
"method_down": "GET",
"url_down": "http://host/$CODE/$STATUS/$TAG1/$TAG2/?name=$NAME",
"url_down": "http://host/$CODE/$SLUG/$STATUS/$TAG1/$TAG2/?name=$NAME",
"body_down": "",
"headers_down": {},
}
self._setup_data(json.dumps(definition))
self.check.name = "Hello World"
self.check.slug = "hello-world"
self.check.tags = "foo bar"
self.check.save()
self.channel.notify(self.flip)
url = "http://host/%s/down/foo/bar/?name=Hello%%20World" % self.check.code
url = f"http://host/{self.check.code}/hello-world/down/foo/bar/?name=Hello%20World"
args, kwargs = mock_get.call_args
self.assertEqual(args[0], "get")

View file

@ -345,6 +345,7 @@ class Webhook(HttpTransport):
"$NOW": safe(flip.created.replace(microsecond=0).isoformat()),
"$NAME_JSON": safe(json.dumps(check.name)),
"$NAME": safe(check.name),
"$SLUG": check.slug,
"$TAGS": safe(check.tags),
"$JSON": safe(json.dumps(check.to_dict())),
}

View file

@ -211,6 +211,10 @@
<pre>{"name": $NAME_JSON}</pre>
</td>
</tr>
<tr>
<th><code>$SLUG</code></th>
<td>Check's slug.</td>
</tr>
<tr>
<th><code>$NOW</code></th>
<td>