elastalert icon indicating copy to clipboard operation
elastalert copied to clipboard

Integration with elasticsearch v5

Open rauizab opened this issue 10 years ago • 86 comments

Hi

I know that the new version v5 of elasticsearch has just being released, but do you know when it will be available the integration of elastalert with the new version? At the moment I am getting:

INFO:elastalert:Starting up WARNING:elasticsearch:POST http://elasticsearch:9200/elastalert_status/elastalert/_search?size=1000 [status:400 request:0.013s] WARNING:elasticsearch:POST http://elasticsearch:9200/elastalert_status/elastalert_status/_search?_source_include=endtime%2Crule_name&size=1 [status:400 request:0.002s] ERROR:root:Error querying for last run: TransportError(400, {u'line': 1, u'root_cause': [{u'reason': u'Unknown key for a START_OBJECT in [filter].', u'type': u'parsing_exception', u'line': 1, u'col': 12}], u'type': u'parsing_exception', u'reason': u'Unknown key for a START_OBJECT in [filter].', u'col': 12}) WARNING:elasticsearch:POST http://elasticsearch:9200/elastalert_status/elastalert_error?op_type=create [status:400 request:0.003s] ERROR:root:Error writing alert info to elasticsearch: TransportError(400, {u'root_cause': [{u'reason': u'Validation Failed: 1: an id must be provided if version type or value are set;', u'type': u'action_request_validation_exception'}], u'type': u'action_request_validation_exception', u'reason': u'Validation Failed: 1: an id must be provided if version type or value are set;'}) Traceback (most recent call last): File "/opt/elastalert/elastalert/elastalert.py", line 1033, in writeback doc_type=doc_type, body=body) File "/usr/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 68, in _wrapped return func(*args, params=params, **kwargs) File "/usr/lib/python2.7/site-packages/elasticsearch/client/init.py", line 227, in create return self.index(index, doc_type, body, id=id, params=params, op_type='create') File "/usr/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 68, in _wrapped return func(args, params=params, **kwargs) File "/usr/lib/python2.7/site-packages/elasticsearch/client/init.py", line 257, in index _make_path(index, doc_type, id), params=params, body=body) File "/usr/lib/python2.7/site-packages/elasticsearch/transport.py", line 301, in perform_request status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout) File "/usr/lib/python2.7/site-packages/elasticsearch/connection/http_requests.py", line 72, in perform_request self._raise_error(response.status_code, raw_data) File "/usr/lib/python2.7/site-packages/elasticsearch/connection/base.py", line 102, in _raise_error raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info) RequestError: TransportError(400, {u'root_cause': [{u'reason': u'Validation Failed: 1: an id must be provided if version type or value are set;', u'type': u'action_request_validation_exception'}], u'type': u'action_request_validation_exception', u'reason': u'Validation Failed: 1: an id must be provided if version type or value are set;'}) WARNING:elasticsearch:GET http://elasticsearch:9200/payment-/_search?_source_include=eventtime%2C%2A%2CuserId&ignore_unavailable=true&size=10000 [status:400 request:0.003s] ERROR:root:Error running query: TransportError(400, {u'line': 1, u'root_cause': [{u'reason': u'no [query] registered for [filtered]', u'type': u'parsing_exception', u'line': 1, u'col': 67}], u'type': u'parsing_exception', u'reason': u'no [query] registered for [filtered]', u'col': 67}) WARNING:elasticsearch:POST http://elasticsearch:9200/elastalert_status/elastalert_error?op_type=create [status:400 request:0.003s] ERROR:root:Error writing alert info to elasticsearch: TransportError(400, {u'root_cause': [{u'reason': u'Validation Failed: 1: an id must be provided if version type or value are set;', u'type': u'action_request_validation_exception'}], u'type': u'action_request_validation_exception', u'reason': u'Validation Failed: 1: an id must be provided if version type or value are set;'}) Traceback (most recent call last): File "/opt/elastalert/elastalert/elastalert.py", line 1033, in writeback doc_type=doc_type, body=body) File "/usr/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 68, in _wrapped return func(*args, params=params, **kwargs) File "/usr/lib/python2.7/site-packages/elasticsearch/client/init.py", line 227, in create return self.index(index, doc_type, body, id=id, params=params, op_type='create') File "/usr/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 68, in _wrapped return func(*args, params=params, **kwargs) File "/usr/lib/python2.7/site-packages/elasticsearch/client/init.py", line 257, in index _make_path(index, doc_type, id), params=params, body=body) File "/usr/lib/python2.7/site-packages/elasticsearch/transport.py", line 301, in perform_request status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout) File "/usr/lib/python2.7/site-packages/elasticsearch/connection/http_requests.py", line 72, in perform_request self._raise_error(response.status_code, raw_data) File "/usr/lib/python2.7/site-packages/elasticsearch/connection/base.py", line 102, in _raise_error raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info) RequestError: TransportError(400, {u'root_cause': [{u'reason': u'Validation Failed: 1: an id must be provided if version type or value are set;', u'type': u'action_request_validation_exception'}], u'type': u'action_request_validation_exception', u'reason': u'Validation Failed: 1: an id must be provided if version type or value are set;'}) INFO:elastalert:Ran User1111MakePayment from 2016-11-02 08:20 UTC to 2016-11-02 13:20 UTC: 0 query hits, 0 matches, 0 alerts sent

Thanks for this great tool!!!!

rauizab avatar Nov 02 '16 13:11 rauizab

ES 5 has been around for a while already, its the GA version that just came out, any ETA on the support would be lovely :+1:

penekk avatar Nov 03 '16 13:11 penekk

+1

watollop avatar Nov 04 '16 11:11 watollop

+1

lrolsen avatar Nov 05 '16 12:11 lrolsen

+1

On Sat, Nov 5, 2016 at 5:14 AM -0700, "lrolsen" <[email protected]mailto:[email protected]> wrote:

+1

You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/Yelp/elastalert/issues/790#issuecomment-258607858, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AH7j4V-D_DPsJ-KmIqww-sOMgZ5FaPG-ks5q7HMggaJpZM4KnOvN.

vijayarulmuthu avatar Nov 05 '16 16:11 vijayarulmuthu

@watollop say me to put +1 here

sabueso avatar Nov 06 '16 20:11 sabueso

+1

pasqualguerrero avatar Nov 06 '16 20:11 pasqualguerrero

+1

tynor88 avatar Nov 07 '16 08:11 tynor88

+1

bennneuh avatar Nov 07 '16 09:11 bennneuh

+1 Duplicate of #510

nick-george avatar Nov 07 '16 09:11 nick-george

+1

AndrewPix avatar Nov 07 '16 11:11 AndrewPix

+1

Alexwii avatar Nov 14 '16 10:11 Alexwii

Is it known what is broken and how can we help ?

stumyp avatar Nov 14 '16 15:11 stumyp

IRC pointed me to https://github.com/Yelp/elastalert/blob/master/elastalert/elastalert.py#L159

bkeifer avatar Nov 15 '16 18:11 bkeifer

+1

doublesea avatar Nov 16 '16 08:11 doublesea

Is it known what is broken and how can we help ?

as i known, it is because "filter" is not available any more in ES 5.0.

There are many "filter" query in EA which will get the 400 HTTP response for the incorrect query clause.

doublesea avatar Nov 16 '16 08:11 doublesea

+1

kojisaiki avatar Nov 16 '16 13:11 kojisaiki

+1

branchnetconsulting avatar Nov 16 '16 21:11 branchnetconsulting

It looks like all needed is to rewrite this query: https://github.com/Yelp/elastalert/blob/master/elastalert/elastalert.py#L159 (thanks @bkeifer )

Documentation says that change should be simple: https://www.elastic.co/guide/en/elasticsearch/reference/5.0/query-dsl-filtered-query.html

I'll try to find some time, my python is a bit rusty :)

stumyp avatar Nov 16 '16 21:11 stumyp

My reading of that doc suggests that the change should be:

diff --git a/elastalert/elastalert.py b/elastalert/elastalert.py
index 2cbd553..a13e739 100644
--- a/elastalert/elastalert.py
+++ b/elastalert/elastalert.py
@@ -156,7 +156,7 @@ class ElastAlerter():
         if starttime and endtime:
             es_filters['filter']['bool']['must'].insert(0, {'range': {timestamp_field: {'gt': starttime,
                                                                                         'lte': endtime}}})
-        query = {'query': {'filtered': es_filters}}
+        query = {'query': {'bool': es_filters}}
         if sort:
             query['sort'] = [{timestamp_field: {'order': 'desc' if desc else 'asc'}}]
         return query

I'll see if I can make it work in our ES5 environment

timwsuqld avatar Nov 16 '16 22:11 timwsuqld

@timwsuqld: plus if statement to detect ES version

stumyp avatar Nov 16 '16 22:11 stumyp