From b024d91c6655bb30561a20a542a1770ab29bb435 Mon Sep 17 00:00:00 2001 From: Jim Ladd Date: Mon, 21 Oct 2019 16:16:10 -0700 Subject: [PATCH] Use correct notif. bodies when sending test notifs * Notification backends now handle body of notifications differently * .. depending on their type (webhook, email, and pagerduty) are currently the only three notification types that use body * email and pagerduty expect a string * webhooks expects a dict in string format --- awx/api/views/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/awx/api/views/__init__.py b/awx/api/views/__init__.py index 63325abe2a..23e66810fe 100644 --- a/awx/api/views/__init__.py +++ b/awx/api/views/__init__.py @@ -4313,8 +4313,15 @@ class NotificationTemplateTest(GenericAPIView): def post(self, request, *args, **kwargs): obj = self.get_object() - notification = obj.generate_notification("Tower Notification Test {} {}".format(obj.id, settings.TOWER_URL_BASE), - {"body": "Ansible Tower Test Notification {} {}".format(obj.id, settings.TOWER_URL_BASE)}) + msg = "Tower Notification Test {} {}".format(obj.id, settings.TOWER_URL_BASE) + if obj.notification_type in ('email', 'pagerduty'): + body = "Ansible Tower Test Notification {} {}".format(obj.id, settings.TOWER_URL_BASE) + elif obj.notification_type == 'webhook': + body = '{{"body": "Ansible Tower Test Notification {} {}"}}'.format(obj.id, settings.TOWER_URL_BASE) + else: + body = {"body": "Ansible Tower Test Notification {} {}".format(obj.id, settings.TOWER_URL_BASE)} + notification = obj.generate_notification(msg, body) + if not notification: return Response({}, status=status.HTTP_400_BAD_REQUEST) else: