forked from GithubBackups/healthchecks
OpsGenie integration returns more detailed error messages
This commit is contained in:
parent
50118d90c5
commit
8c7f3977e2
@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
- API reference in Markdown
|
- API reference in Markdown
|
||||||
- Use Selectize.js for entering tags (#324)
|
- Use Selectize.js for entering tags (#324)
|
||||||
- Zulip integration (#202)
|
- Zulip integration (#202)
|
||||||
|
- OpsGenie integration returns more detailed error messages
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
- The "render_docs" command checks if markdown and pygments is installed (#329)
|
- The "render_docs" command checks if markdown and pygments is installed (#329)
|
||||||
|
@ -502,6 +502,16 @@ class NotifyTestCase(BaseTestCase):
|
|||||||
args, kwargs = mock_post.call_args
|
args, kwargs = mock_post.call_args
|
||||||
self.assertIn("api.eu.opsgenie.com", args[1])
|
self.assertIn("api.eu.opsgenie.com", args[1])
|
||||||
|
|
||||||
|
@patch("hc.api.transports.requests.request")
|
||||||
|
def test_opsgenie_returns_error(self, mock_post):
|
||||||
|
self._setup_data("opsgenie", "123")
|
||||||
|
mock_post.return_value.status_code = 403
|
||||||
|
mock_post.return_value.json.return_value = {"message": "Nice try"}
|
||||||
|
|
||||||
|
self.channel.notify(self.check)
|
||||||
|
n = Notification.objects.first()
|
||||||
|
self.assertEqual(n.error, 'Received status code 403 with a message: "Nice try"')
|
||||||
|
|
||||||
@patch("hc.api.transports.requests.request")
|
@patch("hc.api.transports.requests.request")
|
||||||
def test_pushover(self, mock_post):
|
def test_pushover(self, mock_post):
|
||||||
self._setup_data("po", "123|0")
|
self._setup_data("po", "123|0")
|
||||||
|
@ -141,8 +141,8 @@ class Shell(Transport):
|
|||||||
|
|
||||||
class HttpTransport(Transport):
|
class HttpTransport(Transport):
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_error(cls, r):
|
def get_error(cls, response):
|
||||||
return "Received status code %d" % r.status_code
|
return f"Received status code {response.status_code}"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _request(cls, method, url, **kwargs):
|
def _request(cls, method, url, **kwargs):
|
||||||
@ -258,6 +258,18 @@ class HipChat(HttpTransport):
|
|||||||
|
|
||||||
|
|
||||||
class OpsGenie(HttpTransport):
|
class OpsGenie(HttpTransport):
|
||||||
|
@classmethod
|
||||||
|
def get_error(cls, response):
|
||||||
|
try:
|
||||||
|
m = response.json().get("message")
|
||||||
|
if m:
|
||||||
|
code = response.status_code
|
||||||
|
return f'Received status code {code} with a message: "{m}"'
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return super().get_error(response)
|
||||||
|
|
||||||
def notify(self, check):
|
def notify(self, check):
|
||||||
headers = {
|
headers = {
|
||||||
"Conent-Type": "application/json",
|
"Conent-Type": "application/json",
|
||||||
|
@ -775,7 +775,7 @@ def send_test_notification(request, code):
|
|||||||
error = channel.transport.notify(dummy)
|
error = channel.transport.notify(dummy)
|
||||||
|
|
||||||
if error:
|
if error:
|
||||||
messages.warning(request, "Could not send a test notification: %s" % error)
|
messages.warning(request, "Could not send a test notification. %s" % error)
|
||||||
else:
|
else:
|
||||||
messages.success(request, "Test notification sent!")
|
messages.success(request, "Test notification sent!")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user