mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 23:46:05 -03:30
Refactor message generator
* Job object can now control the output and generate K:V output for notification types that can support it * Notifications store the body as json/dict now to encode more information * Notification Type can further compose the message based on what is sensible for the notification type * This will also allow customizing the message template in the future * All notification types use sane defaults for the level of detail now
This commit is contained in:
@@ -4,12 +4,12 @@
|
||||
import logging
|
||||
|
||||
import requests
|
||||
|
||||
from django.core.mail.backends.base import BaseEmailBackend
|
||||
import json
|
||||
from awx.main.notifications.base import TowerBaseEmailBackend
|
||||
|
||||
logger = logging.getLogger('awx.main.notifications.webhook_backend')
|
||||
|
||||
class WebhookBackend(BaseEmailBackend):
|
||||
class WebhookBackend(TowerBaseEmailBackend):
|
||||
|
||||
init_parameters = {"url": {"label": "Target URL", "type": "string"},
|
||||
"headers": {"label": "HTTP Headers", "type": "object"}}
|
||||
@@ -20,11 +20,16 @@ class WebhookBackend(BaseEmailBackend):
|
||||
self.headers = headers
|
||||
super(WebhookBackend, self).__init__(fail_silently=fail_silently)
|
||||
|
||||
def format_body(self, body):
|
||||
logger.error("Generating body from {}".format(str(body)))
|
||||
return body
|
||||
|
||||
def send_messages(self, messages):
|
||||
sent_messages = 0
|
||||
for m in messages:
|
||||
logger.error("BODY: " + str(m.body))
|
||||
r = requests.post("{}".format(m.recipients()[0]),
|
||||
data=m.body,
|
||||
data=json.dumps(m.body),
|
||||
headers=self.headers)
|
||||
if r.status_code >= 400:
|
||||
logger.error("Error sending notification webhook: {}".format(r.text))
|
||||
|
||||
Reference in New Issue
Block a user