alerts fail when text contains unicode characters
See original GitHub issueattempting to use a filter on a field containing a unicode/non-ASCII character will cause the following exception in case of an alert:
ERROR:root:Traceback (most recent call last): File “/usr/lib/python2.6/site-packages/elastalert-0.0.57-py2.6.egg/elastalert/elastalert.py”, line 826, in alert return self.send_alert(matches, rule, alert_time=None) File “/usr/lib/python2.6/site-packages/elastalert-0.0.57-py2.6.egg/elastalert/elastalert.py”, line 887, in send_alert alerter.alert(matches) File “/usr/lib/python2.6/site-packages/elastalert-0.0.57-py2.6.egg/elastalert/alerts.py”, line 166, in alert logging.info(str(BasicMatchString(self.rule, match))) File “/usr/lib/python2.6/site-packages/elastalert-0.0.57-py2.6.egg/elastalert/alerts.py”, line 84, in str self._add_match_items() File “/usr/lib/python2.6/site-packages/elastalert-0.0.57-py2.6.egg/elastalert/alerts.py”, line 62, in _add_match_items value_str = str(value) UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\ufeff’ in position 0: ordinal not in range(128)
after replacing the str()
call with a unicode()
call, the following exception occurs:
ERROR:root:Traceback (most recent call last): File “/usr/lib/python2.6/site-packages/elastalert-0.0.57-py2.6.egg/elastalert/elastalert.py”, line 826, in alert return self.send_alert(matches, rule, alert_time=None) File “/usr/lib/python2.6/site-packages/elastalert-0.0.57-py2.6.egg/elastalert/elastalert.py”, line 887, in send_alert alerter.alert(matches) File “/usr/lib/python2.6/site-packages/elastalert-0.0.57-py2.6.egg/elastalert/alerts.py”, line 166, in alert logging.info(str(BasicMatchString(self.rule, match))) UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\ufeff’ in position 268: ordinal not in range(128)
after replacing the str()
call with a unicode()
call, the alert appears to work.
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (4 by maintainers)
If you want newlines, you have to use YAML block syntax
Whether this technically includes “\r” I think depends on your operating system.
@tanxiaolong 您好,麻烦问下您的问题解决了么?我也遇到同样的问题。