Commit fde77005 by Eric Fischer

Log payload on 503 errors

EDUCATOR-1956
parent a9506c1a
...@@ -20,9 +20,9 @@ def create_zendesk_ticket(requester_name, requester_email, subject, body, tags=N ...@@ -20,9 +20,9 @@ def create_zendesk_ticket(requester_name, requester_email, subject, body, tags=N
common/djangoapps/util/views.py). Both of those callers use basic auth, and should be switched over to this oauth common/djangoapps/util/views.py). Both of those callers use basic auth, and should be switched over to this oauth
implementation once the immediate pressures of zendesk_proxy are resolved. implementation once the immediate pressures of zendesk_proxy are resolved.
""" """
if not (settings.ZENDESK_URL and settings.ZENDESK_OAUTH_ACCESS_TOKEN): def _std_error_message(details, payload):
log.debug('Zendesk is not configured. Cannot create a ticket.') """Internal helper to standardize error message. This allows for simpler splunk alerts."""
return status.HTTP_503_SERVICE_UNAVAILABLE return 'zendesk_proxy action required\n{}\nNo ticket created for payload {}'.format(details, payload)
# Remove duplicates from tags list # Remove duplicates from tags list
tags = list(set(tags)) tags = list(set(tags))
...@@ -42,6 +42,10 @@ def create_zendesk_ticket(requester_name, requester_email, subject, body, tags=N ...@@ -42,6 +42,10 @@ def create_zendesk_ticket(requester_name, requester_email, subject, body, tags=N
# Encode the data to create a JSON payload # Encode the data to create a JSON payload
payload = json.dumps(data) payload = json.dumps(data)
if not (settings.ZENDESK_URL and settings.ZENDESK_OAUTH_ACCESS_TOKEN):
log.error(_std_error_message("zendesk not configured", payload))
return status.HTTP_503_SERVICE_UNAVAILABLE
# Set the request parameters # Set the request parameters
url = urljoin(settings.ZENDESK_URL, '/api/v2/tickets.json') url = urljoin(settings.ZENDESK_URL, '/api/v2/tickets.json')
headers = { headers = {
...@@ -49,10 +53,6 @@ def create_zendesk_ticket(requester_name, requester_email, subject, body, tags=N ...@@ -49,10 +53,6 @@ def create_zendesk_ticket(requester_name, requester_email, subject, body, tags=N
'Authorization': "Bearer {}".format(settings.ZENDESK_OAUTH_ACCESS_TOKEN), 'Authorization': "Bearer {}".format(settings.ZENDESK_OAUTH_ACCESS_TOKEN),
} }
def _std_error_message(details, payload):
"""Internal helper to standardize error message. This allows for simpler splunk alerts."""
return 'zendesk_proxy action required\n{}\nNo ticket created for payload {}'.format(details, payload)
try: try:
response = requests.post(url, data=payload, headers=headers) response = requests.post(url, data=payload, headers=headers)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment