mirror of
https://github.com/ansible/awx.git
synced 2026-03-25 21:05:03 -02:30
Enable email notifications to work,
...and customize default messages
This commit is contained in:
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
# Python
|
# Python
|
||||||
import logging
|
import logging
|
||||||
|
from copy import copy
|
||||||
|
from urllib.parse import urljoin
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.db import connection, models
|
from django.db import connection, models
|
||||||
@@ -38,9 +40,6 @@ from awx.main.fields import JSONField
|
|||||||
from awx.main.utils import schedule_task_manager
|
from awx.main.utils import schedule_task_manager
|
||||||
|
|
||||||
|
|
||||||
from copy import copy
|
|
||||||
from urllib.parse import urljoin
|
|
||||||
|
|
||||||
__all__ = ['WorkflowJobTemplate', 'WorkflowJob', 'WorkflowJobOptions', 'WorkflowJobNode',
|
__all__ = ['WorkflowJobTemplate', 'WorkflowJob', 'WorkflowJobOptions', 'WorkflowJobNode',
|
||||||
'WorkflowJobTemplateNode', 'WorkflowApprovalTemplate', 'WorkflowApproval']
|
'WorkflowJobTemplateNode', 'WorkflowApprovalTemplate', 'WorkflowApproval']
|
||||||
|
|
||||||
@@ -712,6 +711,8 @@ class WorkflowApproval(UnifiedJob, JobNotificationMixin):
|
|||||||
|
|
||||||
def send_approval_notification(self, status):
|
def send_approval_notification(self, status):
|
||||||
from awx.main.tasks import send_notifications # avoid circular import
|
from awx.main.tasks import send_notifications # avoid circular import
|
||||||
|
if self.workflow_job_template is None:
|
||||||
|
return
|
||||||
for nt in self.workflow_job_template.notification_templates["approvals"]:
|
for nt in self.workflow_job_template.notification_templates["approvals"]:
|
||||||
try:
|
try:
|
||||||
(notification_subject, notification_body) = self.build_notification_message(nt, status)
|
(notification_subject, notification_body) = self.build_notification_message(nt, status)
|
||||||
@@ -727,24 +728,22 @@ class WorkflowApproval(UnifiedJob, JobNotificationMixin):
|
|||||||
|
|
||||||
def build_notification_message(self, nt, status):
|
def build_notification_message(self, nt, status):
|
||||||
subject = []
|
subject = []
|
||||||
subject.append(('{}, Job Number {}').format(self.workflow_approval_template.name,
|
workflow_url = urljoin(settings.TOWER_URL_BASE, '/#/workflows/{}'.format(self.workflow_job.id))
|
||||||
self.id))
|
subject.append(('The approval node "{}"').format(self.workflow_approval_template.name))
|
||||||
if status == 'running':
|
if status == 'running':
|
||||||
subject.append('Please approve or deny this node.')
|
subject.append((' is running. You can approve or deny this node at: {}').format(workflow_url))
|
||||||
if status == 'approved':
|
if status == 'approved':
|
||||||
subject.append('This approval node was approved.')
|
subject.append((' was approved. {}').format(workflow_url))
|
||||||
if status == 'timed_out':
|
if status == 'timed_out':
|
||||||
subject.append('This approval node has timed out.')
|
subject.append((' has timed out. {}').format(workflow_url))
|
||||||
elif status == 'denied':
|
elif status == 'denied':
|
||||||
subject.append('This approval node was denied.')
|
subject.append((' was denied. {}').format(workflow_url))
|
||||||
|
subject = " ".join(subject)
|
||||||
body = self.notification_data()
|
body = self.notification_data()
|
||||||
body['body'] = subject
|
body['body'] = subject
|
||||||
|
|
||||||
return subject, body
|
return subject, body
|
||||||
|
|
||||||
# def get_notification_templates(self):
|
|
||||||
# return self.workflow_job_template.notification_templates
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def workflow_job_template(self):
|
def workflow_job_template(self):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ def send_notifications(notification_list, job_id=None):
|
|||||||
notification.status = "successful"
|
notification.status = "successful"
|
||||||
notification.notifications_sent = sent
|
notification.notifications_sent = sent
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Send Notification Failed {}".format(e))
|
logger.exception("Send Notification Failed {}".format(e))
|
||||||
notification.status = "failed"
|
notification.status = "failed"
|
||||||
notification.error = smart_str(e)
|
notification.error = smart_str(e)
|
||||||
update_fields.append('error')
|
update_fields.append('error')
|
||||||
|
|||||||
Reference in New Issue
Block a user