Skip to content

Not Sending PagerDuty Alerts Due to UnicodeEncodeError #1077

@JohnTrapp

Description

@JohnTrapp

Logs

File "/usr/local/lib/python3.10/site-packages/elastalert/elastalert.py", line 1298, in alert
    return self.send_alert(matches, rule, alert_time=alert_time, retried=retried)
  File "/usr/local/lib/python3.10/site-packages/elastalert/elastalert.py", line 1375, in send_alert
    alert.alert(matches)
  File "/usr/local/lib/python3.10/site-packages/elastalert/alerters/pagerduty.py", line 94, in alert
    response = requests.post(
  File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 117, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 440, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 398, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 239, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/usr/local/lib/python3.10/http/client.py", line 1282, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.10/http/client.py", line 1327, in _send_request
    body = _encode(body, 'body')
  File "/usr/local/lib/python3.10/http/client.py", line 166, in _encode
    raise UnicodeEncodeError(
UnicodeEncodeError: 'latin-1' codec can't encode character '\u21e2' in position 1621: Body ('⇢') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.

Steps to reproduce

  1. Generate a log with a message containing the character and include that message in an alert to PagerDuty.
  2. Note that the alert does not get sent to PagerDuty, effectively dropping the alert.

More info

This is happening with our spring java services that use reactor, as their stack traces use that character. Encoding aside, elastalert2 should catch and handle all exceptions when sending a POST, instead of only looking at the response code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions