Elastalert: AttributeError: '_thread._local' object has no attribute 'alerts_sent'

Created on 8 Jan 2020  Â·  9Comments  Â·  Source: Yelp/elastalert

run elastalert-test-rule with python 3.6.0 and python 3.6.9 have same problem,
which version of python should use?

ERROR:root:Traceback (most recent call last):
File "/opt/pyenv/versions/elastalert_360/lib/python3.6/site-packages/elastalert-0.2.1-py3.6.egg/elastalert/elastalert.py", line 1451, in alert
return self.send_alert(matches, rule, alert_time=alert_time, retried=retried)
File "/opt/pyenv/versions/elastalert_360/lib/python3.6/site-packages/elastalert-0.2.1-py3.6.egg/elastalert/elastalert.py", line 1550, in send_alert
self.thread_data.alerts_sent += 1
AttributeError: '_thread._local' object has no attribute 'alerts_sent'

Elastalert version : 0.2.1

Most helpful comment

This is still a issue in the latest release.

Can we get a proper fix instead of manually adding in the variable?

All 9 comments

Seeing the same issue running elastalert-test-rule with the --alert flag enabled (when alerts are actually sent out) - did you find a fix for this @gcnote ?

+1, seeing the same issue for elastalert-test-rule
Python 3.5.2

Elastalert 0.2.1

This fix discussed in #2556 works for me.

        self.replace_dots_in_field_names = self.conf.get('replace_dots_in_field_names', False)
        self.thread_data.num_hits = 0
        self.thread_data.num_dupes = 0
        self.thread_data.alerts_sent = 0  #add
        self.scheduler = BackgroundScheduler()

https://github.com/Yelp/elastalert/blob/master/elastalert/elastalert.py#L162-L163

Thanks!! @gcnote

This is still a issue in the latest release.

Can we get a proper fix instead of manually adding in the variable?

Still seeing this with latest elastalert.

elastalert[31818]: ERROR:apscheduler.executors.default:Job "ElastAlerter.handle_rule_execution (trigger: interval[0:01:00], next run at: 2020-10-15 21:43:39 PDT)" raised an exception
elastalert[31818]: Traceback (most recent call last):
elastalert[31818]: File "/opt/elastalert_venv/venv/lib/python3.6/site-packages/apscheduler/executors/base.py", line 125, in run_job
elastalert[31818]: retval = job.func(*job.args, **job.kwargs)
elastalert[31818]: File "/opt/elastalert_venv/venv/lib/python3.6/site-packages/elastalert/elastalert.py", line 1278, in handle_rule_execution
elastalert[31818]: self.thread_data.num_hits, self.thread_data.num_dupes, num_matches,
elastalert[31818]: AttributeError: '_thread._local' object has no attribute 'num_hits'

Whats the reason for this?

@daichi703n

Is there a problem that this fix hasn't solved yet?
If there is no problem, make a pull request.

@nsano-rururu
I created PR https://github.com/Yelp/elastalert/pull/2991. Please check it.

@daichi703n

I will try it on the weekend. Thank you.

@daichi703n

We apologize for the delay in reporting. confirmed. The problem has been resolved. It will be included as a patch in the next release of ElastAlertServer. Thank you very much.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wjk1982 picture wjk1982  Â·  3Comments

tkumark picture tkumark  Â·  3Comments

abhishekjiitr picture abhishekjiitr  Â·  3Comments

junaid1460 picture junaid1460  Â·  3Comments

rhysxevans picture rhysxevans  Â·  3Comments