diff --git a/hc/api/tests/test_notify.py b/hc/api/tests/test_notify.py index 2438c941..d65d6121 100644 --- a/hc/api/tests/test_notify.py +++ b/hc/api/tests/test_notify.py @@ -215,6 +215,26 @@ class NotifyTestCase(BaseTestCase): mock_request.assert_called_with( "get", "http://foo.com", headers=headers, timeout=5) + @patch("hc.api.transports.requests.request") + def test_webhooks_support_variables_in_headers(self, mock_request): + definition = { + "url_down": "http://foo.com", + "headers": {"X-Message": "$NAME is DOWN"} + } + + self._setup_data("webhook", json.dumps(definition)) + self.check.name = "Foo" + self.check.save() + + self.channel.notify(self.check) + + headers = { + "User-Agent": "healthchecks.io", + "X-Message": "Foo is DOWN" + } + mock_request.assert_called_with( + "get", "http://foo.com", headers=headers, timeout=5) + def test_email(self): self._setup_data("email", "alice@example.org") self.channel.notify(self.check) diff --git a/hc/api/transports.py b/hc/api/transports.py index 6d1a0559..faf06cc8 100644 --- a/hc/api/transports.py +++ b/hc/api/transports.py @@ -166,7 +166,10 @@ class Webhook(HttpTransport): assert url url = self.prepare(url, check, urlencode=True) - headers = self.channel.headers + headers = {} + for key, value in self.channel.headers.items(): + headers[key] = self.prepare(value, check) + if self.channel.post_data: payload = self.prepare(self.channel.post_data, check) return self.post(url, data=payload.encode("utf-8"), headers=headers)