jertel / elastalert2

ElastAlert 2 is a continuation of the original yelp/elastalert project. Pull requests are appreciated!
https://elastalert2.readthedocs.org
Apache License 2.0
859 stars 277 forks source link

Error while setting up Elastalert2 "AttributeError: module 'datetime' has no attribute 'UTC' " #1468

Closed parvvam closed 1 month ago

parvvam commented 1 month ago

While setting up elastalert2 via a python package, after configuring the rule, and testing it I am getting error : "AttributeError: module 'datetime' has no attribute 'UTC' ".

root@server01:~# elastalert-test-rule test_rule.yml Traceback (most recent call last): File "/usr/local/bin/elastalert-test-rule", line 8, in sys.exit(main()) File "/usr/local/lib/python3.10/dist-packages/elastalert/test_rule.py", line 510, in main test_instance = MockElastAlerter(args) File "/usr/local/lib/python3.10/dist-packages/elastalert/test_rule.py", line 174, in init self.ts_now = ts_now() File "/usr/local/lib/python3.10/dist-packages/elastalert/util.py", line 212, in ts_now now = datetime.datetime.now(tz=datetime.UTC) AttributeError: module 'datetime' has no attribute 'UTC'

please find the contents of test_rule.yml

index: pglogs-* type: frequency num_events: 15 timeframe: hours: 4 filter:

mstsc_TR3nMfzWc8

jertel commented 1 month ago

Read #11 before posting.

See https://github.com/jertel/elastalert2/issues/1400.