Yelp / elastalert

Easy & Flexible Alerting With ElasticSearch
https://elastalert.readthedocs.org
Apache License 2.0
7.99k stars 1.74k forks source link

UnicodeEncodeError when firing command alert #2245

Open simonszu opened 5 years ago

simonszu commented 5 years ago

I am currently experiencing the following error when elastalert fires an alert via the command module:

ERROR:root:Traceback (most recent call last):
  File "/opt/app-root/lib/python2.7/site-packages/elastalert/elastalert.py", line 1341, in alert
    return self.send_alert(matches, rule, alert_time=alert_time, retried=retried)
  File "/opt/app-root/lib/python2.7/site-packages/elastalert/elastalert.py", line 1430, in send_alert
    alert.alert(matches)
  File "/opt/app-root/lib/python2.7/site-packages/elastalert/alerts.py", line 923, in alert
    stdout, stderr = subp.communicate(input=alert_text)
  File "/opt/rh/python27/root/usr/lib64/python2.7/subprocess.py", line 465, in communicate
    self.stdin.write(input)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 1801: ordinal not in range(128)

ERROR:root:Uncaught exception running rule GeneralErrorTest: 'ascii' codec can't encode character u'\xe4' in position 1801: ordinal not in range(128)

The command i am trying to execute is just a logger.

This happens on v0.1.39 as well as on v0.2.0b2. Elastalert is running in a container with Red Hat's python-27-rhel7:2.7-54 image as base image.

Qmando commented 5 years ago

Thanks for the report.

I think the solution is to replace elastalert/alerts.py line 923 with stdout, stderr = subp.communicate(input=alert_text.encode('utf-8'))

I'll try to get this fix in soon.