mirror of
https://github.com/ansible/awx.git
synced 2026-05-09 18:37:36 -02:30
Fixing up some unicode issues
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
|
|
||||||
import pprint
|
import pprint
|
||||||
|
|
||||||
|
from django.utils.encoding import smart_text
|
||||||
from django.core.mail.backends.base import BaseEmailBackend
|
from django.core.mail.backends.base import BaseEmailBackend
|
||||||
|
|
||||||
class TowerBaseEmailBackend(BaseEmailBackend):
|
class TowerBaseEmailBackend(BaseEmailBackend):
|
||||||
@@ -10,9 +12,9 @@ class TowerBaseEmailBackend(BaseEmailBackend):
|
|||||||
if "body" in body:
|
if "body" in body:
|
||||||
body_actual = body['body']
|
body_actual = body['body']
|
||||||
else:
|
else:
|
||||||
body_actual = "{} #{} had status {} on Ansible Tower, view details at {}\n\n".format(body['friendly_name'],
|
body_actual = smart_text("{} #{} had status {} on Ansible Tower, view details at {}\n\n".format(body['friendly_name'],
|
||||||
body['id'],
|
body['id'],
|
||||||
body['status'],
|
body['status'],
|
||||||
body['url'])
|
body['url']))
|
||||||
body_actual += pprint.pformat(body, indent=4)
|
body_actual += pprint.pformat(body, indent=4)
|
||||||
return body_actual
|
return body_actual
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from django.utils.encoding import smart_text
|
||||||
from django.core.mail.backends.smtp import EmailBackend
|
from django.core.mail.backends.smtp import EmailBackend
|
||||||
|
|
||||||
class CustomEmailBackend(EmailBackend):
|
class CustomEmailBackend(EmailBackend):
|
||||||
@@ -19,9 +20,9 @@ class CustomEmailBackend(EmailBackend):
|
|||||||
sender_parameter = "sender"
|
sender_parameter = "sender"
|
||||||
|
|
||||||
def format_body(self, body):
|
def format_body(self, body):
|
||||||
body_actual = "{} #{} had status {} on Ansible Tower, view details at {}\n\n".format(body['friendly_name'],
|
body_actual = smart_text("{} #{} had status {} on Ansible Tower, view details at {}\n\n".format(body['friendly_name'],
|
||||||
body['id'],
|
body['id'],
|
||||||
body['status'],
|
body['status'],
|
||||||
body['url'])
|
body['url']))
|
||||||
body_actual += pprint.pformat(body, indent=4)
|
body_actual += pprint.pformat(body, indent=4)
|
||||||
return body_actual
|
return body_actual
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import logging
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
from django.utils.encoding import smart_text
|
||||||
|
|
||||||
from awx.main.notifications.base import TowerBaseEmailBackend
|
from awx.main.notifications.base import TowerBaseEmailBackend
|
||||||
|
|
||||||
logger = logging.getLogger('awx.main.notifications.hipchat_backend')
|
logger = logging.getLogger('awx.main.notifications.hipchat_backend')
|
||||||
@@ -40,8 +42,8 @@ class HipChatBackend(TowerBaseEmailBackend):
|
|||||||
"from": m.from_email,
|
"from": m.from_email,
|
||||||
"message_format": "text"})
|
"message_format": "text"})
|
||||||
if r.status_code != 204:
|
if r.status_code != 204:
|
||||||
logger.error("Error sending messages: {}".format(r.text))
|
logger.error(smart_text("Error sending messages: {}".format(r.text)))
|
||||||
if not self.fail_silently:
|
if not self.fail_silently:
|
||||||
raise Exception("Error sending message to hipchat: {}".format(r.text))
|
raise Exception(smart_text("Error sending message to hipchat: {}".format(r.text)))
|
||||||
sent_messages += 1
|
sent_messages += 1
|
||||||
return sent_messages
|
return sent_messages
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import logging
|
|||||||
|
|
||||||
import irc.client
|
import irc.client
|
||||||
|
|
||||||
|
from django.utils.encoding import smart_text
|
||||||
|
|
||||||
from awx.main.notifications.base import TowerBaseEmailBackend
|
from awx.main.notifications.base import TowerBaseEmailBackend
|
||||||
|
|
||||||
logger = logging.getLogger('awx.main.notifications.irc_backend')
|
logger = logging.getLogger('awx.main.notifications.irc_backend')
|
||||||
@@ -48,7 +50,7 @@ class IrcBackend(TowerBaseEmailBackend):
|
|||||||
connect_factory=connection_factory,
|
connect_factory=connection_factory,
|
||||||
)
|
)
|
||||||
except irc.client.ServerConnectionError as e:
|
except irc.client.ServerConnectionError as e:
|
||||||
logger.error("Exception connecting to irc server: {}".format(e))
|
logger.error(smart_text("Exception connecting to irc server: {}".format(e)))
|
||||||
if not self.fail_silently:
|
if not self.fail_silently:
|
||||||
raise
|
raise
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
import logging
|
import logging
|
||||||
import pygerduty
|
import pygerduty
|
||||||
|
|
||||||
|
from django.utils.encoding import smart_text
|
||||||
|
|
||||||
from awx.main.notifications.base import TowerBaseEmailBackend
|
from awx.main.notifications.base import TowerBaseEmailBackend
|
||||||
|
|
||||||
logger = logging.getLogger('awx.main.notifications.pagerduty_backend')
|
logger = logging.getLogger('awx.main.notifications.pagerduty_backend')
|
||||||
@@ -33,7 +35,7 @@ class PagerDutyBackend(TowerBaseEmailBackend):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
if not self.fail_silently:
|
if not self.fail_silently:
|
||||||
raise
|
raise
|
||||||
logger.error("Exception connecting to PagerDuty: {}".format(e))
|
logger.error(smart_text("Exception connecting to PagerDuty: {}".format(e)))
|
||||||
for m in messages:
|
for m in messages:
|
||||||
try:
|
try:
|
||||||
pager.trigger_incident(m.recipients()[0],
|
pager.trigger_incident(m.recipients()[0],
|
||||||
@@ -41,7 +43,7 @@ class PagerDutyBackend(TowerBaseEmailBackend):
|
|||||||
details=m.body,
|
details=m.body,
|
||||||
client=m.from_email)
|
client=m.from_email)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Exception sending messages: {}".format(e))
|
logger.error(smart_text("Exception sending messages: {}".format(e)))
|
||||||
if not self.fail_silently:
|
if not self.fail_silently:
|
||||||
raise
|
raise
|
||||||
return sent_messages
|
return sent_messages
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
import logging
|
import logging
|
||||||
from slackclient import SlackClient
|
from slackclient import SlackClient
|
||||||
|
|
||||||
|
from django.utils.encoding import smart_text
|
||||||
|
|
||||||
from awx.main.notifications.base import TowerBaseEmailBackend
|
from awx.main.notifications.base import TowerBaseEmailBackend
|
||||||
|
|
||||||
logger = logging.getLogger('awx.main.notifications.slack_backend')
|
logger = logging.getLogger('awx.main.notifications.slack_backend')
|
||||||
@@ -44,7 +46,7 @@ class SlackBackend(TowerBaseEmailBackend):
|
|||||||
self.connection.rtm_send_message(r, m.subject)
|
self.connection.rtm_send_message(r, m.subject)
|
||||||
sent_messages += 1
|
sent_messages += 1
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Exception sending messages: {}".format(e))
|
logger.error(smart_text("Exception sending messages: {}".format(e)))
|
||||||
if not self.fail_silently:
|
if not self.fail_silently:
|
||||||
raise
|
raise
|
||||||
return sent_messages
|
return sent_messages
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import logging
|
|||||||
|
|
||||||
from twilio.rest import TwilioRestClient
|
from twilio.rest import TwilioRestClient
|
||||||
|
|
||||||
|
from django.utils.encoding import smart_text
|
||||||
|
|
||||||
from awx.main.notifications.base import TowerBaseEmailBackend
|
from awx.main.notifications.base import TowerBaseEmailBackend
|
||||||
|
|
||||||
logger = logging.getLogger('awx.main.notifications.twilio_backend')
|
logger = logging.getLogger('awx.main.notifications.twilio_backend')
|
||||||
@@ -31,7 +33,7 @@ class TwilioBackend(TowerBaseEmailBackend):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
if not self.fail_silently:
|
if not self.fail_silently:
|
||||||
raise
|
raise
|
||||||
logger.error("Exception connecting to Twilio: {}".format(e))
|
logger.error(smart_text("Exception connecting to Twilio: {}".format(e)))
|
||||||
|
|
||||||
for m in messages:
|
for m in messages:
|
||||||
try:
|
try:
|
||||||
@@ -41,7 +43,7 @@ class TwilioBackend(TowerBaseEmailBackend):
|
|||||||
body=m.subject)
|
body=m.subject)
|
||||||
sent_messages += 1
|
sent_messages += 1
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Exception sending messages: {}".format(e))
|
logger.error(smart_text("Exception sending messages: {}".format(e)))
|
||||||
if not self.fail_silently:
|
if not self.fail_silently:
|
||||||
raise
|
raise
|
||||||
return sent_messages
|
return sent_messages
|
||||||
|
|||||||
@@ -2,9 +2,11 @@
|
|||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from django.utils.encoding import smart_text
|
||||||
|
|
||||||
from awx.main.notifications.base import TowerBaseEmailBackend
|
from awx.main.notifications.base import TowerBaseEmailBackend
|
||||||
|
|
||||||
logger = logging.getLogger('awx.main.notifications.webhook_backend')
|
logger = logging.getLogger('awx.main.notifications.webhook_backend')
|
||||||
@@ -30,8 +32,8 @@ class WebhookBackend(TowerBaseEmailBackend):
|
|||||||
data=json.dumps(m.body),
|
data=json.dumps(m.body),
|
||||||
headers=self.headers)
|
headers=self.headers)
|
||||||
if r.status_code >= 400:
|
if r.status_code >= 400:
|
||||||
logger.error("Error sending notification webhook: {}".format(r.text))
|
logger.error(smart_text("Error sending notification webhook: {}".format(r.text)))
|
||||||
if not self.fail_silently:
|
if not self.fail_silently:
|
||||||
raise Exception("Error sending notification webhook: {}".format(r.text))
|
raise Exception(smart_text("Error sending notification webhook: {}".format(r.text)))
|
||||||
sent_messages += 1
|
sent_messages += 1
|
||||||
return sent_messages
|
return sent_messages
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ from celery import Task, task
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import transaction, DatabaseError
|
from django.db import transaction, DatabaseError
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
|
from django.utils.encoding import smart_text
|
||||||
from django.core.mail import send_mail
|
from django.core.mail import send_mail
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
@@ -83,7 +84,7 @@ def send_notifications(notification_list, job_id=None):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Send Notification Failed {}".format(e))
|
logger.error("Send Notification Failed {}".format(e))
|
||||||
notification.status = "failed"
|
notification.status = "failed"
|
||||||
notification.error = str(e)
|
notification.error = smart_text(e)
|
||||||
finally:
|
finally:
|
||||||
notification.save()
|
notification.save()
|
||||||
if job_id is not None:
|
if job_id is not None:
|
||||||
|
|||||||
Reference in New Issue
Block a user